Skip to content

Commit 7b61184

Browse files
committed
Auto merge of #12498 - Kobzol:run-verbose-print-env, r=arlosi
Print environment variables for `cargo run` in extra verbose mode
2 parents 3a34fca + 4eac5a1 commit 7b61184

File tree

6 files changed

+98
-6
lines changed

6 files changed

+98
-6
lines changed

src/cargo/ops/cargo_run.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ pub fn run(
100100
// by `compile.target_process` (the package's root directory)
101101
process.args(args).cwd(config.cwd());
102102

103+
if config.extra_verbose() {
104+
process.display_env_vars();
105+
}
106+
103107
config.shell().status("Running", process.to_string())?;
104108

105109
process.exec_replace()

src/cargo/ops/cargo_test.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn run_unit_tests(
126126
script_meta,
127127
} in compilation.tests.iter()
128128
{
129-
let (exe_display, cmd) = cmd_builds(
129+
let (exe_display, mut cmd) = cmd_builds(
130130
config,
131131
cwd,
132132
unit,
@@ -136,6 +136,11 @@ fn run_unit_tests(
136136
compilation,
137137
"unittests",
138138
)?;
139+
140+
if config.extra_verbose() {
141+
cmd.display_env_vars();
142+
}
143+
139144
config
140145
.shell()
141146
.concise(|shell| shell.status("Running", &exe_display))?;
@@ -268,9 +273,14 @@ fn run_doc_tests(
268273
p.arg("-Zunstable-options");
269274
}
270275

276+
if config.extra_verbose() {
277+
p.display_env_vars();
278+
}
279+
271280
config
272281
.shell()
273282
.verbose(|shell| shell.status("Running", p.to_string()))?;
283+
274284
if let Err(e) = p.exec() {
275285
let code = fail_fast_code(&e);
276286
let unit_err = UnitTestError {

tests/testsuite/bench.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,3 +1688,40 @@ error: unexpected argument `--keep-going` found
16881688
.with_status(101)
16891689
.run();
16901690
}
1691+
1692+
#[cargo_test(nightly, reason = "bench")]
1693+
fn cargo_bench_print_env_verbose() {
1694+
let p = project()
1695+
.file("Cargo.toml", &basic_manifest("foo", "0.0.1"))
1696+
.file(
1697+
"src/main.rs",
1698+
r#"
1699+
#![feature(test)]
1700+
#[cfg(test)]
1701+
extern crate test;
1702+
1703+
fn hello() -> &'static str {
1704+
"hello"
1705+
}
1706+
1707+
pub fn main() {
1708+
println!("{}", hello())
1709+
}
1710+
1711+
#[bench]
1712+
fn bench_hello(_b: &mut test::Bencher) {
1713+
assert_eq!(hello(), "hello")
1714+
}
1715+
"#,
1716+
)
1717+
.build();
1718+
p.cargo("bench -vv")
1719+
.with_stderr(
1720+
"\
1721+
[COMPILING] foo v0.0.1 ([CWD])
1722+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc[..]`
1723+
[FINISHED] bench [optimized] target(s) in [..]
1724+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] [CWD]/target/release/deps/foo-[..][EXE] --bench`",
1725+
)
1726+
.run();
1727+
}

tests/testsuite/profile_targets.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ fn profile_selection_test() {
328328
[RUNNING] `[..]/deps/foo-[..]`
329329
[RUNNING] `[..]/deps/test1-[..]`
330330
[DOCTEST] foo
331-
[RUNNING] `rustdoc [..]--test [..]
331+
[RUNNING] `[..] rustdoc [..]--test [..]
332332
").run();
333333
p.cargo("test -vv")
334334
.with_stderr_unordered(
@@ -341,7 +341,7 @@ fn profile_selection_test() {
341341
[RUNNING] `[..]/deps/foo-[..]`
342342
[RUNNING] `[..]/deps/test1-[..]`
343343
[DOCTEST] foo
344-
[RUNNING] `rustdoc [..]--test [..]
344+
[RUNNING] `[..] rustdoc [..]--test [..]
345345
",
346346
)
347347
.run();
@@ -395,7 +395,7 @@ fn profile_selection_test_release() {
395395
[RUNNING] `[..]/deps/foo-[..]`
396396
[RUNNING] `[..]/deps/test1-[..]`
397397
[DOCTEST] foo
398-
[RUNNING] `rustdoc [..]--test [..]`
398+
[RUNNING] `[..] rustdoc [..]--test [..]`
399399
").run();
400400
p.cargo("test --release -vv")
401401
.with_stderr_unordered(
@@ -408,7 +408,7 @@ fn profile_selection_test_release() {
408408
[RUNNING] `[..]/deps/foo-[..]`
409409
[RUNNING] `[..]/deps/test1-[..]`
410410
[DOCTEST] foo
411-
[RUNNING] `rustdoc [..]--test [..]
411+
[RUNNING] `[..] rustdoc [..]--test [..]
412412
",
413413
)
414414
.run();

tests/testsuite/run.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Tests for the `cargo run` command.
22
3-
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, project, Project};
3+
use cargo_test_support::{
4+
basic_bin_manifest, basic_lib_manifest, basic_manifest, project, Project,
5+
};
46
use cargo_util::paths::dylib_path_envvar;
57

68
#[cargo_test]
@@ -1416,6 +1418,24 @@ fn default_run_workspace() {
14161418
p.cargo("run").with_stdout("run-a").run();
14171419
}
14181420

1421+
#[cargo_test]
1422+
fn print_env_verbose() {
1423+
let p = project()
1424+
.file("Cargo.toml", &basic_manifest("a", "0.0.1"))
1425+
.file("src/main.rs", r#"fn main() {println!("run-a");}"#)
1426+
.build();
1427+
1428+
p.cargo("run -vv")
1429+
.with_stderr(
1430+
"\
1431+
[COMPILING] a v0.0.1 ([CWD])
1432+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name a[..]`
1433+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1434+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] target/debug/a[EXE]`",
1435+
)
1436+
.run();
1437+
}
1438+
14191439
#[cargo_test]
14201440
#[cfg(target_os = "macos")]
14211441
fn run_link_system_path_macos() {

tests/testsuite/test.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4861,3 +4861,24 @@ error: unexpected argument `--keep-going` found
48614861
.with_status(101)
48624862
.run();
48634863
}
4864+
4865+
#[cargo_test]
4866+
fn cargo_test_print_env_verbose() {
4867+
let p = project()
4868+
.file("Cargo.toml", &basic_manifest("foo", "0.0.1"))
4869+
.file("src/lib.rs", "")
4870+
.build();
4871+
4872+
p.cargo("test -vv")
4873+
.with_stderr(
4874+
"\
4875+
[COMPILING] foo v0.0.1 ([CWD])
4876+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name foo[..]`
4877+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name foo[..]`
4878+
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
4879+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] [CWD]/target/debug/deps/foo-[..][EXE]`
4880+
[DOCTEST] foo
4881+
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustdoc --crate-type lib --crate-name foo[..]",
4882+
)
4883+
.run();
4884+
}

0 commit comments

Comments
 (0)