Skip to content

Commit

Permalink
Auto merge of #9195 - guswynn:test_name, r=ehuss
Browse files Browse the repository at this point in the history
Make it more clear which module is being tested when running cargo test

I recently asked in zulip if this is a good idea, as I find it hard to find the module thats being tested from the complex path with the hash.

Output of `cargo test`:
```
2021-02-21 13:29:33 I > ~/repos/cargo/target/debug/cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.42s
     Running unittests (target/debug/deps/test_tests-759130ea61f71571)

running 1 test
test tests::unit_test ... ok

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

     Running tests2/lib.rs (target/debug/deps/integration_tests-6b7f9fcd1721f083)

running 2 tests
test tests2_lib ... ok
test second_test::tests2_second ... ok

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

     Running tests/lib.rs (target/debug/deps/lib-d2be6d29597c2790)

running 2 tests
test second_test::tests_i_am_run_twice ... ok
test tests_lib ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in
0.00s
...
```
  • Loading branch information
bors committed Feb 24, 2021
2 parents 8eb0e9a + 04c8372 commit 9a7fe2c
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 120 deletions.
21 changes: 19 additions & 2 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::OsString;

use crate::core::compiler::{Compilation, CompileKind, Doctest, UnitOutput};
use crate::core::shell::Verbosity;
use crate::core::Workspace;
use crate::core::{TargetKind, Workspace};
use crate::ops;
use crate::util::errors::CargoResult;
use crate::util::{add_path_args, CargoTestError, Config, ProcessError, Test};
Expand Down Expand Up @@ -85,7 +85,24 @@ fn run_unit_tests(
} in compilation.tests.iter()
{
let test = unit.target.name().to_string();
let exe_display = path.strip_prefix(cwd).unwrap_or(path).display();

let test_path = unit.target.src_path().path().unwrap();
let exe_display = if let TargetKind::Test = unit.target.kind() {
format!(
"{} ({})",
test_path
.strip_prefix(unit.pkg.root())
.unwrap_or(&test_path)
.display(),
path.strip_prefix(cwd).unwrap_or(path).display()
)
} else {
format!(
"unittests ({})",
path.strip_prefix(cwd).unwrap_or(path).display()
)
};

let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?;
cmd.args(test_args);
if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet {
Expand Down
72 changes: 36 additions & 36 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn cargo_bench_simple() {
"\
[COMPILING] foo v0.5.0 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
)
.with_stdout_contains("test bench_hello ... bench: [..]")
.run();
Expand Down Expand Up @@ -91,8 +91,8 @@ fn bench_bench_implicit() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/mybench-[..][EXE]
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
[RUNNING] [..] (target/release/deps/mybench-[..][EXE])
",
)
.with_stdout_contains("test run2 ... bench: [..]")
Expand Down Expand Up @@ -139,7 +139,7 @@ fn bench_bin_implicit() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
",
)
.with_stdout_contains("test run1 ... bench: [..]")
Expand Down Expand Up @@ -176,7 +176,7 @@ fn bench_tarname() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/bin2-[..][EXE]
[RUNNING] [..] (target/release/deps/bin2-[..][EXE])
",
)
.with_stdout_contains("test run2 ... bench: [..]")
Expand Down Expand Up @@ -344,7 +344,7 @@ fn cargo_bench_failing_test() {
"\
[COMPILING] foo v0.5.0 ([CWD])[..]
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
)
.with_either_contains(
"[..]thread '[..]' panicked at 'assertion failed: `(left == right)`[..]",
Expand Down Expand Up @@ -416,8 +416,8 @@ fn bench_with_lib_dep() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/baz-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
[RUNNING] [..] (target/release/deps/baz-[..][EXE])",
)
.with_stdout_contains("test lib_bench ... bench: [..]")
.with_stdout_contains("test bin_bench ... bench: [..]")
Expand Down Expand Up @@ -481,7 +481,7 @@ fn bench_with_deep_lib_dep() {
[COMPILING] foo v0.0.1 ([..])
[COMPILING] bar v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/bar-[..][EXE]",
[RUNNING] [..] (target/release/deps/bar-[..][EXE])",
)
.with_stdout_contains("test bar_bench ... bench: [..]")
.run();
Expand Down Expand Up @@ -538,8 +538,8 @@ fn external_bench_explicit() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/bench-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
[RUNNING] [..] (target/release/deps/bench-[..][EXE])",
)
.with_stdout_contains("test internal_bench ... bench: [..]")
.with_stdout_contains("test external_bench ... bench: [..]")
Expand Down Expand Up @@ -585,8 +585,8 @@ fn external_bench_implicit() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/external-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
[RUNNING] [..] (target/release/deps/external-[..][EXE])",
)
.with_stdout_contains("test internal_bench ... bench: [..]")
.with_stdout_contains("test external_bench ... bench: [..]")
Expand Down Expand Up @@ -664,7 +664,7 @@ For more information on this warning you can consult
https://github.com/rust-lang/cargo/issues/5330
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
",
)
.run();
Expand Down Expand Up @@ -711,15 +711,15 @@ fn pass_through_command_line() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
)
.with_stdout_contains("test bar ... bench: [..]")
.run();

p.cargo("bench foo")
.with_stderr(
"[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
)
.with_stdout_contains("test foo ... bench: [..]")
.run();
Expand Down Expand Up @@ -804,8 +804,8 @@ fn lib_bin_same_name() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/foo-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
)
.with_stdout_contains_n("test [..] ... bench: [..]", 2)
.run();
Expand Down Expand Up @@ -853,8 +853,8 @@ fn lib_with_standard_name() {
"\
[COMPILING] syntax v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/syntax-[..][EXE]
[RUNNING] target/release/deps/bench-[..][EXE]",
[RUNNING] [..] (target/release/deps/syntax-[..][EXE])
[RUNNING] [..] (target/release/deps/bench-[..][EXE])",
)
.with_stdout_contains("test foo_bench ... bench: [..]")
.with_stdout_contains("test bench ... bench: [..]")
Expand Down Expand Up @@ -905,7 +905,7 @@ fn lib_with_standard_name2() {
"\
[COMPILING] syntax v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/syntax-[..][EXE]",
[RUNNING] [..] (target/release/deps/syntax-[..][EXE])",
)
.with_stdout_contains("test bench ... bench: [..]")
.run();
Expand Down Expand Up @@ -1040,15 +1040,15 @@ fn bench_twice_with_build_cmd() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
)
.with_stdout_contains("test foo ... bench: [..]")
.run();

p.cargo("bench")
.with_stderr(
"[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
[RUNNING] [..] (target/release/deps/foo-[..][EXE])",
)
.with_stdout_contains("test foo ... bench: [..]")
.run();
Expand Down Expand Up @@ -1175,7 +1175,7 @@ fn test_a_bench() {
"\
[COMPILING] foo v0.1.0 ([..])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/debug/deps/b-[..][EXE]",
[RUNNING] [..] (target/debug/deps/b-[..][EXE])",
)
.with_stdout_contains("test foo ... ok")
.run();
Expand Down Expand Up @@ -1251,9 +1251,9 @@ fn test_bench_no_fail_fast() {

p.cargo("bench --no-fail-fast -- --test-threads=1")
.with_status(101)
.with_stderr_contains("[RUNNING] target/release/deps/foo-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/foo-[..][EXE])")
.with_stdout_contains("running 2 tests")
.with_stderr_contains("[RUNNING] target/release/deps/foo-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/foo-[..][EXE])")
.with_stdout_contains("test bench_hello [..]")
.with_stdout_contains("test bench_nope [..]")
.run();
Expand Down Expand Up @@ -1345,9 +1345,9 @@ fn test_bench_multiple_packages() {
.build();

p.cargo("bench -p bar -p baz")
.with_stderr_contains("[RUNNING] target/release/deps/bbaz-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bbaz-[..][EXE])")
.with_stdout_contains("test bench_baz ... bench: [..]")
.with_stderr_contains("[RUNNING] target/release/deps/bbar-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bbar-[..][EXE])")
.with_stdout_contains("test bench_bar ... bench: [..]")
.run();
}
Expand Down Expand Up @@ -1402,9 +1402,9 @@ fn bench_all_workspace() {
.build();

p.cargo("bench --workspace")
.with_stderr_contains("[RUNNING] target/release/deps/bar-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
.with_stdout_contains("test bench_bar ... bench: [..]")
.with_stderr_contains("[RUNNING] target/release/deps/foo-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/foo-[..][EXE])")
.with_stdout_contains("test bench_foo ... bench: [..]")
.run();
}
Expand Down Expand Up @@ -1553,9 +1553,9 @@ fn bench_all_virtual_manifest() {

// The order in which bar and baz are built is not guaranteed
p.cargo("bench --workspace")
.with_stderr_contains("[RUNNING] target/release/deps/baz-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/baz-[..][EXE])")
.with_stdout_contains("test bench_baz ... bench: [..]")
.with_stderr_contains("[RUNNING] target/release/deps/bar-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
.with_stdout_contains("test bench_bar ... bench: [..]")
.run();
}
Expand Down Expand Up @@ -1606,9 +1606,9 @@ fn bench_virtual_manifest_glob() {

// The order in which bar and baz are built is not guaranteed
p.cargo("bench -p '*z'")
.with_stderr_contains("[RUNNING] target/release/deps/baz-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/baz-[..][EXE])")
.with_stdout_contains("test bench_baz ... bench: [..]")
.with_stderr_does_not_contain("[RUNNING] target/release/deps/bar-[..][EXE]")
.with_stderr_does_not_contain("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
.with_stdout_does_not_contain("test bench_bar ... bench: [..]")
.run();
}
Expand Down Expand Up @@ -1699,9 +1699,9 @@ fn bench_virtual_manifest_all_implied() {
// The order in which bar and baz are built is not guaranteed

p.cargo("bench")
.with_stderr_contains("[RUNNING] target/release/deps/baz-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/baz-[..][EXE])")
.with_stdout_contains("test bench_baz ... bench: [..]")
.with_stderr_contains("[RUNNING] target/release/deps/bar-[..][EXE]")
.with_stderr_contains("[RUNNING] [..] (target/release/deps/bar-[..][EXE])")
.with_stdout_contains("test bench_bar ... bench: [..]")
.run();
}
Expand Down
12 changes: 6 additions & 6 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ fn cross_tests() {
"\
[COMPILING] foo v0.0.0 ([CWD])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]",
[RUNNING] [..] (target/{triple}/debug/deps/foo-[..][EXE])
[RUNNING] [..] (target/{triple}/debug/deps/bar-[..][EXE])",
triple = target
))
.with_stdout_contains("test test_foo ... ok")
Expand Down Expand Up @@ -380,7 +380,7 @@ fn no_cross_doctests() {
let host_output = "\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/debug/deps/foo-[..][EXE]
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
[DOCTEST] foo
";

Expand All @@ -395,7 +395,7 @@ fn no_cross_doctests() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
[RUNNING] [..] (target/{triple}/debug/deps/foo-[..][EXE])
[DOCTEST] foo
",
triple = target
Expand Down Expand Up @@ -1060,8 +1060,8 @@ fn cross_test_dylib() {
[COMPILING] bar v0.0.1 ([CWD]/bar)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{arch}/debug/deps/foo-[..][EXE]
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]",
[RUNNING] [..] (target/{arch}/debug/deps/foo-[..][EXE])
[RUNNING] [..] (target/{arch}/debug/deps/test-[..][EXE])",
arch = cross_compile::alternate()
))
.with_stdout_contains_n("test foo ... ok", 2)
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fn changing_profiles_caches_targets() {
"\
[..]Compiling foo v0.0.1 ([..])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[..]debug[..]deps[..]foo-[..][EXE]
[RUNNING] [..] (target[..]debug[..]deps[..]foo-[..][EXE])
[DOCTEST] foo
",
)
Expand All @@ -268,7 +268,7 @@ fn changing_profiles_caches_targets() {
.with_stderr(
"\
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[..]debug[..]deps[..]foo-[..][EXE]
[RUNNING] [..] (target[..]debug[..]deps[..]foo-[..][EXE])
",
)
.run();
Expand Down Expand Up @@ -2441,7 +2441,7 @@ fn linking_interrupted() {
"\
[COMPILING] foo [..]
[FINISHED] [..]
[RUNNING] target/debug/deps/t1[..]
[RUNNING] tests/t1.rs (target/debug/deps/t1[..])
",
)
.run();
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ fn dev_deps_with_testing() {
[COMPILING] [..] v0.5.0 ([..])
[COMPILING] [..] v0.5.0 ([..]
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/debug/deps/foo-[..][EXE]",
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
)
.with_stdout_contains("test tests::foo ... ok")
.run();
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn cargo_compile_with_root_dev_deps_with_testing() {
[COMPILING] [..] v0.5.0 ([..])
[COMPILING] [..] v0.5.0 ([..])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/debug/deps/foo-[..][EXE]",
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
)
.with_stdout_contains("running 0 tests")
.run();
Expand Down Expand Up @@ -770,7 +770,7 @@ fn dev_deps_no_rebuild_lib() {
[COMPILING] [..] v0.5.0 ([CWD][..])
[COMPILING] [..] v0.5.0 ([CWD][..])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/debug/deps/foo-[..][EXE]",
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
)
.with_stdout_contains("running 0 tests")
.run();
Expand Down
Loading

0 comments on commit 9a7fe2c

Please sign in to comment.