Skip to content

Commit

Permalink
Print environment variables for cargo run in extra verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Aug 15, 2023
1 parent f137594 commit 5405cd3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cargo/ops/cargo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 21 additions & 1 deletion tests/testsuite/run.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5405cd3

Please sign in to comment.