Skip to content

Commit bf82412

Browse files
committed
Auto merge of #10691 - danilhendrasr:master, r=weihanglo
No printing executable names when running tests and benchmarks with json message format Fixes: #10684 I added a new test for this, though I'm not sure if it's necessary. Let me know if I should delete it.
2 parents 11d4599 + e04d777 commit bf82412

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ pub fn run_tests(
2222
let compilation = compile_tests(ws, options)?;
2323

2424
if options.no_run {
25-
display_no_run_information(ws, test_args, &compilation, "unittests")?;
25+
if !options.compile_opts.build_config.emit_json() {
26+
display_no_run_information(ws, test_args, &compilation, "unittests")?;
27+
}
28+
2629
return Ok(None);
2730
}
2831
let (test, mut errors) = run_unit_tests(ws.config(), options, test_args, &compilation)?;
@@ -50,7 +53,10 @@ pub fn run_benches(
5053
let compilation = compile_tests(ws, options)?;
5154

5255
if options.no_run {
53-
display_no_run_information(ws, args, &compilation, "benches")?;
56+
if !options.compile_opts.build_config.emit_json() {
57+
display_no_run_information(ws, args, &compilation, "benches")?;
58+
}
59+
5460
return Ok(None);
5561
}
5662

tests/testsuite/bench.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,39 @@ fn test_bench_no_run() {
12161216
.run();
12171217
}
12181218

1219+
#[cargo_test]
1220+
fn test_bench_no_run_emit_json() {
1221+
if !is_nightly() {
1222+
return;
1223+
}
1224+
1225+
let p = project()
1226+
.file("src/lib.rs", "")
1227+
.file(
1228+
"benches/bbaz.rs",
1229+
r#"
1230+
#![feature(test)]
1231+
1232+
extern crate test;
1233+
1234+
use test::Bencher;
1235+
1236+
#[bench]
1237+
fn bench_baz(_: &mut Bencher) {}
1238+
"#,
1239+
)
1240+
.build();
1241+
1242+
p.cargo("bench --no-run --message-format json")
1243+
.with_stderr(
1244+
"\
1245+
[COMPILING] foo v0.0.1 ([..])
1246+
[FINISHED] bench [optimized] target(s) in [..]
1247+
",
1248+
)
1249+
.run();
1250+
}
1251+
12191252
#[cargo_test]
12201253
fn test_bench_no_fail_fast() {
12211254
if !is_nightly() {

tests/testsuite/test.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,22 @@ fn test_no_run() {
13521352
.run();
13531353
}
13541354

1355+
#[cargo_test]
1356+
fn test_no_run_emit_json() {
1357+
let p = project()
1358+
.file("src/lib.rs", "#[test] fn foo() { panic!() }")
1359+
.build();
1360+
1361+
p.cargo("test --no-run --message-format json")
1362+
.with_stderr(
1363+
"\
1364+
[COMPILING] foo v0.0.1 ([CWD])
1365+
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
1366+
",
1367+
)
1368+
.run();
1369+
}
1370+
13551371
#[cargo_test]
13561372
fn test_run_specific_bin_target() {
13571373
let prj = project()

0 commit comments

Comments
 (0)