diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ff275df9b31c0..c85864631a0a3 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1000,8 +1000,15 @@ impl<'test> TestCx<'test> { /// `root_out_dir` and `root_testpaths` refer to the parameters of the actual test being run. /// Auxiliaries, no matter how deep, have the same root_out_dir and root_testpaths. - fn document(&self, root_out_dir: &Utf8Path, root_testpaths: &TestPaths) -> ProcRes { + fn document( + &self, + root_out_dir: &Utf8Path, + root_testpaths: &TestPaths, + kind: DocKind, + ) -> ProcRes { if self.props.build_aux_docs { + assert_eq!(kind, DocKind::Html, "build-aux-docs doesn't make sense for rustdoc json"); + for rel_ab in &self.props.aux.builds { let aux_testpaths = self.compute_aux_test_paths(root_testpaths, rel_ab); let props_for_aux = @@ -1018,7 +1025,7 @@ impl<'test> TestCx<'test> { create_dir_all(aux_cx.output_base_dir()).unwrap(); // use root_testpaths here, because aux-builds should have the // same --out-dir and auxiliary directory. - let auxres = aux_cx.document(&root_out_dir, root_testpaths); + let auxres = aux_cx.document(&root_out_dir, root_testpaths, kind); if !auxres.status.success() { return auxres; } @@ -1063,8 +1070,11 @@ impl<'test> TestCx<'test> { .args(&self.props.compile_flags) .args(&self.props.doc_flags); - if self.config.mode == TestMode::RustdocJson { - rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options"); + match kind { + DocKind::Html => {} + DocKind::Json => { + rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options"); + } } if let Some(ref linker) = self.config.target_linker { @@ -2203,7 +2213,7 @@ impl<'test> TestCx<'test> { let aux_dir = new_rustdoc.aux_output_dir(); new_rustdoc.build_all_auxiliary(&new_rustdoc.testpaths, &aux_dir, &mut rustc); - let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths); + let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths, DocKind::Html); if !proc_res.status.success() { writeln!(self.stderr, "failed to run nightly rustdoc"); return; @@ -3121,6 +3131,12 @@ enum CompareOutcome { Differed, } +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum DocKind { + Html, + Json, +} + impl CompareOutcome { fn should_error(&self) -> bool { matches!(self, CompareOutcome::Differed) diff --git a/src/tools/compiletest/src/runtest/js_doc.rs b/src/tools/compiletest/src/runtest/js_doc.rs index fd53f01ca1746..93b05617e6f8c 100644 --- a/src/tools/compiletest/src/runtest/js_doc.rs +++ b/src/tools/compiletest/src/runtest/js_doc.rs @@ -1,13 +1,13 @@ use std::process::Command; -use super::TestCx; +use super::{DocKind, TestCx}; impl TestCx<'_> { pub(super) fn run_rustdoc_js_test(&self) { if let Some(nodejs) = &self.config.nodejs { let out_dir = self.output_base_dir(); - self.document(&out_dir, &self.testpaths); + self.document(&out_dir, &self.testpaths, DocKind::Html); let file_stem = self.testpaths.file.file_stem().expect("no file stem"); let res = self.run_command_to_procres( diff --git a/src/tools/compiletest/src/runtest/rustdoc.rs b/src/tools/compiletest/src/runtest/rustdoc.rs index 4a143aa5824e7..32b1823961bea 100644 --- a/src/tools/compiletest/src/runtest/rustdoc.rs +++ b/src/tools/compiletest/src/runtest/rustdoc.rs @@ -1,6 +1,6 @@ use std::process::Command; -use super::{TestCx, remove_and_create_dir_all}; +use super::{DocKind, TestCx, remove_and_create_dir_all}; impl TestCx<'_> { pub(super) fn run_rustdoc_test(&self) { @@ -11,7 +11,7 @@ impl TestCx<'_> { panic!("failed to remove and recreate output directory `{out_dir}`: {e}") }); - let proc_res = self.document(&out_dir, &self.testpaths); + let proc_res = self.document(&out_dir, &self.testpaths, DocKind::Html); if !proc_res.status.success() { self.fatal_proc_rec("rustdoc failed!", &proc_res); } diff --git a/src/tools/compiletest/src/runtest/rustdoc_json.rs b/src/tools/compiletest/src/runtest/rustdoc_json.rs index b8da6e2ac5280..dd7ebe9efaeef 100644 --- a/src/tools/compiletest/src/runtest/rustdoc_json.rs +++ b/src/tools/compiletest/src/runtest/rustdoc_json.rs @@ -1,6 +1,6 @@ use std::process::Command; -use super::{TestCx, remove_and_create_dir_all}; +use super::{DocKind, TestCx, remove_and_create_dir_all}; impl TestCx<'_> { pub(super) fn run_rustdoc_json_test(&self) { @@ -13,7 +13,7 @@ impl TestCx<'_> { panic!("failed to remove and recreate output directory `{out_dir}`: {e}") }); - let proc_res = self.document(&out_dir, &self.testpaths); + let proc_res = self.document(&out_dir, &self.testpaths, DocKind::Json); if !proc_res.status.success() { self.fatal_proc_rec("rustdoc failed!", &proc_res); }