Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
37 changes: 37 additions & 0 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,3 +1688,40 @@ error: unexpected argument `--keep-going` found
.with_status(101)
.run();
}

#[cargo_test(nightly, reason = "bench")]
fn cargo_bench_print_env_verbose() {
let p = project()
.file("Cargo.toml", &basic_manifest("foo", "0.0.1"))
.file(
"src/main.rs",
r#"
#![feature(test)]
#[cfg(test)]
extern crate test;

fn hello() -> &'static str {
"hello"
}

pub fn main() {
println!("{}", hello())
}

#[bench]
fn bench_hello(_b: &mut test::Bencher) {
assert_eq!(hello(), "hello")
}
"#,
)
.build();
p.cargo("bench -vv")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc[..]`
[FINISHED] bench [optimized] target(s) in [..]
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] [CWD]/target/release/deps/foo-[..][EXE] --bench`",
)
.run();
}
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
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
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();
}