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 16, 2023
1 parent 5405cd3 commit 9267277
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
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
8 changes: 4 additions & 4 deletions tests/testsuite/profile_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -341,7 +341,7 @@ fn profile_selection_test() {
[RUNNING] `[..]/deps/foo-[..]`
[RUNNING] `[..]/deps/test1-[..]`
[DOCTEST] foo
[RUNNING] `rustdoc [..]--test [..]
[RUNNING] `[..] rustdoc [..]--test [..]
",
)
.run();
Expand Down Expand Up @@ -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(
Expand All @@ -408,7 +408,7 @@ fn profile_selection_test_release() {
[RUNNING] `[..]/deps/foo-[..]`
[RUNNING] `[..]/deps/test1-[..]`
[DOCTEST] foo
[RUNNING] `rustdoc [..]--test [..]
[RUNNING] `[..] rustdoc [..]--test [..]
",
)
.run();
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 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();
}

0 comments on commit 9267277

Please sign in to comment.