diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 53916715a9f1..adf144ac2ed4 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -100,6 +100,10 @@ pub fn run( // by `compile.target_process` (the package's root directory) process.args(args).cwd(config.cwd()); + if config.extra_verbose() { + process.display_env_vars(); + } + config.shell().status("Running", process.to_string())?; process.exec_replace() diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 7b1dbbc1148b..0d0bd800fa9e 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -126,7 +126,7 @@ fn run_unit_tests( script_meta, } in compilation.tests.iter() { - let (exe_display, cmd) = cmd_builds( + let (exe_display, mut cmd) = cmd_builds( config, cwd, unit, @@ -136,6 +136,11 @@ fn run_unit_tests( compilation, "unittests", )?; + + if config.extra_verbose() { + cmd.display_env_vars(); + } + config .shell() .concise(|shell| shell.status("Running", &exe_display))?; @@ -268,9 +273,14 @@ fn run_doc_tests( p.arg("-Zunstable-options"); } + if config.extra_verbose() { + p.display_env_vars(); + } + config .shell() .verbose(|shell| shell.status("Running", p.to_string()))?; + if let Err(e) = p.exec() { let code = fail_fast_code(&e); let unit_err = UnitTestError { diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs index 5b59a56a436e..d773308c6836 100644 --- a/tests/testsuite/bench.rs +++ b/tests/testsuite/bench.rs @@ -1688,3 +1688,40 @@ error: unexpected argument `--keep-going` found .with_status(101) .run(); } + +#[cargo_test(nightly, reason = "bench")] +fn cargo_bench_print_env_verbose() { + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.0.1")) + .file( + "src/main.rs", + r#" + #![feature(test)] + #[cfg(test)] + extern crate test; + + fn hello() -> &'static str { + "hello" + } + + pub fn main() { + println!("{}", hello()) + } + + #[bench] + fn bench_hello(_b: &mut test::Bencher) { + assert_eq!(hello(), "hello") + } + "#, + ) + .build(); + p.cargo("bench -vv") + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc[..]` +[FINISHED] bench [optimized] target(s) in [..] +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] [CWD]/target/release/deps/foo-[..][EXE] --bench`", + ) + .run(); +} diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index a88ca34fd6d3..f2de169b9f1f 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -328,7 +328,7 @@ fn profile_selection_test() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc [..]--test [..] +[RUNNING] `[..] rustdoc [..]--test [..] ").run(); p.cargo("test -vv") .with_stderr_unordered( @@ -341,7 +341,7 @@ fn profile_selection_test() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc [..]--test [..] +[RUNNING] `[..] rustdoc [..]--test [..] ", ) .run(); @@ -395,7 +395,7 @@ fn profile_selection_test_release() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc [..]--test [..]` +[RUNNING] `[..] rustdoc [..]--test [..]` ").run(); p.cargo("test --release -vv") .with_stderr_unordered( @@ -408,7 +408,7 @@ fn profile_selection_test_release() { [RUNNING] `[..]/deps/foo-[..]` [RUNNING] `[..]/deps/test1-[..]` [DOCTEST] foo -[RUNNING] `rustdoc [..]--test [..] +[RUNNING] `[..] rustdoc [..]--test [..] ", ) .run(); diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 586502288b82..64cf4e16c6bc 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -1,6 +1,8 @@ //! Tests for the `cargo run` command. -use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, project, Project}; +use cargo_test_support::{ + basic_bin_manifest, basic_lib_manifest, basic_manifest, project, Project, +}; use cargo_util::paths::dylib_path_envvar; #[cargo_test] @@ -1416,6 +1418,24 @@ fn default_run_workspace() { p.cargo("run").with_stdout("run-a").run(); } +#[cargo_test] +fn print_env_verbose() { + let p = project() + .file("Cargo.toml", &basic_manifest("a", "0.0.1")) + .file("src/main.rs", r#"fn main() {println!("run-a");}"#) + .build(); + + p.cargo("run -vv") + .with_stderr( + "\ +[COMPILING] a v0.0.1 ([CWD]) +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name a[..]` +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] target/debug/a[EXE]`", + ) + .run(); +} + #[cargo_test] #[cfg(target_os = "macos")] fn run_link_system_path_macos() { diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index a90ab0fd04cb..c6ae4ce612f8 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -4861,3 +4861,24 @@ error: unexpected argument `--keep-going` found .with_status(101) .run(); } + +#[cargo_test] +fn cargo_test_print_env_verbose() { + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.0.1")) + .file("src/lib.rs", "") + .build(); + + p.cargo("test -vv") + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name foo[..]` +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name foo[..]` +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] [CWD]/target/debug/deps/foo-[..][EXE]` +[DOCTEST] foo +[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustdoc --crate-type lib --crate-name foo[..]", + ) + .run(); +}