Skip to content

Commit bef4d79

Browse files
committed
Print executable name on cargo test --no-run.
Closes #9957 Signed-off-by: Vaibhav <[email protected]>
1 parent a821e2c commit bef4d79

File tree

11 files changed

+112
-24
lines changed

11 files changed

+112
-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: 81 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,30 @@ pub fn run_tests(
2122
let compilation = compile_tests(ws, options)?;
2223

2324
if options.no_run {
25+
let config = ws.config();
26+
let cwd = config.cwd();
27+
for UnitOutput {
28+
unit,
29+
path,
30+
script_meta,
31+
} in compilation.tests.iter()
32+
{
33+
let (exe_display, cmd) = cmd_builds(
34+
config,
35+
cwd,
36+
unit,
37+
path,
38+
script_meta,
39+
test_args,
40+
&compilation,
41+
)?;
42+
config
43+
.shell()
44+
.concise(|shell| shell.status("Executable", &exe_display))?;
45+
config
46+
.shell()
47+
.verbose(|shell| shell.status("Executable", &cmd))?;
48+
}
2449
return Ok(None);
2550
}
2651
let (test, mut errors) = run_unit_tests(ws.config(), options, test_args, &compilation)?;
@@ -48,6 +73,23 @@ pub fn run_benches(
4873
let compilation = compile_tests(ws, options)?;
4974

5075
if options.no_run {
76+
let config = ws.config();
77+
let cwd = config.cwd();
78+
for UnitOutput {
79+
unit,
80+
path,
81+
script_meta,
82+
} in compilation.tests.iter()
83+
{
84+
let (exe_display, cmd) =
85+
cmd_builds(config, cwd, unit, path, script_meta, args, &compilation)?;
86+
config
87+
.shell()
88+
.concise(|shell| shell.status("Executable", &exe_display))?;
89+
config
90+
.shell()
91+
.verbose(|shell| shell.status("Executable", &cmd))?;
92+
}
5193
return Ok(None);
5294
}
5395

@@ -86,28 +128,8 @@ fn run_unit_tests(
86128
{
87129
let test = unit.target.name().to_string();
88130

89-
let test_path = unit.target.src_path().path().unwrap();
90-
let exe_display = if let TargetKind::Test = unit.target.kind() {
91-
format!(
92-
"{} ({})",
93-
test_path
94-
.strip_prefix(unit.pkg.root())
95-
.unwrap_or(test_path)
96-
.display(),
97-
path.strip_prefix(cwd).unwrap_or(path).display()
98-
)
99-
} else {
100-
format!(
101-
"unittests ({})",
102-
path.strip_prefix(cwd).unwrap_or(path).display()
103-
)
104-
};
105-
106-
let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?;
107-
cmd.args(test_args);
108-
if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet {
109-
cmd.arg("--quiet");
110-
}
131+
let (exe_display, cmd) =
132+
cmd_builds(config, cwd, unit, path, script_meta, test_args, compilation)?;
111133
config
112134
.shell()
113135
.concise(|shell| shell.status("Running", &exe_display))?;
@@ -152,6 +174,41 @@ fn run_unit_tests(
152174
}
153175
}
154176

177+
fn cmd_builds(
178+
config: &Config,
179+
cwd: &Path,
180+
unit: &Unit,
181+
path: &PathBuf,
182+
script_meta: &Option<Metadata>,
183+
test_args: &[&str],
184+
compilation: &Compilation<'_>,
185+
) -> CargoResult<(String, ProcessBuilder)> {
186+
let test_path = unit.target.src_path().path().unwrap();
187+
let exe_display = if let TargetKind::Test = unit.target.kind() {
188+
format!(
189+
"{} ({})",
190+
test_path
191+
.strip_prefix(unit.pkg.root())
192+
.unwrap_or(test_path)
193+
.display(),
194+
path.strip_prefix(cwd).unwrap_or(path).display()
195+
)
196+
} else {
197+
format!(
198+
"unittests ({})",
199+
path.strip_prefix(cwd).unwrap_or(path).display()
200+
)
201+
};
202+
203+
let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?;
204+
cmd.args(test_args);
205+
if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet {
206+
cmd.arg("--quiet");
207+
}
208+
209+
Ok((exe_display, cmd))
210+
}
211+
155212
fn run_doc_tests(
156213
ws: &Workspace<'_>,
157214
options: &TestOptions,

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] [..] (target/release/deps/foo-[..][EXE])
1213+
[EXECUTABLE] [..] (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] [..] (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] [..] (target/debug/deps/foo-[..][EXE])
600+
[EXECUTABLE] [..] (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
@@ -849,6 +849,7 @@ fn fresh_swapping_commands() {
849849
[FRESH] bar v1.0.0
850850
[FRESH] foo [..]
851851
[FINISHED] [..]
852+
[EXECUTABLE] `[..]/target/release/deps/foo-[..][EXE]`
852853
",
853854
)
854855
.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] [..] (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] [..] (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
@@ -490,6 +490,7 @@ fn test_with_dev_profile() {
490490
[COMPILING] foo v0.1.0 [..]
491491
[RUNNING] `rustc --crate-name foo [..]-C debuginfo=2[..]
492492
[FINISHED] [..]
493+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
493494
",
494495
)
495496
.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] [..] (target/debug/deps/foo-[..][EXE])
13491350
",
13501351
)
13511352
.run();
@@ -1963,6 +1964,7 @@ fn example_bin_same_name() {
19631964
[RUNNING] `rustc [..]`
19641965
[RUNNING] `rustc [..]`
19651966
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
1967+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
19661968
",
19671969
)
19681970
.run();
@@ -2498,6 +2500,9 @@ fn bin_does_not_rebuild_tests() {
24982500
[RUNNING] `rustc [..] src/main.rs [..]`
24992501
[RUNNING] `rustc [..] src/main.rs [..]`
25002502
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
2503+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
2504+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
2505+
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
25012506
",
25022507
)
25032508
.run();
@@ -2556,6 +2561,7 @@ fn selective_test_optional_dep() {
25562561
[RUNNING] `rustc [..] a/src/lib.rs [..]`
25572562
[RUNNING] `rustc [..] a/src/lib.rs [..]`
25582563
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
2564+
[EXECUTABLE] `[..]/target/debug/deps/a-[..][EXE]`
25592565
",
25602566
)
25612567
.run();

0 commit comments

Comments
 (0)