Skip to content

Commit 46c9b51

Browse files
committed
Auto merge of #10346 - yerke:yerke/no-run-test-executable-path, r=ehuss
Print executable name on cargo test --no-run #2 Closes #9957 This is a continuation of #9959.
2 parents 86376c8 + 0b74ea2 commit 46c9b51

File tree

11 files changed

+120
-24
lines changed

11 files changed

+120
-24
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ fn substitute_macros(input: &str) -> String {
144144
("[YANK]", " Yank"),
145145
("[OWNER]", " Owner"),
146146
("[MIGRATING]", " Migrating"),
147+
("[EXECUTABLE]", " Executable"),
147148
];
148149
let mut result = input.to_owned();
149150
for &(pat, subst) in &macros {

src/cargo/ops/cargo_test.rs

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use crate::core::compiler::{Compilation, CompileKind, Doctest, UnitOutput};
1+
use crate::core::compiler::{Compilation, CompileKind, Doctest, Metadata, Unit, UnitOutput};
22
use crate::core::shell::Verbosity;
33
use crate::core::{TargetKind, Workspace};
44
use crate::ops;
55
use crate::util::errors::CargoResult;
66
use crate::util::{add_path_args, CargoTestError, Config, Test};
7-
use cargo_util::ProcessError;
7+
use cargo_util::{ProcessBuilder, ProcessError};
88
use std::ffi::OsString;
9+
use std::path::{Path, PathBuf};
910

1011
pub struct TestOptions {
1112
pub compile_opts: ops::CompileOptions,
@@ -21,6 +22,7 @@ pub fn run_tests(
2122
let compilation = compile_tests(ws, options)?;
2223

2324
if options.no_run {
25+
display_no_run_information(ws, test_args, &compilation, "unittests")?;
2426
return Ok(None);
2527
}
2628
let (test, mut errors) = run_unit_tests(ws.config(), options, test_args, &compilation)?;
@@ -48,6 +50,7 @@ pub fn run_benches(
4850
let compilation = compile_tests(ws, options)?;
4951

5052
if options.no_run {
53+
display_no_run_information(ws, args, &compilation, "benches")?;
5154
return Ok(None);
5255
}
5356

@@ -84,28 +87,16 @@ fn run_unit_tests(
8487
script_meta,
8588
} in compilation.tests.iter()
8689
{
87-
let test_path = unit.target.src_path().path().unwrap();
88-
let exe_display = if let TargetKind::Test = unit.target.kind() {
89-
format!(
90-
"{} ({})",
91-
test_path
92-
.strip_prefix(unit.pkg.root())
93-
.unwrap_or(test_path)
94-
.display(),
95-
path.strip_prefix(cwd).unwrap_or(path).display()
96-
)
97-
} else {
98-
format!(
99-
"unittests ({})",
100-
path.strip_prefix(cwd).unwrap_or(path).display()
101-
)
102-
};
103-
104-
let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?;
105-
cmd.args(test_args);
106-
if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet {
107-
cmd.arg("--quiet");
108-
}
90+
let (exe_display, cmd) = cmd_builds(
91+
config,
92+
cwd,
93+
unit,
94+
path,
95+
script_meta,
96+
test_args,
97+
compilation,
98+
"unittests",
99+
)?;
109100
config
110101
.shell()
111102
.concise(|shell| shell.status("Running", &exe_display))?;
@@ -264,3 +255,77 @@ fn run_doc_tests(
264255
}
265256
Ok((Test::Doc, errors))
266257
}
258+
259+
fn display_no_run_information(
260+
ws: &Workspace<'_>,
261+
test_args: &[&str],
262+
compilation: &Compilation<'_>,
263+
exec_type: &str,
264+
) -> CargoResult<()> {
265+
let config = ws.config();
266+
let cwd = config.cwd();
267+
for UnitOutput {
268+
unit,
269+
path,
270+
script_meta,
271+
} in compilation.tests.iter()
272+
{
273+
let (exe_display, cmd) = cmd_builds(
274+
config,
275+
cwd,
276+
unit,
277+
path,
278+
script_meta,
279+
test_args,
280+
&compilation,
281+
exec_type,
282+
)?;
283+
config
284+
.shell()
285+
.concise(|shell| shell.status("Executable", &exe_display))?;
286+
config
287+
.shell()
288+
.verbose(|shell| shell.status("Executable", &cmd))?;
289+
}
290+
291+
return Ok(());
292+
}
293+
294+
fn cmd_builds(
295+
config: &Config,
296+
cwd: &Path,
297+
unit: &Unit,
298+
path: &PathBuf,
299+
script_meta: &Option<Metadata>,
300+
test_args: &[&str],
301+
compilation: &Compilation<'_>,
302+
exec_type: &str,
303+
) -> CargoResult<(String, ProcessBuilder)> {
304+
let test_path = unit.target.src_path().path().unwrap();
305+
let short_test_path = test_path
306+
.strip_prefix(unit.pkg.root())
307+
.unwrap_or(test_path)
308+
.display();
309+
310+
let exe_display = match unit.target.kind() {
311+
TargetKind::Test | TargetKind::Bench => format!(
312+
"{} ({})",
313+
short_test_path,
314+
path.strip_prefix(cwd).unwrap_or(path).display()
315+
),
316+
_ => format!(
317+
"{} {} ({})",
318+
exec_type,
319+
short_test_path,
320+
path.strip_prefix(cwd).unwrap_or(path).display()
321+
),
322+
};
323+
324+
let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?;
325+
cmd.args(test_args);
326+
if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet {
327+
cmd.arg("--quiet");
328+
}
329+
330+
Ok((exe_display, cmd))
331+
}

tests/testsuite/bench.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,8 @@ fn test_bench_no_run() {
12091209
"\
12101210
[COMPILING] foo v0.0.1 ([..])
12111211
[FINISHED] bench [optimized] target(s) in [..]
1212+
[EXECUTABLE] benches src/lib.rs (target/release/deps/foo-[..][EXE])
1213+
[EXECUTABLE] benches/bbaz.rs (target/release/deps/bbaz-[..][EXE])
12121214
",
12131215
)
12141216
.run();

tests/testsuite/features2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,7 @@ fn minimal_download() {
20742074
[COMPILING] dev_dep v1.0.0
20752075
[COMPILING] foo v0.1.0 [..]
20762076
[FINISHED] [..]
2077+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
20772078
",
20782079
)
20792080
.run();

tests/testsuite/freshness.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ fn no_rebuild_transitive_target_deps() {
596596
[COMPILING] b v0.0.1 ([..])
597597
[COMPILING] foo v0.0.1 ([..])
598598
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
599+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
600+
[EXECUTABLE] tests/foo.rs (target/debug/deps/foo-[..][EXE])
599601
",
600602
)
601603
.run();
@@ -1125,6 +1127,7 @@ fn reuse_workspace_lib() {
11251127
[COMPILING] baz v0.1.1 ([..])
11261128
[RUNNING] `rustc[..] --test [..]`
11271129
[FINISHED] [..]
1130+
[EXECUTABLE] `[..]/target/debug/deps/baz-[..][EXE]`
11281131
",
11291132
)
11301133
.run();
@@ -1376,6 +1379,7 @@ fn reuse_panic_build_dep_test() {
13761379
[RUNNING] [..]build-script-build`
13771380
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--test[..]
13781381
[FINISHED] [..]
1382+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
13791383
",
13801384
)
13811385
.run();

tests/testsuite/lto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ fn fresh_swapping_commands() {
836836
[FRESH] bar v1.0.0
837837
[FRESH] foo [..]
838838
[FINISHED] [..]
839+
[EXECUTABLE] `[..]/target/release/deps/foo-[..][EXE]`
839840
",
840841
)
841842
.run();

tests/testsuite/messages.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn deduplicate_messages_basic() {
6363
warning: `foo` (lib) generated 1 warning
6464
warning: `foo` (lib test) generated 1 warning (1 duplicate)
6565
[FINISHED] [..]
66+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
6667
",
6768
rustc_message
6869
);
@@ -106,6 +107,7 @@ warning: `foo` (lib) generated 1 warning
106107
{}\
107108
warning: `foo` (lib test) generated 2 warnings (1 duplicate)
108109
[FINISHED] [..]
110+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
109111
",
110112
lib_output, lib_test_output
111113
);

tests/testsuite/profile_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ fn test_with_dev_profile() {
452452
[COMPILING] foo v0.1.0 [..]
453453
[RUNNING] `rustc --crate-name foo [..]-C debuginfo=0[..]
454454
[FINISHED] [..]
455+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
455456
",
456457
)
457458
.run();

tests/testsuite/profiles.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ fn panic_unwind_does_not_build_twice() {
406406
[RUNNING] `rustc --crate-name foo src/main.rs [..] --test [..]
407407
[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]
408408
[FINISHED] [..]
409+
[EXECUTABLE] `[..]/target/debug/deps/t1-[..][EXE]`
410+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
411+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
409412
",
410413
)
411414
.run();

tests/testsuite/rustflags.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,9 @@ fn cfg_rustflags_normal_source() {
10991099
[RUNNING] `rustc [..] --cfg bar[..]`
11001100
[RUNNING] `rustc [..] --cfg bar[..]`
11011101
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
1102+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
1103+
[EXECUTABLE] `[..]/target/debug/deps/a-[..][EXE]`
1104+
[EXECUTABLE] `[..]/target/debug/deps/c-[..][EXE]`
11021105
",
11031106
)
11041107
.run();
@@ -1111,6 +1114,8 @@ fn cfg_rustflags_normal_source() {
11111114
[RUNNING] `rustc [..] --cfg bar[..]`
11121115
[RUNNING] `rustc [..] --cfg bar[..]`
11131116
[FINISHED] bench [optimized] target(s) in [..]
1117+
[EXECUTABLE] `[..]/target/release/deps/foo-[..][EXE]`
1118+
[EXECUTABLE] `[..]/target/release/deps/a-[..][EXE]`
11141119
",
11151120
)
11161121
.run();
@@ -1181,6 +1186,9 @@ fn cfg_rustflags_precedence() {
11811186
[RUNNING] `rustc [..] --cfg bar[..]`
11821187
[RUNNING] `rustc [..] --cfg bar[..]`
11831188
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
1189+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
1190+
[EXECUTABLE] `[..]/target/debug/deps/a-[..][EXE]`
1191+
[EXECUTABLE] `[..]/target/debug/deps/c-[..][EXE]`
11841192
",
11851193
)
11861194
.run();
@@ -1193,6 +1201,8 @@ fn cfg_rustflags_precedence() {
11931201
[RUNNING] `rustc [..] --cfg bar[..]`
11941202
[RUNNING] `rustc [..] --cfg bar[..]`
11951203
[FINISHED] bench [optimized] target(s) in [..]
1204+
[EXECUTABLE] `[..]/target/release/deps/foo-[..][EXE]`
1205+
[EXECUTABLE] `[..]/target/release/deps/a-[..][EXE]`
11961206
",
11971207
)
11981208
.run();

tests/testsuite/test.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ fn test_no_run() {
13461346
"\
13471347
[COMPILING] foo v0.0.1 ([CWD])
13481348
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
1349+
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
13491350
",
13501351
)
13511352
.run();
@@ -2001,6 +2002,7 @@ fn example_bin_same_name() {
20012002
[RUNNING] `rustc [..]`
20022003
[RUNNING] `rustc [..]`
20032004
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
2005+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
20042006
",
20052007
)
20062008
.run();
@@ -2536,6 +2538,9 @@ fn bin_does_not_rebuild_tests() {
25362538
[RUNNING] `rustc [..] src/main.rs [..]`
25372539
[RUNNING] `rustc [..] src/main.rs [..]`
25382540
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
2541+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
2542+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
2543+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
25392544
",
25402545
)
25412546
.run();
@@ -2594,6 +2599,7 @@ fn selective_test_optional_dep() {
25942599
[RUNNING] `rustc [..] a/src/lib.rs [..]`
25952600
[RUNNING] `rustc [..] a/src/lib.rs [..]`
25962601
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
2602+
[EXECUTABLE] `[..]/target/debug/deps/a-[..][EXE]`
25972603
",
25982604
)
25992605
.run();

0 commit comments

Comments
 (0)