Skip to content

Fix bug in auxiliary test case compilation in TestCommand #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions bootstrap/src/test.rs
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ impl Run for TestCommand {

impl TestCommand {
pub fn collect_testcases(&self, manifest: &Manifest) -> Vec<TestCase> {
let mut tests = vec![];
let mut cases = vec![];

let verbose = self.verbose;

@@ -94,7 +94,7 @@ impl TestCommand {
let name = format!("examples/{}", filename.to_string_lossy());
let output_file = manifest.out_dir.join("examples").join(filename);
let testcase = TestCase::new(name, case, output_file, TestType::Compile, verbose);
tests.push(testcase);
cases.push(testcase);
}

// Codegen tests
@@ -104,7 +104,7 @@ impl TestCommand {
let name = format!("codegen/{}", filename.to_string_lossy());
let output_file = manifest.out_dir.join("tests/codegen").join(filename);
let testcase = TestCase::new(name, case, output_file, TestType::FileCheck, verbose);
tests.push(testcase);
cases.push(testcase);
}

// Bless tests - the output should be the same as the last run
@@ -114,30 +114,37 @@ impl TestCommand {
let name = format!("bless/{}", filename.to_string_lossy());
let output_file = manifest.out_dir.join("tests/bless").join(filename);
let testcase = TestCase::new(name, case, output_file, TestType::Bless, verbose);
tests.push(testcase);
cases.push(testcase);
}

// Collect test-auxiliary
let aux_use = regex::Regex::new(r"^//@\s*aux-build:(?P<fname>.*)").unwrap();
let mut auxiliary = vec![];
for case in tests.iter() {
let source = std::fs::read_to_string(&case.source).unwrap();
for cap in aux_use.captures_iter(&source) {
let aux_use = regex::Regex::new(r"(?m)//@\s*aux-build:(?P<fname>.*)").unwrap();
let mut auxiliaries = vec![];
for case in cases.iter() {
let content = std::fs::read_to_string(&case.source).unwrap();
for cap in aux_use.captures_iter(&content) {
println!("{:?}", case.source);
let fname = cap.name("fname").unwrap().as_str();
let source = Path::new("tests/auxiliary").join(fname);
let filename = source.file_stem().unwrap();
let name = format!("auxiliary/{}", filename.to_string_lossy());

// deduplication
if auxiliaries.iter().any(|aux: &TestCase| aux.name == name) {
continue;
}

let output_file = manifest.out_dir.join(filename); // aux files are output to the base directory
let testcase =
TestCase::new(name, source, output_file, TestType::CompileLib, verbose);
auxiliary.push(testcase);
auxiliaries.push(testcase);
}
}

// Compile auxiliary before the tests
let mut cases = auxiliary;
cases.extend(tests);
cases
let mut testcases = auxiliaries;
testcases.extend(cases);
testcases
}
}