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

Improve rustdoc gui tester #85191

Merged
merged 3 commits into from
May 12, 2021
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
25 changes: 19 additions & 6 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,17 +827,30 @@ impl Step for RustdocGUI {
}

let out_dir = builder.test_out(self.target).join("rustdoc-gui");
let mut command = builder.rustdoc_cmd(self.compiler);
command.arg("src/test/rustdoc-gui/lib.rs").arg("-o").arg(&out_dir);
builder.run(&mut command);

// We remove existing folder to be sure there won't be artifacts remaining.
let _ = fs::remove_dir_all(&out_dir);

// We generate docs for the libraries present in the rustdoc-gui's src folder.
let libs_dir = builder.build.src.join("src/test/rustdoc-gui/src");
for entry in libs_dir.read_dir().expect("read_dir call failed") {
let entry = entry.expect("invalid entry");
let path = entry.path();
if path.extension().map(|e| e == "rs").unwrap_or(false) {
let mut command = builder.rustdoc_cmd(self.compiler);
command.arg(path).arg("-o").arg(&out_dir);
builder.run(&mut command);
}
}

// We now run GUI tests.
let mut command = Command::new(&nodejs);
command
.arg("src/tools/rustdoc-gui/tester.js")
.arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
.arg("--doc-folder")
.arg(out_dir.join("test_docs"))
.arg(out_dir)
.arg("--tests-folder")
.arg("src/test/rustdoc-gui");
.arg(builder.build.src.join("src/test/rustdoc-gui"));
builder.run(&mut command);
} else {
builder.info("No nodejs found, skipping \"src/test/rustdoc-gui\" tests");
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/basic-code.goml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
click: ".srclink"
assert: (".line-numbers", 1)
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/basic.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
assert: ("#functions")
goto: ./struct.Foo.html
assert: ("div.type-decl")
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/check_info_sign_position.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
goto: ./fn.check_list_code_block.html
// If the codeblock is the first element of the docblock, the information tooltip must have
// have some top margin to avoid going over the toggle (the "[+]").
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/code-sidebar-toggle.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
click: ".srclink"
click: "#sidebar-toggle"
wait-for: 500
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/hash-item-expansion.goml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This test ensures that the element corresponding to the hash is displayed.
goto: file://|DOC_PATH|/struct.Foo.html#method.borrow
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.borrow
// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "")
// Please note the "\" below is needed because otherwise ".borrow" would be interpreted as
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/impl-default-expansion.goml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This test ensures that the impl blocks are open by default.
goto: file://|DOC_PATH|/struct.Foo.html
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
assert: ("#main > details.implementors-toggle", "open", "")
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/list_code_block.goml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
goto: ./fn.check_list_code_block.html
assert: ("pre.rust.fn")
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/search-input-mobile.goml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test to ensure that you can click on the search input, whatever the width.
// The PR which fixed it is: https://github.com/rust-lang/rust/pull/81592
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
size: (463, 700)
// We first check that the search input isn't already focused.
assert-false: ("input.search-input:focus")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
write: (".search-input", "Foo")
// Waiting for the search results to appear...
wait-for: "#titles"
assert: ("#titles > button:nth-of-type(1)", "class", "selected")

// To go back to the original "state"
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
write: (".search-input", "-> String")
// Waiting for the search results to appear...
wait-for: "#titles"
// With this search, only the last tab shouldn't be empty so it should be selected.
assert: ("#titles > button:nth-of-type(3)", "class", "selected")

// To go back to the original "state"
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
write: (".search-input", "-> Something")
// Waiting for the search results to appear...
wait-for: "#titles"
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/shortcuts.goml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Check that the various shortcuts are working.
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
// We first check that the search input isn't already focused.
assert-false: "input.search-input:focus"
press-key: "s"
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-gui/source-code-page.goml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
goto: file://|DOC_PATH|/../src/test_docs/lib.rs.html
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
// Check that we can click on the line number.
click: (40, 224) // This is the position of the span for line 4.
// Unfortunately, "#4" isn't a valid query selector, so we have to go around that limitation
// by instead getting the nth span.
assert: (".line-numbers > span:nth-child(4)", "class", "line-highlighted")
// We now check that the good spans are highlighted
goto: file://|DOC_PATH|/../src/test_docs/lib.rs.html#4-6
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html#4-6
assert-false: (".line-numbers > span:nth-child(3)", "class", "line-highlighted")
assert: (".line-numbers > span:nth-child(4)", "class", "line-highlighted")
assert: (".line-numbers > span:nth-child(5)", "class", "line-highlighted")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/theme-change.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
click: "#theme-picker"
click: "#theme-choices > button:first-child"
wait-for: 500
Expand Down
13 changes: 8 additions & 5 deletions src/test/rustdoc-gui/toggle-docs.goml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
goto: file://|DOC_PATH|/index.html
goto: file://|DOC_PATH|/test_docs/index.html
assert: ("#main > details.top-doc", "open", "")
click: "#toggle-all-docs"
wait-for: 5000
assert: ("#main > div.docblock.hidden-by-usual-hider")
wait-for: 1000
// This is now collapsed so there shouldn't be the "open" attribute on details.
assert-false: ("#main > details.top-doc", "open", "")
click: "#toggle-all-docs"
wait-for: 5000
assert: ("#main > div.docblock.hidden-by-usual-hider", 0)
wait-for: 1000
// Not collapsed anymore so the "open" attribute should be back.
assert: ("#main > details.top-doc", "open", "")
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/trait-sidebar-item-order.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
goto: file://|DOC_PATH|/trait.AnotherOne.html
goto: file://|DOC_PATH|/test_docs/trait.AnotherOne.html
assert: (".sidebar-links a:nth-of-type(1)", "another")
assert: (".sidebar-links a:nth-of-type(2)", "func1")
assert: (".sidebar-links a:nth-of-type(3)", "func2")
Expand Down