mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Run mergeable doctest as part of standalone doctests if there is only one
This commit is contained in:
parent
bfabf1db44
commit
d512438435
@ -267,50 +267,53 @@ pub(crate) fn run_tests(
|
|||||||
if doctests.is_empty() {
|
if doctests.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
doctests.sort_by(|(_, a), (_, b)| a.name.cmp(&b.name));
|
// If there is only one mergeable doctest, the cost to run it would be higher than just
|
||||||
|
// running it alonside standalone doctests.
|
||||||
|
if doctests.len() > 1 {
|
||||||
|
doctests.sort_by(|(_, a), (_, b)| a.name.cmp(&b.name));
|
||||||
|
|
||||||
let mut tests_runner = runner::DocTestRunner::new();
|
let mut tests_runner = runner::DocTestRunner::new();
|
||||||
|
|
||||||
let rustdoc_test_options = IndividualTestOptions::new(
|
let rustdoc_test_options = IndividualTestOptions::new(
|
||||||
&rustdoc_options,
|
&rustdoc_options,
|
||||||
&Some(format!("merged_doctest_{edition}")),
|
&Some(format!("merged_doctest_{edition}")),
|
||||||
PathBuf::from(format!("doctest_{edition}.rs")),
|
PathBuf::from(format!("doctest_{edition}.rs")),
|
||||||
);
|
);
|
||||||
|
|
||||||
for (doctest, scraped_test) in &doctests {
|
for (doctest, scraped_test) in &doctests {
|
||||||
tests_runner.add_test(doctest, scraped_test, &target_str);
|
tests_runner.add_test(doctest, scraped_test, &target_str);
|
||||||
}
|
}
|
||||||
if let Ok(success) = tests_runner.run_merged_tests(
|
if let Ok(success) = tests_runner.run_merged_tests(
|
||||||
rustdoc_test_options,
|
rustdoc_test_options,
|
||||||
edition,
|
edition,
|
||||||
&opts,
|
&opts,
|
||||||
&test_args,
|
&test_args,
|
||||||
rustdoc_options,
|
rustdoc_options,
|
||||||
) {
|
) {
|
||||||
ran_edition_tests += 1;
|
ran_edition_tests += 1;
|
||||||
if !success {
|
if !success {
|
||||||
nb_errors += 1;
|
nb_errors += 1;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
// We failed to compile all compatible tests as one so we push them into the
|
// We failed to compile all compatible tests as one so we push them into the
|
||||||
// `standalone_tests` doctests.
|
// `standalone_tests` doctests.
|
||||||
debug!("Failed to compile compatible doctests for edition {} all at once", edition);
|
debug!("Failed to compile compatible doctests for edition {} all at once", edition);
|
||||||
for (doctest, scraped_test) in doctests {
|
}
|
||||||
doctest.generate_unique_doctest(
|
for (doctest, scraped_test) in doctests {
|
||||||
&scraped_test.text,
|
doctest.generate_unique_doctest(
|
||||||
scraped_test.langstr.test_harness,
|
&scraped_test.text,
|
||||||
&opts,
|
scraped_test.langstr.test_harness,
|
||||||
Some(&opts.crate_name),
|
&opts,
|
||||||
);
|
Some(&opts.crate_name),
|
||||||
standalone_tests.push(generate_test_desc_and_fn(
|
);
|
||||||
doctest,
|
standalone_tests.push(generate_test_desc_and_fn(
|
||||||
scraped_test,
|
doctest,
|
||||||
opts.clone(),
|
scraped_test,
|
||||||
Arc::clone(&rustdoc_options),
|
opts.clone(),
|
||||||
unused_extern_reports.clone(),
|
Arc::clone(&rustdoc_options),
|
||||||
));
|
unused_extern_reports.clone(),
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//@ compile-flags: --test --test-args=--test-threads=1 -Zunstable-options --edition 2024
|
//@ compile-flags: --test --test-args=--test-threads=1 -Zunstable-options --edition 2024
|
||||||
//@ normalize-stdout-test: "tests/rustdoc-ui" -> "$$DIR"
|
//@ normalize-stdout-test: "tests/rustdoc-ui" -> "$$DIR"
|
||||||
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
|
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
|
||||||
//@ normalize-stdout-test "wrong-ast.rs:\d+:\d+" -> "wrong-ast.rs:$$LINE:$$COL"
|
//@ normalize-stdout-test ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL"
|
||||||
|
|
||||||
/// This one should fail: crate attributes should remain crate attributes
|
/// This one should fail: crate attributes should remain crate attributes
|
||||||
/// in standalone doctests.
|
/// in standalone doctests.
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
running 1 test
|
running 1 test
|
||||||
test $DIR/failed-doctest-should-panic.rs - Foo (line 9) - should panic ... FAILED
|
test $DIR/failed-doctest-should-panic.rs - Foo (line 9) ... FAILED
|
||||||
|
|
||||||
failures:
|
failures:
|
||||||
|
|
||||||
---- $DIR/failed-doctest-should-panic.rs - Foo (line 9) stdout ----
|
---- $DIR/failed-doctest-should-panic.rs - Foo (line 9) stdout ----
|
||||||
note: test did not panic as expected
|
Test executable succeeded, but it's marked `should_panic`.
|
||||||
|
|
||||||
failures:
|
failures:
|
||||||
$DIR/failed-doctest-should-panic.rs - Foo (line 9)
|
$DIR/failed-doctest-should-panic.rs - Foo (line 9)
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
|
|
||||||
running 1 test
|
running 3 tests
|
||||||
test $DIR/wrong-ast-2024.rs - three (line 17) - should panic ... ok
|
|
||||||
|
|
||||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
|
|
||||||
|
|
||||||
|
|
||||||
running 2 tests
|
|
||||||
test $DIR/wrong-ast-2024.rs - one (line 7) ... FAILED
|
test $DIR/wrong-ast-2024.rs - one (line 7) ... FAILED
|
||||||
|
test $DIR/wrong-ast-2024.rs - three (line 17) ... ok
|
||||||
test $DIR/wrong-ast-2024.rs - two (line 12) ... FAILED
|
test $DIR/wrong-ast-2024.rs - two (line 12) ... FAILED
|
||||||
|
|
||||||
failures:
|
failures:
|
||||||
@ -37,5 +32,5 @@ failures:
|
|||||||
$DIR/wrong-ast-2024.rs - one (line 7)
|
$DIR/wrong-ast-2024.rs - one (line 7)
|
||||||
$DIR/wrong-ast-2024.rs - two (line 12)
|
$DIR/wrong-ast-2024.rs - two (line 12)
|
||||||
|
|
||||||
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
|
test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
|
||||||
|
|
||||||
|
17
tests/rustdoc-ui/run-as-standalone.rs
Normal file
17
tests/rustdoc-ui/run-as-standalone.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// This test ensures that if there is only one mergeable doctest, then it is
|
||||||
|
// instead run as part of standalone doctests.
|
||||||
|
|
||||||
|
//@ compile-flags:--test --test-args=--test-threads=1 -Zunstable-options --edition 2024
|
||||||
|
//@ normalize-stdout-test: "tests/rustdoc-ui" -> "$$DIR"
|
||||||
|
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
|
||||||
|
//@ normalize-stdout-test ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL"
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
/// ```
|
||||||
|
/// let x = 12;
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```compile_fail
|
||||||
|
/// let y = x;
|
||||||
|
/// ```
|
||||||
|
pub fn one() {}
|
7
tests/rustdoc-ui/run-as-standalone.stdout
Normal file
7
tests/rustdoc-ui/run-as-standalone.stdout
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
running 2 tests
|
||||||
|
test $DIR/run-as-standalone.rs - one (line 10) ... ok
|
||||||
|
test $DIR/run-as-standalone.rs - one (line 14) - compile fail ... ok
|
||||||
|
|
||||||
|
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
|
||||||
|
|
Loading…
Reference in New Issue
Block a user