Skip to content

Commit 4b1db07

Browse files
Don't special-case if there is only one merged doctest
1 parent 72aeffa commit 4b1db07

File tree

7 files changed

+43
-67
lines changed

7 files changed

+43
-67
lines changed

src/librustdoc/doctest.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -267,39 +267,35 @@ pub(crate) fn run_tests(
267267
if doctests.is_empty() {
268268
continue;
269269
}
270-
// If there is only one mergeable doctest, the cost to run it would be higher than just
271-
// running it alonside standalone doctests.
272-
if doctests.len() > 1 {
273-
doctests.sort_by(|(_, a), (_, b)| a.name.cmp(&b.name));
270+
doctests.sort_by(|(_, a), (_, b)| a.name.cmp(&b.name));
274271

275-
let mut tests_runner = runner::DocTestRunner::new();
272+
let mut tests_runner = runner::DocTestRunner::new();
276273

277-
let rustdoc_test_options = IndividualTestOptions::new(
278-
&rustdoc_options,
279-
&Some(format!("merged_doctest_{edition}")),
280-
PathBuf::from(format!("doctest_{edition}.rs")),
281-
);
274+
let rustdoc_test_options = IndividualTestOptions::new(
275+
&rustdoc_options,
276+
&Some(format!("merged_doctest_{edition}")),
277+
PathBuf::from(format!("doctest_{edition}.rs")),
278+
);
282279

283-
for (doctest, scraped_test) in &doctests {
284-
tests_runner.add_test(doctest, scraped_test, &target_str);
285-
}
286-
if let Ok(success) = tests_runner.run_merged_tests(
287-
rustdoc_test_options,
288-
edition,
289-
&opts,
290-
&test_args,
291-
rustdoc_options,
292-
) {
293-
ran_edition_tests += 1;
294-
if !success {
295-
nb_errors += 1;
296-
}
297-
continue;
280+
for (doctest, scraped_test) in &doctests {
281+
tests_runner.add_test(doctest, scraped_test, &target_str);
282+
}
283+
if let Ok(success) = tests_runner.run_merged_tests(
284+
rustdoc_test_options,
285+
edition,
286+
&opts,
287+
&test_args,
288+
rustdoc_options,
289+
) {
290+
ran_edition_tests += 1;
291+
if !success {
292+
nb_errors += 1;
298293
}
299-
// We failed to compile all compatible tests as one so we push them into the
300-
// `standalone_tests` doctests.
301-
debug!("Failed to compile compatible doctests for edition {} all at once", edition);
294+
continue;
302295
}
296+
// We failed to compile all compatible tests as one so we push them into the
297+
// `standalone_tests` doctests.
298+
debug!("Failed to compile compatible doctests for edition {} all at once", edition);
303299
for (doctest, scraped_test) in doctests {
304300
doctest.generate_unique_doctest(
305301
&scraped_test.text,

tests/rustdoc-ui/doctest/failed-doctest-should-panic.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
running 1 test
3-
test $DIR/failed-doctest-should-panic.rs - Foo (line 9) ... FAILED
3+
test $DIR/failed-doctest-should-panic.rs - Foo (line 9) - should panic ... FAILED
44

55
failures:
66

77
---- $DIR/failed-doctest-should-panic.rs - Foo (line 9) stdout ----
8-
Test executable succeeded, but it's marked `should_panic`.
8+
note: test did not panic as expected
99

1010
failures:
1111
$DIR/failed-doctest-should-panic.rs - Foo (line 9)

tests/rustdoc-ui/doctest/wrong-ast-2024.stdout

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

2-
running 3 tests
2+
running 1 test
3+
test $DIR/wrong-ast-2024.rs - three (line 17) - should panic ... ok
4+
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
6+
7+
8+
running 2 tests
39
test $DIR/wrong-ast-2024.rs - one (line 7) ... FAILED
4-
test $DIR/wrong-ast-2024.rs - three (line 17) ... ok
510
test $DIR/wrong-ast-2024.rs - two (line 12) ... FAILED
611

712
failures:
@@ -32,5 +37,5 @@ failures:
3237
$DIR/wrong-ast-2024.rs - one (line 7)
3338
$DIR/wrong-ast-2024.rs - two (line 12)
3439

35-
test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
40+
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
3641

tests/rustdoc-ui/doctest/wrong-ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ compile-flags:--test --test-args=--test-threads=1
22
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
33
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
4-
//@ normalize-stdout-test ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL"
54
//@ failure-status: 101
65

76
/// ```
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22
running 3 tests
3-
test $DIR/wrong-ast.rs - one (line 7) ... FAILED
4-
test $DIR/wrong-ast.rs - three (line 17) ... ok
5-
test $DIR/wrong-ast.rs - two (line 12) ... FAILED
3+
test $DIR/wrong-ast.rs - one (line 6) ... FAILED
4+
test $DIR/wrong-ast.rs - three (line 16) ... ok
5+
test $DIR/wrong-ast.rs - two (line 11) ... FAILED
66

77
failures:
88

9-
---- $DIR/wrong-ast.rs - one (line 7) stdout ----
9+
---- $DIR/wrong-ast.rs - one (line 6) stdout ----
1010
error[E0758]: unterminated block comment
11-
--> $DIR/wrong-ast.rs:$LINE:$COL
11+
--> $DIR/wrong-ast.rs:7:1
1212
|
1313
LL | /* plop
1414
| ^^^^^^^
@@ -17,9 +17,9 @@ error: aborting due to 1 previous error
1717

1818
For more information about this error, try `rustc --explain E0758`.
1919
Couldn't compile the test.
20-
---- $DIR/wrong-ast.rs - two (line 12) stdout ----
20+
---- $DIR/wrong-ast.rs - two (line 11) stdout ----
2121
error: unexpected closing delimiter: `}`
22-
--> $DIR/wrong-ast.rs:$LINE:$COL
22+
--> $DIR/wrong-ast.rs:12:1
2323
|
2424
LL | } mod __doctest_1 { fn main() {
2525
| ^ unexpected closing delimiter
@@ -29,8 +29,8 @@ error: aborting due to 1 previous error
2929
Couldn't compile the test.
3030

3131
failures:
32-
$DIR/wrong-ast.rs - one (line 7)
33-
$DIR/wrong-ast.rs - two (line 12)
32+
$DIR/wrong-ast.rs - one (line 6)
33+
$DIR/wrong-ast.rs - two (line 11)
3434

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

tests/rustdoc-ui/run-as-standalone.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/rustdoc-ui/run-as-standalone.stdout

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)