Auto merge of #84863 - ABouttefeux:libtest, r=m-ou-se

Show test type during prints

Test output can sometimes be confusing. For example doctest with the no_run argument are displayed the same way than test that are run.

During #83857 I got the feedback that test output can be confusing.

For the moment test output is
```
test $DIR/test-type.rs - f (line 12) ... ignored
test $DIR/test-type.rs - f (line 15) ... ok
test $DIR/test-type.rs - f (line 21) ... ok
test $DIR/test-type.rs - f (line 6) ... ok
```

I propose to change output by indicating the test type as
```
test $DIR/test-type.rs - f (line 12) ... ignored
test $DIR/test-type.rs - f (line 15) - compile ... ok
test $DIR/test-type.rs - f (line 21) - compile fail ... ok
test $DIR/test-type.rs - f (line 6) ... ok
```
by indicating the test type after the test name (and in the case of doctest after the function name and line) and before the "...".

------------

Note: this is a proof of concept, the implementation is probably not optimal as the properties added in `TestDesc` are only use in the display and does not represent actual change of behavior, maybe `TestType::DocTest` could have fields
This commit is contained in:
bors 2021-06-06 09:13:59 +00:00
commit 3740ba2a7d
18 changed files with 219 additions and 18 deletions

View file

@ -880,6 +880,7 @@ impl Tester for Collector {
let target = self.options.target.clone();
let target_str = target.to_string();
let unused_externs = self.unused_extern_reports.clone();
let no_run = config.no_run || options.no_run;
if !config.compile_fail {
self.compiling_test_count.fetch_add(1, Ordering::SeqCst);
}
@ -941,13 +942,16 @@ impl Tester for Collector {
// compiler failures are test failures
should_panic: testing::ShouldPanic::No,
allow_fail: config.allow_fail,
#[cfg(not(bootstrap))]
compile_fail: config.compile_fail,
#[cfg(not(bootstrap))]
no_run,
test_type: testing::TestType::DocTest,
},
testfn: testing::DynTestFn(box move || {
let report_unused_externs = |uext| {
unused_externs.lock().unwrap().push(uext);
};
let no_run = config.no_run || options.no_run;
let res = run_test(
&test,
&cratename,

View file

@ -1,6 +1,6 @@
running 1 test
test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) ... FAILED
test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) - compile fail ... FAILED
failures:

View file

@ -1,6 +1,6 @@
running 1 test
test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) ... FAILED
test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) - compile fail ... FAILED
failures:

View file

@ -1,6 +1,6 @@
running 1 test
test $DIR/issue-80992.rs - test (line 7) ... ok
test $DIR/issue-80992.rs - test (line 7) - compile fail ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

View file

@ -1,12 +1,12 @@
running 7 tests
test $DIR/no-run-flag.rs - f (line 11) ... ok
test $DIR/no-run-flag.rs - f (line 11) - compile ... ok
test $DIR/no-run-flag.rs - f (line 14) ... ignored
test $DIR/no-run-flag.rs - f (line 17) ... ok
test $DIR/no-run-flag.rs - f (line 23) ... ok
test $DIR/no-run-flag.rs - f (line 28) ... ok
test $DIR/no-run-flag.rs - f (line 32) ... ok
test $DIR/no-run-flag.rs - f (line 8) ... ok
test $DIR/no-run-flag.rs - f (line 17) - compile ... ok
test $DIR/no-run-flag.rs - f (line 23) - compile fail ... ok
test $DIR/no-run-flag.rs - f (line 28) - compile ... ok
test $DIR/no-run-flag.rs - f (line 32) - compile ... ok
test $DIR/no-run-flag.rs - f (line 8) - compile ... ok
test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME

View file

@ -0,0 +1,26 @@
// compile-flags: --test --test-args=--test-threads=1
// check-pass
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
/// ```
/// let a = true;
/// ```
/// ```should_panic
/// panic!()
/// ```
/// ```ignore (incomplete-code)
/// fn foo() {
/// ```
/// ```no_run
/// loop {
/// println!("Hello, world");
/// }
/// ```
/// fails to compile
/// ```compile_fail
/// let x = 5;
/// x += 2; // shouldn't compile!
/// ```
pub fn f() {}

View file

@ -0,0 +1,10 @@
running 5 tests
test $DIR/test-type.rs - f (line 12) ... ignored
test $DIR/test-type.rs - f (line 15) - compile ... ok
test $DIR/test-type.rs - f (line 21) - compile fail ... ok
test $DIR/test-type.rs - f (line 6) ... ok
test $DIR/test-type.rs - f (line 9) ... ok
test result: ok. 4 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME

View file

@ -0,0 +1,28 @@
// compile-flags: --test
// run-flags: --test-threads=1
// check-run-results
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
// ignore-emscripten no threads support
// run-pass
#[test]
fn test_ok() {
let _a = true;
}
#[test]
#[should_panic]
fn test_panic() {
panic!();
}
#[test]
#[ignore]
fn test_no_run() {
loop{
println!("Hello, world");
}
}
fn main() {}

View file

@ -0,0 +1,8 @@
running 3 tests
test test_no_run ... ignored
test test_ok ... ok
test test_panic - should panic ... ok
test result: ok. 2 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME

View file

@ -2,7 +2,7 @@
running 4 tests
test it_fails ... about to fail
FAILED
test it_panics ... about to panic
test it_panics - should panic ... about to panic
ok
test it_works ... about to succeed
ok

View file

@ -2,7 +2,7 @@
running 5 tests
test it_exits ... FAILED
test it_fails ... FAILED
test it_panics ... ok
test it_panics - should panic ... ok
test it_works ... ok
test no_residual_environment ... ok

View file

@ -664,6 +664,10 @@ fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec<test
ignore,
should_panic,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: test::TestType::Unknown,
},
testfn: make_test_closure(config, testpaths, revision),

View file

@ -2676,12 +2676,11 @@ impl<'test> TestCx<'test> {
let mut tested = 0;
for _ in res.stdout.split('\n').filter(|s| s.starts_with("test ")).inspect(|s| {
let tmp: Vec<&str> = s.split(" - ").collect();
if tmp.len() == 2 {
let path = tmp[0].rsplit("test ").next().unwrap();
if let Some((left, right)) = s.split_once(" - ") {
let path = left.rsplit("test ").next().unwrap();
if let Some(ref mut v) = files.get_mut(&path.replace('\\', "/")) {
tested += 1;
let mut iter = tmp[1].split("(line ");
let mut iter = right.split("(line ");
iter.next();
let line = iter
.next()