Skip to content

Commit ca3ebea

Browse files
authored
Fix bug in auxiliary test case compilation in TestCommand (#11)
Signed-off-by: xizheyin <[email protected]>
1 parent 2f477f0 commit ca3ebea

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

bootstrap/src/test.rs

Lines changed: 20 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,37 @@ 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"(?m)//@\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) {
126+
println!("{:?}", case.source);
126127
let fname = cap.name("fname").unwrap().as_str();
127128
let source = Path::new("tests/auxiliary").join(fname);
128129
let filename = source.file_stem().unwrap();
129130
let name = format!("auxiliary/{}", filename.to_string_lossy());
131+
132+
// deduplication
133+
if auxiliaries.iter().any(|aux: &TestCase| aux.name == name) {
134+
continue;
135+
}
136+
130137
let output_file = manifest.out_dir.join(filename); // aux files are output to the base directory
131138
let testcase =
132139
TestCase::new(name, source, output_file, TestType::CompileLib, verbose);
133-
auxiliary.push(testcase);
140+
auxiliaries.push(testcase);
134141
}
135142
}
136143

137144
// Compile auxiliary before the tests
138-
let mut cases = auxiliary;
139-
cases.extend(tests);
140-
cases
145+
let mut testcases = auxiliaries;
146+
testcases.extend(cases);
147+
testcases
141148
}
142149
}
143150

0 commit comments

Comments
 (0)