From 5405cd3a8b89fb2daf49f9528e35a0ac070e0581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 14 Aug 2023 20:38:24 +0200 Subject: [PATCH 1/3] Print environment variables for `cargo run` in extra verbose mode --- src/cargo/ops/cargo_run.rs | 4 ++++ tests/testsuite/run.rs | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) 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/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() { From 92672770480816703b99fa62c2822469ceafaf2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 15 Aug 2023 13:44:08 +0200 Subject: [PATCH 2/3] Print environment variables for `cargo test` in extra verbose mode --- src/cargo/ops/cargo_test.rs | 12 +++++++++++- tests/testsuite/profile_targets.rs | 8 ++++---- tests/testsuite/test.rs | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 1166ea6832cb..91a2b6bbe043 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))?; @@ -266,9 +271,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/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/test.rs b/tests/testsuite/test.rs index 4820c7dcd788..cbe01e658d94 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(); +} From 4eac5a1fd152c62f7275896afb4379e39413e99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 16 Aug 2023 13:47:27 +0200 Subject: [PATCH 3/3] Add test for environment variables in verbose mode for `cargo bench` --- tests/testsuite/bench.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs index 64b13f48b656..a11a4a899ca7 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(); +}