Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub fn run_tests(
let compilation = compile_tests(ws, options)?;

if options.no_run {
display_no_run_information(ws, test_args, &compilation, "unittests")?;
if !options.compile_opts.build_config.emit_json() {
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 +53,10 @@ pub fn run_benches(
let compilation = compile_tests(ws, options)?;

if options.no_run {
display_no_run_information(ws, args, &compilation, "benches")?;
if !options.compile_opts.build_config.emit_json() {
display_no_run_information(ws, args, &compilation, "benches")?;
}

return Ok(None);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,39 @@ fn test_bench_no_run() {
.run();
}

#[cargo_test]
fn test_bench_no_run_emit_json() {
if !is_nightly() {
return;
}

let p = project()
.file("src/lib.rs", "")
.file(
"benches/bbaz.rs",
r#"
#![feature(test)]

extern crate test;

use test::Bencher;

#[bench]
fn bench_baz(_: &mut Bencher) {}
"#,
)
.build();

p.cargo("bench --no-run --message-format json")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] bench [optimized] target(s) in [..]
",
)
.run();
}

#[cargo_test]
fn test_bench_no_fail_fast() {
if !is_nightly() {
Expand Down
16 changes: 16 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,22 @@ fn test_no_run() {
.run();
}

#[cargo_test]
fn test_no_run_emit_json() {
let p = project()
.file("src/lib.rs", "#[test] fn foo() { panic!() }")
.build();

p.cargo("test --no-run --message-format json")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}

#[cargo_test]
fn test_run_specific_bin_target() {
let prj = project()
Expand Down