Skip to content

Commit d69743b

Browse files
committed
compiletest runs my tests now
1 parent adb71cf commit d69743b

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl<'test> TestCx<'test> {
735735
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
736736
rustc.args(&self.props.compile_flags);
737737

738-
self.compose_and_run_compiler(rustc, Some(src))
738+
self.compose_and_run_compiler(&self.testpaths, rustc, Some(src))
739739
}
740740

741741
fn run_debuginfo_test(&self) {
@@ -1591,14 +1591,14 @@ impl<'test> TestCx<'test> {
15911591
passes,
15921592
);
15931593

1594-
self.compose_and_run_compiler(rustc, None)
1594+
self.compose_and_run_compiler(&self.testpaths, rustc, None)
15951595
}
15961596

15971597
/// aux: whether we are building the aux docs or main docs
1598-
fn document(&self, out_dir: &Path) -> ProcRes {
1598+
fn document(&self, out_dir: &Path, of: &TestPaths) -> ProcRes {
15991599
if self.props.build_aux_docs {
16001600
for rel_ab in &self.props.aux_builds {
1601-
let aux_testpaths = self.compute_aux_test_paths(dbg!(&self.testpaths), dbg!(rel_ab));
1601+
let aux_testpaths = self.compute_aux_test_paths(of, rel_ab);
16021602
let aux_props =
16031603
self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
16041604
let aux_cx = TestCx {
@@ -1609,12 +1609,7 @@ impl<'test> TestCx<'test> {
16091609
};
16101610
// Create the directory for the stdout/stderr files.
16111611
create_dir_all(aux_cx.output_base_dir()).unwrap();
1612-
let out_dir = if aux_props.unique_doc_aux_dir {
1613-
out_dir.join("docs").join(rel_ab.trim_end_matches(".rs")).join("doc")
1614-
} else {
1615-
out_dir.to_owned()
1616-
};
1617-
let auxres = aux_cx.document(&out_dir);
1612+
let auxres = aux_cx.document(&out_dir, of);
16181613
if !auxres.status.success() {
16191614
return auxres;
16201615
}
@@ -1625,14 +1620,28 @@ impl<'test> TestCx<'test> {
16251620

16261621
let rustdoc_path = self.config.rustdoc_path.as_ref().expect("--rustdoc-path not passed");
16271622

1623+
let out_dir = if self.props.unique_doc_aux_dir {
1624+
let file_name = self.testpaths.file.file_name().expect("file name should not be empty")
1625+
.to_str()
1626+
.expect("file name utf8")
1627+
.trim_end_matches(".rs");
1628+
let out_dir = out_dir.join("docs").join(file_name).join("doc");
1629+
create_dir_all(&out_dir).unwrap();
1630+
out_dir
1631+
} else {
1632+
out_dir.to_path_buf()
1633+
};
1634+
16281635
let mut rustdoc = Command::new(rustdoc_path);
1636+
let current_dir = output_base_dir(self.config, of, self.safe_revision());
1637+
rustdoc.current_dir(current_dir);
16291638
rustdoc
16301639
.arg("-L")
16311640
.arg(self.config.run_lib_path.to_str().unwrap())
16321641
.arg("-L")
16331642
.arg(aux_dir)
16341643
.arg("-o")
1635-
.arg(out_dir)
1644+
.arg(&out_dir)
16361645
.arg("--deny")
16371646
.arg("warnings")
16381647
.arg(&self.testpaths.file)
@@ -1649,7 +1658,7 @@ impl<'test> TestCx<'test> {
16491658
rustdoc.arg(format!("-Clinker={}", linker));
16501659
}
16511660

1652-
self.compose_and_run_compiler(rustdoc, None)
1661+
self.compose_and_run_compiler(of, rustdoc, None)
16531662
}
16541663

16551664
fn exec_compiled_test(&self) -> ProcRes {
@@ -1765,7 +1774,6 @@ impl<'test> TestCx<'test> {
17651774
fn compute_aux_test_paths(&self, of: &TestPaths, rel_ab: &str) -> TestPaths {
17661775
let test_ab =
17671776
of.file.parent().expect("test file path has no parent").join("auxiliary").join(rel_ab);
1768-
dbg!(&of, rel_ab, &test_ab);
17691777
if !test_ab.exists() {
17701778
self.fatal(&format!("aux-build `{}` source not found", test_ab.display()))
17711779
}
@@ -1848,9 +1856,9 @@ impl<'test> TestCx<'test> {
18481856
}
18491857
}
18501858

1851-
fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes {
1859+
fn compose_and_run_compiler(&self, testpaths: &TestPaths, mut rustc: Command, input: Option<String>) -> ProcRes {
18521860
let aux_dir = self.aux_output_dir();
1853-
self.build_all_auxiliary(&self.testpaths, &aux_dir, &mut rustc);
1861+
self.build_all_auxiliary(testpaths, &aux_dir, &mut rustc);
18541862

18551863
rustc.envs(self.props.rustc_env.clone());
18561864
self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove);
@@ -1870,7 +1878,7 @@ impl<'test> TestCx<'test> {
18701878
aux_dir: &Path,
18711879
is_bin: bool,
18721880
) -> AuxType {
1873-
let aux_testpaths = self.compute_aux_test_paths(dbg!(of), dbg!(source_path));
1881+
let aux_testpaths = self.compute_aux_test_paths(of, source_path);
18741882
let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
18751883
let mut aux_dir = aux_dir.to_path_buf();
18761884
if is_bin {
@@ -2041,7 +2049,7 @@ impl<'test> TestCx<'test> {
20412049
let is_aux = input_file.components().map(|c| c.as_os_str()).any(|c| c == "auxiliary");
20422050
let is_rustdoc = self.is_rustdoc() && !is_aux;
20432051
let mut rustc = if !is_rustdoc {
2044-
Command::new(&self.config.rustc_path)
2052+
Command::new(dbg!(&self.config.rustc_path))
20452053
} else {
20462054
Command::new(&self.config.rustdoc_path.clone().expect("no rustdoc built yet"))
20472055
};
@@ -2565,7 +2573,7 @@ impl<'test> TestCx<'test> {
25652573
Vec::new(),
25662574
);
25672575

2568-
let proc_res = self.compose_and_run_compiler(rustc, None);
2576+
let proc_res = self.compose_and_run_compiler(&self.testpaths, rustc, None);
25692577
let output_path = self.get_filecheck_file("ll");
25702578
(proc_res, output_path)
25712579
}
@@ -2601,7 +2609,7 @@ impl<'test> TestCx<'test> {
26012609
Vec::new(),
26022610
);
26032611

2604-
let proc_res = self.compose_and_run_compiler(rustc, None);
2612+
let proc_res = self.compose_and_run_compiler(&self.testpaths, rustc, None);
26052613
let output_path = self.get_filecheck_file("s");
26062614
(proc_res, output_path)
26072615
}
@@ -2684,7 +2692,7 @@ impl<'test> TestCx<'test> {
26842692
let out_dir = self.output_base_dir();
26852693
remove_and_create_dir_all(&out_dir);
26862694

2687-
let proc_res = self.document(&out_dir);
2695+
let proc_res = self.document(&out_dir, &self.testpaths);
26882696
if !proc_res.status.success() {
26892697
self.fatal_proc_rec("rustdoc failed!", &proc_res);
26902698
}
@@ -2743,7 +2751,7 @@ impl<'test> TestCx<'test> {
27432751
let aux_dir = new_rustdoc.aux_output_dir();
27442752
new_rustdoc.build_all_auxiliary(&new_rustdoc.testpaths, &aux_dir, &mut rustc);
27452753

2746-
let proc_res = new_rustdoc.document(&compare_dir);
2754+
let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths);
27472755
if !proc_res.status.success() {
27482756
eprintln!("failed to run nightly rustdoc");
27492757
return;
@@ -2866,7 +2874,7 @@ impl<'test> TestCx<'test> {
28662874
let out_dir = self.output_base_dir();
28672875
remove_and_create_dir_all(&out_dir);
28682876

2869-
let proc_res = self.document(&out_dir);
2877+
let proc_res = self.document(&out_dir, &self.testpaths);
28702878
if !proc_res.status.success() {
28712879
self.fatal_proc_rec("rustdoc failed!", &proc_res);
28722880
}
@@ -2942,28 +2950,27 @@ impl<'test> TestCx<'test> {
29422950
fn check_rustdoc_test_option(&self, res: ProcRes) {
29432951
let mut other_files = Vec::new();
29442952
let mut files: HashMap<String, Vec<usize>> = HashMap::new();
2945-
let cwd = env::current_dir().unwrap();
2946-
files.insert(
2947-
self.testpaths
2948-
.file
2949-
.strip_prefix(&cwd)
2950-
.unwrap_or(&self.testpaths.file)
2953+
let testpath = fs::canonicalize(&self.testpaths.file)
2954+
.expect("failed to canonicalize");
2955+
let testpath = testpath
29512956
.to_str()
29522957
.unwrap()
2953-
.replace('\\', "/"),
2958+
.replace('\\', "/");
2959+
files.insert(
2960+
testpath,
29542961
self.get_lines(&self.testpaths.file, Some(&mut other_files)),
29552962
);
29562963
for other_file in other_files {
29572964
let mut path = self.testpaths.file.clone();
29582965
path.set_file_name(&format!("{}.rs", other_file));
2959-
files.insert(
2960-
path.strip_prefix(&cwd).unwrap_or(&path).to_str().unwrap().replace('\\', "/"),
2961-
self.get_lines(&path, None),
2962-
);
2966+
let path = fs::canonicalize(path).expect("failed to canonicalize");
2967+
let normalized = path.to_str().unwrap().replace('\\', "/");
2968+
files.insert(normalized, self.get_lines(&path, None));
29632969
}
29642970

29652971
let mut tested = 0;
29662972
for _ in res.stdout.split('\n').filter(|s| s.starts_with("test ")).inspect(|s| {
2973+
dbg!(&s);
29672974
if let Some((left, right)) = s.split_once(" - ") {
29682975
let path = left.rsplit("test ").next().unwrap();
29692976
if let Some(ref mut v) = files.get_mut(&path.replace('\\', "/")) {
@@ -3796,7 +3803,7 @@ impl<'test> TestCx<'test> {
37963803
if let Some(nodejs) = &self.config.nodejs {
37973804
let out_dir = self.output_base_dir();
37983805

3799-
self.document(&out_dir);
3806+
self.document(&out_dir, &self.testpaths);
38003807

38013808
let root = self.config.find_rust_src_root().unwrap();
38023809
let file_stem =
@@ -4112,7 +4119,7 @@ impl<'test> TestCx<'test> {
41124119
rustc.arg(crate_name);
41134120
}
41144121

4115-
let res = self.compose_and_run_compiler(rustc, None);
4122+
let res = self.compose_and_run_compiler(&self.testpaths, rustc, None);
41164123
if !res.status.success() {
41174124
self.fatal_proc_rec("failed to compile fixed code", &res);
41184125
}

src/tools/compiletest/src/runtest/coverage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'test> TestCx<'test> {
191191

192192
rustdoc_cmd.arg(&self.testpaths.file);
193193

194-
let proc_res = self.compose_and_run_compiler(rustdoc_cmd, None);
194+
let proc_res = self.compose_and_run_compiler(&self.testpaths, rustdoc_cmd, None);
195195
if !proc_res.status.success() {
196196
self.fatal_proc_rec("rustdoc --test failed!", &proc_res)
197197
}

0 commit comments

Comments
 (0)