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] 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 53916715a..adf144ac2 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 586502288..64cf4e16c 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() {