Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new tool rustdoc-gui-test #111348

Merged
merged 6 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4324,6 +4324,15 @@ dependencies = [
"tracing-tree",
]

[[package]]
name = "rustdoc-gui-test"
version = "0.1.0"
dependencies = [
"compiletest",
"getopts",
"walkdir",
]

[[package]]
name = "rustdoc-json-types"
version = "0.1.0"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"src/tools/generate-copyright",
"src/tools/suggest-tests",
"src/tools/generate-windows-sys",
"src/tools/rustdoc-gui-test",
]

exclude = [
Expand Down
6 changes: 4 additions & 2 deletions library/test/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ pub enum ShouldPanic {
}

/// Whether should console output be colored or not
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Default, Debug)]
pub enum ColorConfig {
#[default]
AutoColor,
AlwaysColor,
NeverColor,
}

/// Format of the test results output
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum OutputFormat {
/// Verbose output
Pretty,
/// Quiet output
#[default]
Terse,
/// JSON output
Json,
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@ impl<'a> Builder<'a> {
tool::Miri,
tool::CargoMiri,
llvm::Lld,
llvm::CrtBeginEnd
llvm::CrtBeginEnd,
tool::RustdocGUITest,
),
Kind::Check | Kind::Clippy | Kind::Fix => describe!(
check::Std,
Expand Down
116 changes: 28 additions & 88 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,28 +942,6 @@ fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
.or_else(|| get_browser_ui_test_version_inner(npm, true))
}

fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
match fs::read_to_string(
src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
) {
Ok(v) => {
if v.trim() != installed_version {
eprintln!(
"⚠️ Installed version of browser-ui-test (`{}`) is different than the \
one used in the CI (`{}`)",
installed_version, v
);
eprintln!(
"You can install this version using `npm update browser-ui-test` or by using \
`npm install browser-ui-test@{}`",
v,
);
}
}
Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocGUI {
pub target: TargetSelection,
Expand Down Expand Up @@ -995,94 +973,56 @@ impl Step for RustdocGUI {
}

fn run(self, builder: &Builder<'_>) {
let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
let npm = builder.config.npm.as_ref().expect("npm isn't available");

builder.ensure(compile::Std::new(self.compiler, self.target));

// The goal here is to check if the necessary packages are installed, and if not, we
// panic.
match get_browser_ui_test_version(&npm) {
Some(version) => {
// We also check the version currently used in CI and emit a warning if it's not the
// same one.
compare_browser_ui_test_version(&version, &builder.build.src);
}
None => {
eprintln!(
"error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
dependency is missing",
);
eprintln!(
"If you want to install the `{0}` dependency, run `npm install {0}`",
"browser-ui-test",
);
panic!("Cannot run rustdoc-gui tests");
}
}
let mut cmd = builder.tool_cmd(Tool::RustdocGUITest);

let out_dir = builder.test_out(self.target).join("rustdoc-gui");

// We remove existing folder to be sure there won't be artifacts remaining.
builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));

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

if !path.is_dir() {
continue;
}
if let Some(out_dir) = out_dir.to_str() {
cmd.arg("--out-dir").arg(out_dir);
}

let mut cargo = Command::new(&builder.initial_cargo);
cargo
.arg("doc")
.arg("--target-dir")
.arg(&out_dir)
.env("RUSTC_BOOTSTRAP", "1")
.env("RUSTDOC", builder.rustdoc(self.compiler))
.env("RUSTC", builder.rustc(self.compiler))
.current_dir(path);
// FIXME: implement a `// compile-flags` command or similar
// instead of hard-coding this test
if entry.file_name() == "link_to_definition" {
cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
} else if entry.file_name() == "scrape_examples" {
cargo.arg("-Zrustdoc-scrape-examples");
} else if entry.file_name() == "extend_css" {
cargo.env("RUSTDOCFLAGS", &format!("--extend-css extra.css"));
}
builder.run(&mut cargo);
}
if let Some(initial_cargo) = builder.config.initial_cargo.to_str() {
cmd.arg("--initial-cargo").arg(initial_cargo);
}

// We now run GUI tests.
let mut command = Command::new(&nodejs);
command
.arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
.arg("--jobs")
.arg(&builder.jobs().to_string())
.arg("--doc-folder")
.arg(out_dir.join("doc"))
.arg("--tests-folder")
.arg(builder.build.src.join("tests/rustdoc-gui"));
cmd.arg("--jobs").arg(builder.jobs().to_string());

cmd.env("RUSTDOC", builder.rustdoc(self.compiler))
.env("RUSTC", builder.rustc(self.compiler));

for path in &builder.paths {
if let Some(p) = util::is_valid_test_suite_arg(path, "tests/rustdoc-gui", builder) {
if !p.ends_with(".goml") {
eprintln!("A non-goml file was given: `{}`", path.display());
panic!("Cannot run rustdoc-gui tests");
}
if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
command.arg("--file").arg(name);
cmd.arg("--goml-file").arg(name);
}
}
}

for test_arg in builder.config.test_args() {
command.arg(test_arg);
cmd.arg("--test-arg").arg(test_arg);
}
builder.run(&mut command);

if let Some(ref nodejs) = builder.config.nodejs {
cmd.arg("--nodejs").arg(nodejs);
}

if let Some(ref npm) = builder.config.npm {
cmd.arg("--npm").arg(npm);
}

let _time = util::timeit(&builder);
crate::render_tests::try_run_tests(builder, &mut cmd);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ bootstrap_tool!(
GenerateCopyright, "src/tools/generate-copyright", "generate-copyright";
SuggestTests, "src/tools/suggest-tests", "suggest-tests";
GenerateWindowsSys, "src/tools/generate-windows-sys", "generate-windows-sys";
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test", is_unstable_tool = true, allow_features = "test";
);

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
Expand Down
3 changes: 3 additions & 0 deletions src/tools/compiletest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "compiletest"
version = "0.0.0"
edition = "2021"

[lib]
doctest = false

[dependencies]
colored = "2"
diff = "0.1.10"
Expand Down
8 changes: 7 additions & 1 deletion src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ string_enum! {
}
}

impl Default for Mode {
fn default() -> Self {
Mode::Ui
}
}

impl Mode {
pub fn disambiguator(self) -> &'static str {
// Pretty-printing tests could run concurrently, and if they do,
Expand Down Expand Up @@ -125,7 +131,7 @@ pub enum PanicStrategy {
}

/// Configuration for compiletest
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
pub struct Config {
/// `true` to overwrite stderr/stdout files instead of complaining about changes in output.
pub bless: bool,
Expand Down
Loading