Skip to content

Commit 2888098

Browse files
committed
Auto merge of #148003 - aDotInTheVoid:rustdoc-postcard-compiletest-groundwork, r=jieyouxu
compiletest: pass rustdoc mode as param, rather than implicitly Spun out of #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. r? `@jieyouxu` CC `@jalil-salame`
2 parents 58b4453 + 616fff7 commit 2888098

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
@@ -999,8 +999,15 @@ impl<'test> TestCx<'test> {
999999

10001000
/// `root_out_dir` and `root_testpaths` refer to the parameters of the actual test being run.
10011001
/// Auxiliaries, no matter how deep, have the same root_out_dir and root_testpaths.
1002-
fn document(&self, root_out_dir: &Utf8Path, root_testpaths: &TestPaths) -> ProcRes {
1002+
fn document(
1003+
&self,
1004+
root_out_dir: &Utf8Path,
1005+
root_testpaths: &TestPaths,
1006+
kind: DocKind,
1007+
) -> ProcRes {
10031008
if self.props.build_aux_docs {
1009+
assert_eq!(kind, DocKind::Html, "build-aux-docs only make sense for html output");
1010+
10041011
for rel_ab in &self.props.aux.builds {
10051012
let aux_testpaths = self.compute_aux_test_paths(root_testpaths, rel_ab);
10061013
let props_for_aux =
@@ -1017,7 +1024,7 @@ impl<'test> TestCx<'test> {
10171024
create_dir_all(aux_cx.output_base_dir()).unwrap();
10181025
// use root_testpaths here, because aux-builds should have the
10191026
// same --out-dir and auxiliary directory.
1020-
let auxres = aux_cx.document(&root_out_dir, root_testpaths);
1027+
let auxres = aux_cx.document(&root_out_dir, root_testpaths, kind);
10211028
if !auxres.status.success() {
10221029
return auxres;
10231030
}
@@ -1062,8 +1069,11 @@ impl<'test> TestCx<'test> {
10621069
.args(&self.props.compile_flags)
10631070
.args(&self.props.doc_flags);
10641071

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

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

2205-
let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths);
2215+
let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths, DocKind::Html);
22062216
if !proc_res.status.success() {
22072217
writeln!(self.stderr, "failed to run nightly rustdoc");
22082218
return;
@@ -3120,6 +3130,12 @@ enum CompareOutcome {
31203130
Differed,
31213131
}
31223132

3133+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3134+
enum DocKind {
3135+
Html,
3136+
Json,
3137+
}
3138+
31233139
impl CompareOutcome {
31243140
fn should_error(&self) -> bool {
31253141
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)