Skip to content

Commit 97669d6

Browse files
committed
Fix bug in auxiliary test case compilation in TestCommand
Signed-off-by: xizheyin <[email protected]>
1 parent 2f477f0 commit 97669d6

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

bootstrap/src/test.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Run for TestCommand {
8383

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

8888
let verbose = self.verbose;
8989

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

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

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

120120
// Collect test-auxiliary
121-
let aux_use = regex::Regex::new(r"^//@\s*aux-build:(?P<fname>.*)").unwrap();
122-
let mut auxiliary = vec![];
123-
for case in tests.iter() {
124-
let source = std::fs::read_to_string(&case.source).unwrap();
125-
for cap in aux_use.captures_iter(&source) {
121+
let aux_use = regex::Regex::new(r"\s*//@\s*aux-build:(?P<fname>.*)").unwrap();
122+
let mut auxiliaries = vec![];
123+
for case in cases.iter() {
124+
let content = std::fs::read_to_string(&case.source).unwrap();
125+
for cap in aux_use.captures_iter(&content) {
126126
let fname = cap.name("fname").unwrap().as_str();
127127
let source = Path::new("tests/auxiliary").join(fname);
128128
let filename = source.file_stem().unwrap();
129129
let name = format!("auxiliary/{}", filename.to_string_lossy());
130+
131+
// deduplication
132+
if auxiliaries.iter().any(|aux: &TestCase| aux.name == name) {
133+
continue;
134+
}
135+
130136
let output_file = manifest.out_dir.join(filename); // aux files are output to the base directory
131137
let testcase =
132138
TestCase::new(name, source, output_file, TestType::CompileLib, verbose);
133-
auxiliary.push(testcase);
139+
auxiliaries.push(testcase);
134140
}
135141
}
136142

137143
// Compile auxiliary before the tests
138-
let mut cases = auxiliary;
139-
cases.extend(tests);
140-
cases
144+
let mut testcases = auxiliaries;
145+
testcases.extend(cases);
146+
testcases
141147
}
142148
}
143149

0 commit comments

Comments
 (0)