Skip to content

Commit dbfc95f

Browse files
committed
Auto merge of rust-lang#111348 - ozkanonur:remove-hardcoded-rustdoc-flags, r=albertlarsan68,oli-obk
new tool `rustdoc-gui-test` Implements new tool `rustdoc-gui-test` that allows using compiletest headers for `rustdoc-gui` tests.
2 parents 23040c4 + c7cec29 commit dbfc95f

File tree

18 files changed

+1435
-1231
lines changed

18 files changed

+1435
-1231
lines changed

Cargo.lock

+9
Original file line numberDiff line numberDiff line change
@@ -4379,6 +4379,15 @@ dependencies = [
43794379
"tracing-tree",
43804380
]
43814381

4382+
[[package]]
4383+
name = "rustdoc-gui-test"
4384+
version = "0.1.0"
4385+
dependencies = [
4386+
"compiletest",
4387+
"getopts",
4388+
"walkdir",
4389+
]
4390+
43824391
[[package]]
43834392
name = "rustdoc-json-types"
43844393
version = "0.1.0"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ members = [
4040
"src/tools/generate-copyright",
4141
"src/tools/suggest-tests",
4242
"src/tools/generate-windows-sys",
43+
"src/tools/rustdoc-gui-test",
4344
]
4445

4546
exclude = [

library/test/src/options.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ pub enum ShouldPanic {
1616
}
1717

1818
/// Whether should console output be colored or not
19-
#[derive(Copy, Clone, Debug)]
19+
#[derive(Copy, Clone, Default, Debug)]
2020
pub enum ColorConfig {
21+
#[default]
2122
AutoColor,
2223
AlwaysColor,
2324
NeverColor,
2425
}
2526

2627
/// Format of the test results output
27-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
28+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
2829
pub enum OutputFormat {
2930
/// Verbose output
3031
Pretty,
3132
/// Quiet output
33+
#[default]
3234
Terse,
3335
/// JSON output
3436
Json,

src/bootstrap/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ impl<'a> Builder<'a> {
689689
tool::Miri,
690690
tool::CargoMiri,
691691
llvm::Lld,
692-
llvm::CrtBeginEnd
692+
llvm::CrtBeginEnd,
693+
tool::RustdocGUITest,
693694
),
694695
Kind::Check | Kind::Clippy | Kind::Fix => describe!(
695696
check::Std,

src/bootstrap/test.rs

+28-88
Original file line numberDiff line numberDiff line change
@@ -944,28 +944,6 @@ fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
944944
.or_else(|| get_browser_ui_test_version_inner(npm, true))
945945
}
946946

947-
fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
948-
match fs::read_to_string(
949-
src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
950-
) {
951-
Ok(v) => {
952-
if v.trim() != installed_version {
953-
eprintln!(
954-
"⚠️ Installed version of browser-ui-test (`{}`) is different than the \
955-
one used in the CI (`{}`)",
956-
installed_version, v
957-
);
958-
eprintln!(
959-
"You can install this version using `npm update browser-ui-test` or by using \
960-
`npm install browser-ui-test@{}`",
961-
v,
962-
);
963-
}
964-
}
965-
Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
966-
}
967-
}
968-
969947
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
970948
pub struct RustdocGUI {
971949
pub target: TargetSelection,
@@ -997,94 +975,56 @@ impl Step for RustdocGUI {
997975
}
998976

999977
fn run(self, builder: &Builder<'_>) {
1000-
let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
1001-
let npm = builder.config.npm.as_ref().expect("npm isn't available");
1002-
1003978
builder.ensure(compile::Std::new(self.compiler, self.target));
1004979

1005-
// The goal here is to check if the necessary packages are installed, and if not, we
1006-
// panic.
1007-
match get_browser_ui_test_version(&npm) {
1008-
Some(version) => {
1009-
// We also check the version currently used in CI and emit a warning if it's not the
1010-
// same one.
1011-
compare_browser_ui_test_version(&version, &builder.build.src);
1012-
}
1013-
None => {
1014-
eprintln!(
1015-
"error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
1016-
dependency is missing",
1017-
);
1018-
eprintln!(
1019-
"If you want to install the `{0}` dependency, run `npm install {0}`",
1020-
"browser-ui-test",
1021-
);
1022-
panic!("Cannot run rustdoc-gui tests");
1023-
}
1024-
}
980+
let mut cmd = builder.tool_cmd(Tool::RustdocGUITest);
1025981

1026982
let out_dir = builder.test_out(self.target).join("rustdoc-gui");
1027-
1028-
// We remove existing folder to be sure there won't be artifacts remaining.
1029983
builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
1030984

1031-
let src_path = builder.build.src.join("tests/rustdoc-gui/src");
1032-
// We generate docs for the libraries present in the rustdoc-gui's src folder.
1033-
for entry in src_path.read_dir().expect("read_dir call failed") {
1034-
if let Ok(entry) = entry {
1035-
let path = entry.path();
985+
if let Some(src) = builder.config.src.to_str() {
986+
cmd.arg("--rust-src").arg(src);
987+
}
1036988

1037-
if !path.is_dir() {
1038-
continue;
1039-
}
989+
if let Some(out_dir) = out_dir.to_str() {
990+
cmd.arg("--out-dir").arg(out_dir);
991+
}
1040992

1041-
let mut cargo = Command::new(&builder.initial_cargo);
1042-
cargo
1043-
.arg("doc")
1044-
.arg("--target-dir")
1045-
.arg(&out_dir)
1046-
.env("RUSTC_BOOTSTRAP", "1")
1047-
.env("RUSTDOC", builder.rustdoc(self.compiler))
1048-
.env("RUSTC", builder.rustc(self.compiler))
1049-
.current_dir(path);
1050-
// FIXME: implement a `// compile-flags` command or similar
1051-
// instead of hard-coding this test
1052-
if entry.file_name() == "link_to_definition" {
1053-
cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
1054-
} else if entry.file_name() == "scrape_examples" {
1055-
cargo.arg("-Zrustdoc-scrape-examples");
1056-
} else if entry.file_name() == "extend_css" {
1057-
cargo.env("RUSTDOCFLAGS", &format!("--extend-css extra.css"));
1058-
}
1059-
builder.run(&mut cargo);
1060-
}
993+
if let Some(initial_cargo) = builder.config.initial_cargo.to_str() {
994+
cmd.arg("--initial-cargo").arg(initial_cargo);
1061995
}
1062996

1063-
// We now run GUI tests.
1064-
let mut command = Command::new(&nodejs);
1065-
command
1066-
.arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
1067-
.arg("--jobs")
1068-
.arg(&builder.jobs().to_string())
1069-
.arg("--doc-folder")
1070-
.arg(out_dir.join("doc"))
1071-
.arg("--tests-folder")
1072-
.arg(builder.build.src.join("tests/rustdoc-gui"));
997+
cmd.arg("--jobs").arg(builder.jobs().to_string());
998+
999+
cmd.env("RUSTDOC", builder.rustdoc(self.compiler))
1000+
.env("RUSTC", builder.rustc(self.compiler));
1001+
10731002
for path in &builder.paths {
10741003
if let Some(p) = util::is_valid_test_suite_arg(path, "tests/rustdoc-gui", builder) {
10751004
if !p.ends_with(".goml") {
10761005
eprintln!("A non-goml file was given: `{}`", path.display());
10771006
panic!("Cannot run rustdoc-gui tests");
10781007
}
10791008
if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
1080-
command.arg("--file").arg(name);
1009+
cmd.arg("--goml-file").arg(name);
10811010
}
10821011
}
10831012
}
1013+
10841014
for test_arg in builder.config.test_args() {
1085-
command.arg(test_arg);
1015+
cmd.arg("--test-arg").arg(test_arg);
10861016
}
1087-
builder.run(&mut command);
1017+
1018+
if let Some(ref nodejs) = builder.config.nodejs {
1019+
cmd.arg("--nodejs").arg(nodejs);
1020+
}
1021+
1022+
if let Some(ref npm) = builder.config.npm {
1023+
cmd.arg("--npm").arg(npm);
1024+
}
1025+
1026+
let _time = util::timeit(&builder);
1027+
crate::render_tests::try_run_tests(builder, &mut cmd);
10881028
}
10891029
}
10901030

src/bootstrap/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ bootstrap_tool!(
302302
GenerateCopyright, "src/tools/generate-copyright", "generate-copyright";
303303
SuggestTests, "src/tools/suggest-tests", "suggest-tests";
304304
GenerateWindowsSys, "src/tools/generate-windows-sys", "generate-windows-sys";
305+
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test", is_unstable_tool = true, allow_features = "test";
305306
);
306307

307308
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]

src/tools/compiletest/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "compiletest"
33
version = "0.0.0"
44
edition = "2021"
55

6+
[lib]
7+
doctest = false
8+
69
[dependencies]
710
colored = "2"
811
diff = "0.1.10"

src/tools/compiletest/src/common.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ string_enum! {
6969
}
7070
}
7171

72+
impl Default for Mode {
73+
fn default() -> Self {
74+
Mode::Ui
75+
}
76+
}
77+
7278
impl Mode {
7379
pub fn disambiguator(self) -> &'static str {
7480
// Pretty-printing tests could run concurrently, and if they do,
@@ -125,7 +131,7 @@ pub enum PanicStrategy {
125131
}
126132

127133
/// Configuration for compiletest
128-
#[derive(Debug, Clone)]
134+
#[derive(Debug, Default, Clone)]
129135
pub struct Config {
130136
/// `true` to overwrite stderr/stdout files instead of complaining about changes in output.
131137
pub bless: bool,

0 commit comments

Comments
 (0)