Skip to content

Commit

Permalink
display bench exec info differently
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke committed Feb 2, 2022
1 parent ed579b6 commit 0b74ea2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
33 changes: 22 additions & 11 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn run_tests(
let compilation = compile_tests(ws, options)?;

if options.no_run {
display_no_run_information(ws, test_args, &compilation)?;
display_no_run_information(ws, test_args, &compilation, "unittests")?;
return Ok(None);
}
let (test, mut errors) = run_unit_tests(ws.config(), options, test_args, &compilation)?;
Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn run_benches(
let compilation = compile_tests(ws, options)?;

if options.no_run {
display_no_run_information(ws, args, &compilation)?;
display_no_run_information(ws, args, &compilation, "benches")?;
return Ok(None);
}

Expand Down Expand Up @@ -87,8 +87,16 @@ fn run_unit_tests(
script_meta,
} in compilation.tests.iter()
{
let (exe_display, cmd) =
cmd_builds(config, cwd, unit, path, script_meta, test_args, compilation)?;
let (exe_display, cmd) = cmd_builds(
config,
cwd,
unit,
path,
script_meta,
test_args,
compilation,
"unittests",
)?;
config
.shell()
.concise(|shell| shell.status("Running", &exe_display))?;
Expand Down Expand Up @@ -252,6 +260,7 @@ fn display_no_run_information(
ws: &Workspace<'_>,
test_args: &[&str],
compilation: &Compilation<'_>,
exec_type: &str,
) -> CargoResult<()> {
let config = ws.config();
let cwd = config.cwd();
Expand All @@ -269,6 +278,7 @@ fn display_no_run_information(
script_meta,
test_args,
&compilation,
exec_type,
)?;
config
.shell()
Expand All @@ -289,25 +299,26 @@ fn cmd_builds(
script_meta: &Option<Metadata>,
test_args: &[&str],
compilation: &Compilation<'_>,
exec_type: &str,
) -> CargoResult<(String, ProcessBuilder)> {
let test_path = unit.target.src_path().path().unwrap();
let short_test_path = test_path
.strip_prefix(unit.pkg.root())
.unwrap_or(test_path)
.display();

let exe_display = if let TargetKind::Test = unit.target.kind() {
format!(
let exe_display = match unit.target.kind() {
TargetKind::Test | TargetKind::Bench => format!(
"{} ({})",
short_test_path,
path.strip_prefix(cwd).unwrap_or(path).display()
)
} else {
format!(
"unittests {} ({})",
),
_ => format!(
"{} {} ({})",
exec_type,
short_test_path,
path.strip_prefix(cwd).unwrap_or(path).display()
)
),
};

let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?;
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,8 @@ fn test_bench_no_run() {
"\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] bench [optimized] target(s) in [..]
[EXECUTABLE] unittests src/lib.rs (target/release/deps/foo-[..][EXE])
[EXECUTABLE] unittests benches/bbaz.rs (target/release/deps/bbaz-[..][EXE])
[EXECUTABLE] benches src/lib.rs (target/release/deps/foo-[..][EXE])
[EXECUTABLE] benches/bbaz.rs (target/release/deps/bbaz-[..][EXE])
",
)
.run();
Expand Down

0 comments on commit 0b74ea2

Please sign in to comment.