Skip to content

Closes report doctest line numbers in a clickable format #143839

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,10 @@ impl ScrapedDocTest {
global_crate_attrs: Vec<String>,
) -> Self {
let mut item_path = logical_path.join("::");
item_path.retain(|c| c != ' ');
if !item_path.is_empty() {
item_path.push(' ');
item_path.insert_str(0, " - ");
}
let name =
format!("{} - {item_path}(line {line})", filename.prefer_remapped_unconditionally());
let name = format!("{}:{line}{item_path}", filename.prefer_remapped_unconditionally());

Self { filename, line, langstr, text, name, span, global_crate_attrs }
}
Expand Down
18 changes: 5 additions & 13 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,23 +2272,15 @@ impl<'test> TestCx<'test> {

let mut tested = 0;
for _ in res.stdout.split('\n').filter(|s| s.starts_with("test ")).inspect(|s| {
if let Some((left, right)) = s.split_once(" - ") {
let path = left.rsplit("test ").next().unwrap();
if let Some((left, _)) = s.split_once(" - ") {
let path_with_line = left.rsplit("test ").next().unwrap();
let (path, line_number) =
path_with_line.rsplit_once(":").expect("line number not found");
let path = fs::canonicalize(&path).expect("failed to canonicalize");
let path = path.to_str().unwrap().replace('\\', "/");
if let Some(ref mut v) = files.get_mut(&path) {
tested += 1;
let mut iter = right.split("(line ");
iter.next();
let line = iter
.next()
.unwrap_or(")")
.split(')')
.next()
.unwrap_or("0")
.parse()
.unwrap_or(0);
if let Ok(pos) = v.binary_search(&line) {
if let Ok(pos) = v.binary_search(&line_number.parse::<usize>().unwrap_or(0)) {
v.remove(pos);
} else {
self.fatal_proc_rec(
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/doctests-merge/doctest-2021.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

running 2 tests
test doctest.rs - (line 4) ... ok
test doctest.rs - init (line 8) ... ok
test doctest.rs:4 ... ok
test doctest.rs:8 - init ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

4 changes: 2 additions & 2 deletions tests/run-make/doctests-merge/doctest-2024.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

running 2 tests
test doctest.rs - (line 4) ... ok
test doctest.rs - init (line 8) ... ok
test doctest.rs:4 ... ok
test doctest.rs:8 - init ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

4 changes: 2 additions & 2 deletions tests/run-make/doctests-merge/doctest-standalone.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

running 2 tests
test doctest-standalone.rs - (line 4) ... ok
test doctest-standalone.rs - init (line 8) ... ok
test doctest-standalone.rs:4 ... ok
test doctest-standalone.rs:8 - init ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

2 changes: 1 addition & 1 deletion tests/run-make/rustdoc-cfgspec-parsing/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ fn main() {
.library_search_path(cwd())
.input("foo.rs")
.run()
.assert_stdout_contains("foo.rs - foo (line 1) ... ok");
.assert_stdout_contains("foo.rs:1 - foo ... ok");
}
6 changes: 3 additions & 3 deletions tests/run-make/rustdoc-error-lines/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fn main() {
let output = rustdoc().input("input.rs").arg("--test").run_fail().stdout_utf8();

let should_contain = &[
"input.rs - foo (line 5)",
"input.rs:5 - foo",
"input.rs:8:15",
"input.rs - bar (line 13)",
"input.rs:13 - bar",
"input.rs:16:15",
"input.rs - bar (line 22)",
"input.rs:22 - bar",
"input.rs:25:15",
];
for text in should_contain {
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc-ui/2024-doctests-checks.stdout
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

running 1 test
test $DIR/2024-doctests-checks.rs - Foo (line 8) ... ok
test $DIR/2024-doctests-checks.rs:8 - Foo ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME


running 1 test
test $DIR/2024-doctests-checks.rs - Foo (line 15) ... ok
test $DIR/2024-doctests-checks.rs:15 - Foo ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

4 changes: 2 additions & 2 deletions tests/rustdoc-ui/2024-doctests-crate-attribute.stdout
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

running 1 test
test $DIR/2024-doctests-crate-attribute.rs - Foo (line 20) ... ok
test $DIR/2024-doctests-crate-attribute.rs:20 - Foo ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME


running 1 test
test $DIR/2024-doctests-crate-attribute.rs - Foo (line 11) ... ok
test $DIR/2024-doctests-crate-attribute.rs:11 - Foo ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

4 changes: 2 additions & 2 deletions tests/rustdoc-ui/doctest/cfg-test.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

running 2 tests
test $DIR/cfg-test.rs - Bar (line 27) ... ok
test $DIR/cfg-test.rs - Foo (line 19) ... ok
test $DIR/cfg-test.rs:19 - Foo ... ok
test $DIR/cfg-test.rs:27 - Bar ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

2 changes: 1 addition & 1 deletion tests/rustdoc-ui/doctest/check-cfg-test.stdout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

running 1 test
test $DIR/check-cfg-test.rs - Foo (line 8) ... ok
test $DIR/check-cfg-test.rs:8 - Foo ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

8 changes: 4 additions & 4 deletions tests/rustdoc-ui/doctest/comment-in-attr-134221-2.stdout
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

running 2 tests
test $DIR/comment-in-attr-134221-2.rs - (line 11) ... FAILED
test $DIR/comment-in-attr-134221-2.rs - (line 7) ... ok
test $DIR/comment-in-attr-134221-2.rs:11 ... FAILED
test $DIR/comment-in-attr-134221-2.rs:7 ... ok

failures:

---- $DIR/comment-in-attr-134221-2.rs - (line 11) stdout ----
---- $DIR/comment-in-attr-134221-2.rs:11 stdout ----
error: unknown start of token: \
--> $DIR/comment-in-attr-134221-2.rs:$LINE:$COL
|
Expand All @@ -25,7 +25,7 @@ error: aborting due to 2 previous errors
Couldn't compile the test.

failures:
$DIR/comment-in-attr-134221-2.rs - (line 11)
$DIR/comment-in-attr-134221-2.rs:11

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

18 changes: 9 additions & 9 deletions tests/rustdoc-ui/doctest/comment-in-attr-134221.stdout
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

running 3 tests
test $DIR/comment-in-attr-134221.rs - (line 11) ... FAILED
test $DIR/comment-in-attr-134221.rs - (line 17) ... FAILED
test $DIR/comment-in-attr-134221.rs - (line 23) ... FAILED
test $DIR/comment-in-attr-134221.rs:11 ... FAILED
test $DIR/comment-in-attr-134221.rs:17 ... FAILED
test $DIR/comment-in-attr-134221.rs:23 ... FAILED

failures:

---- $DIR/comment-in-attr-134221.rs - (line 11) stdout ----
---- $DIR/comment-in-attr-134221.rs:11 stdout ----
error[E0635]: unknown feature `foo`
--> $DIR/comment-in-attr-134221.rs:$LINE:$COL
|
Expand All @@ -17,7 +17,7 @@ error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0635`.
Couldn't compile the test.
---- $DIR/comment-in-attr-134221.rs - (line 17) stdout ----
---- $DIR/comment-in-attr-134221.rs:17 stdout ----
error[E0635]: unknown feature `foo`
--> $DIR/comment-in-attr-134221.rs:$LINE:$COL
|
Expand All @@ -28,7 +28,7 @@ error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0635`.
Couldn't compile the test.
---- $DIR/comment-in-attr-134221.rs - (line 23) stdout ----
---- $DIR/comment-in-attr-134221.rs:23 stdout ----
error: this file contains an unclosed delimiter
--> $DIR/comment-in-attr-134221.rs:$LINE:$COL
|
Expand All @@ -42,9 +42,9 @@ error: aborting due to 1 previous error
Couldn't compile the test.

failures:
$DIR/comment-in-attr-134221.rs - (line 11)
$DIR/comment-in-attr-134221.rs - (line 17)
$DIR/comment-in-attr-134221.rs - (line 23)
$DIR/comment-in-attr-134221.rs:11
$DIR/comment-in-attr-134221.rs:17
$DIR/comment-in-attr-134221.rs:23

test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

6 changes: 3 additions & 3 deletions tests/rustdoc-ui/doctest/dead-code-2024.stdout
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

running 1 test
test $DIR/dead-code-2024.rs - f (line 13) - compile ... FAILED
test $DIR/dead-code-2024.rs:13 - f - compile ... FAILED

failures:

---- $DIR/dead-code-2024.rs - f (line 13) stdout ----
---- $DIR/dead-code-2024.rs:13 - f stdout ----
error: trait `T` is never used
--> $DIR/dead-code-2024.rs:14:7
|
Expand All @@ -23,7 +23,7 @@ error: aborting due to 1 previous error
Couldn't compile the test.

failures:
$DIR/dead-code-2024.rs - f (line 13)
$DIR/dead-code-2024.rs:13 - f

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

Loading
Loading