Skip to content

Commit 616fff7

Browse files
committed
compiletest: pass rustdoc mode as param, rather than implicitly
Spun out of https://www.github.com/rust-lang/rust/pull/142642 In the future, I want the rustdoc-json test suite to invoke rustdoc twice, once with `--output-format=json`, and once with the (not yet implemented) `--output-format=postcard` flag. Doing that requires being able to explicitly tell the `.document()` function which format to use, rather then implicitly using json in the rustdoc-json suite, and HTML in all others.
1 parent dc1feab commit 616fff7

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,15 @@ impl<'test> TestCx<'test> {
10001000

10011001
/// `root_out_dir` and `root_testpaths` refer to the parameters of the actual test being run.
10021002
/// Auxiliaries, no matter how deep, have the same root_out_dir and root_testpaths.
1003-
fn document(&self, root_out_dir: &Utf8Path, root_testpaths: &TestPaths) -> ProcRes {
1003+
fn document(
1004+
&self,
1005+
root_out_dir: &Utf8Path,
1006+
root_testpaths: &TestPaths,
1007+
kind: DocKind,
1008+
) -> ProcRes {
10041009
if self.props.build_aux_docs {
1010+
assert_eq!(kind, DocKind::Html, "build-aux-docs only make sense for html output");
1011+
10051012
for rel_ab in &self.props.aux.builds {
10061013
let aux_testpaths = self.compute_aux_test_paths(root_testpaths, rel_ab);
10071014
let props_for_aux =
@@ -1018,7 +1025,7 @@ impl<'test> TestCx<'test> {
10181025
create_dir_all(aux_cx.output_base_dir()).unwrap();
10191026
// use root_testpaths here, because aux-builds should have the
10201027
// same --out-dir and auxiliary directory.
1021-
let auxres = aux_cx.document(&root_out_dir, root_testpaths);
1028+
let auxres = aux_cx.document(&root_out_dir, root_testpaths, kind);
10221029
if !auxres.status.success() {
10231030
return auxres;
10241031
}
@@ -1063,8 +1070,11 @@ impl<'test> TestCx<'test> {
10631070
.args(&self.props.compile_flags)
10641071
.args(&self.props.doc_flags);
10651072

1066-
if self.config.mode == TestMode::RustdocJson {
1067-
rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options");
1073+
match kind {
1074+
DocKind::Html => {}
1075+
DocKind::Json => {
1076+
rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options");
1077+
}
10681078
}
10691079

10701080
if let Some(ref linker) = self.config.target_linker {
@@ -2203,7 +2213,7 @@ impl<'test> TestCx<'test> {
22032213
let aux_dir = new_rustdoc.aux_output_dir();
22042214
new_rustdoc.build_all_auxiliary(&new_rustdoc.testpaths, &aux_dir, &mut rustc);
22052215

2206-
let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths);
2216+
let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths, DocKind::Html);
22072217
if !proc_res.status.success() {
22082218
writeln!(self.stderr, "failed to run nightly rustdoc");
22092219
return;
@@ -3121,6 +3131,12 @@ enum CompareOutcome {
31213131
Differed,
31223132
}
31233133

3134+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3135+
enum DocKind {
3136+
Html,
3137+
Json,
3138+
}
3139+
31243140
impl CompareOutcome {
31253141
fn should_error(&self) -> bool {
31263142
matches!(self, CompareOutcome::Differed)

src/tools/compiletest/src/runtest/js_doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::process::Command;
22

3-
use super::TestCx;
3+
use super::{DocKind, TestCx};
44

55
impl TestCx<'_> {
66
pub(super) fn run_rustdoc_js_test(&self) {
77
if let Some(nodejs) = &self.config.nodejs {
88
let out_dir = self.output_base_dir();
99

10-
self.document(&out_dir, &self.testpaths);
10+
self.document(&out_dir, &self.testpaths, DocKind::Html);
1111

1212
let file_stem = self.testpaths.file.file_stem().expect("no file stem");
1313
let res = self.run_command_to_procres(

src/tools/compiletest/src/runtest/rustdoc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::process::Command;
22

3-
use super::{TestCx, remove_and_create_dir_all};
3+
use super::{DocKind, TestCx, remove_and_create_dir_all};
44

55
impl TestCx<'_> {
66
pub(super) fn run_rustdoc_test(&self) {
@@ -11,7 +11,7 @@ impl TestCx<'_> {
1111
panic!("failed to remove and recreate output directory `{out_dir}`: {e}")
1212
});
1313

14-
let proc_res = self.document(&out_dir, &self.testpaths);
14+
let proc_res = self.document(&out_dir, &self.testpaths, DocKind::Html);
1515
if !proc_res.status.success() {
1616
self.fatal_proc_rec("rustdoc failed!", &proc_res);
1717
}

src/tools/compiletest/src/runtest/rustdoc_json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::process::Command;
22

3-
use super::{TestCx, remove_and_create_dir_all};
3+
use super::{DocKind, TestCx, remove_and_create_dir_all};
44

55
impl TestCx<'_> {
66
pub(super) fn run_rustdoc_json_test(&self) {
@@ -13,7 +13,7 @@ impl TestCx<'_> {
1313
panic!("failed to remove and recreate output directory `{out_dir}`: {e}")
1414
});
1515

16-
let proc_res = self.document(&out_dir, &self.testpaths);
16+
let proc_res = self.document(&out_dir, &self.testpaths, DocKind::Json);
1717
if !proc_res.status.success() {
1818
self.fatal_proc_rec("rustdoc failed!", &proc_res);
1919
}

0 commit comments

Comments
 (0)