Skip to content

Commit

Permalink
Print environment variables for cargo test 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 5405cd3 commit 2db59da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))?;
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4861,3 +4861,24 @@ error: unexpected argument `--keep-going` found
.with_status(101)
.run();
}

#[cargo_test]
fn 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]`
Doc-tests foo
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustdoc --crate-type lib --crate-name foo[..]",
)
.run();
}

0 comments on commit 2db59da

Please sign in to comment.