From c8914411e682aab1403b0dca70d0729e3072046d Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Wed, 28 Nov 2018 21:23:10 +0300 Subject: [PATCH 1/5] pass -q flag to test harness --- src/bin/cargo/commands/test.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index dca409845de..ab613c9dbf3 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -140,6 +140,10 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { .map(|s| s.to_string()), ); + if args.is_present("quiet") { + test_args.push("-q".to_string()) + } + let err = ops::run_tests(&ws, &ops, &test_args)?; match err { None => Ok(()), From 57d5048cad19f21d99fbc0828bbce6b65508f191 Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Thu, 29 Nov 2018 02:55:34 +0300 Subject: [PATCH 2/5] update --quiet description for cargo test --- src/bin/cargo/cli.rs | 1 - src/bin/cargo/commands/test.rs | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 3b2f2f99ab0..f0fc2d28b50 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -220,7 +220,6 @@ See 'cargo help ' for more information on a specific command.\n", .arg( opt("quiet", "No output printed to stdout") .short("q") - .global(true), ) .arg( opt("color", "Coloring: auto, always, never") diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index ab613c9dbf3..b2cff39b048 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -18,6 +18,10 @@ pub fn cli() -> App { .multiple(true) .last(true), ) + .arg( + opt("quiet", "Display one character per test instead of one line") + .short("q") + ) .arg_targets_all( "Test only this package's library unit tests", "Test only the specified binary", From e873e4e9d5e043d9441813328b4112e67c93f68a Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Thu, 29 Nov 2018 21:32:24 +0300 Subject: [PATCH 3/5] explicitly add --quiet option to all subcommands --- src/bin/cargo/cli.rs | 8 +++----- src/bin/cargo/commands/bench.rs | 1 + src/bin/cargo/commands/build.rs | 1 + src/bin/cargo/commands/check.rs | 1 + src/bin/cargo/commands/clean.rs | 1 + src/bin/cargo/commands/doc.rs | 1 + src/bin/cargo/commands/fetch.rs | 1 + src/bin/cargo/commands/fix.rs | 1 + src/bin/cargo/commands/generate_lockfile.rs | 1 + src/bin/cargo/commands/git_checkout.rs | 1 + src/bin/cargo/commands/init.rs | 1 + src/bin/cargo/commands/install.rs | 1 + src/bin/cargo/commands/locate_project.rs | 1 + src/bin/cargo/commands/login.rs | 1 + src/bin/cargo/commands/metadata.rs | 1 + src/bin/cargo/commands/new.rs | 1 + src/bin/cargo/commands/owner.rs | 1 + src/bin/cargo/commands/package.rs | 1 + src/bin/cargo/commands/pkgid.rs | 1 + src/bin/cargo/commands/publish.rs | 1 + src/bin/cargo/commands/read_manifest.rs | 1 + src/bin/cargo/commands/run.rs | 1 + src/bin/cargo/commands/rustc.rs | 1 + src/bin/cargo/commands/rustdoc.rs | 1 + src/bin/cargo/commands/search.rs | 1 + src/bin/cargo/commands/uninstall.rs | 1 + src/bin/cargo/commands/update.rs | 1 + src/bin/cargo/commands/verify_project.rs | 1 + src/bin/cargo/commands/version.rs | 1 + src/bin/cargo/commands/yank.rs | 1 + 30 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index f0fc2d28b50..a1b8eb8ce7b 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -145,7 +145,7 @@ fn execute_subcommand(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { config.configure( args.occurrences_of("verbose") as u32, - if args.is_present("quiet") { + if args.is_present("quiet") || subcommand_args.is_present("quiet") { Some(true) } else { None @@ -217,10 +217,7 @@ See 'cargo help ' for more information on a specific command.\n", .multiple(true) .global(true), ) - .arg( - opt("quiet", "No output printed to stdout") - .short("q") - ) + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg( opt("color", "Coloring: auto, always, never") .value_name("WHEN") @@ -239,3 +236,4 @@ See 'cargo help ' for more information on a specific command.\n", ) .subcommands(commands::builtin()) } + diff --git a/src/bin/cargo/commands/bench.rs b/src/bin/cargo/commands/bench.rs index 84681e6bde7..0a42f450cb1 100644 --- a/src/bin/cargo/commands/bench.rs +++ b/src/bin/cargo/commands/bench.rs @@ -6,6 +6,7 @@ pub fn cli() -> App { subcommand("bench") .setting(AppSettings::TrailingVarArg) .about("Execute all benchmarks of a local package") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg( Arg::with_name("BENCHNAME") .help("If specified, only run benches containing this string in their names"), diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index 3938a8e5630..367ab2e91eb 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -7,6 +7,7 @@ pub fn cli() -> App { // subcommand aliases are handled in aliased_command() // .alias("b") .about("Compile a local package and all of its dependencies") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_package_spec( "Package to build (see `cargo help pkgid`)", "Build all packages in the workspace", diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index e4f73f260ae..d0d5c6215bd 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -7,6 +7,7 @@ pub fn cli() -> App { // subcommand aliases are handled in aliased_command() // .alias("c") .about("Check a local package and all of its dependencies for errors") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_package_spec( "Package(s) to check", "Check all packages in the workspace", diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index e21fc470f1e..e336f73a031 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -5,6 +5,7 @@ use cargo::ops::{self, CleanOptions}; pub fn cli() -> App { subcommand("clean") .about("Remove artifacts that cargo has generated in the past") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_package_spec_simple("Package to clean artifacts for") .arg_manifest_path() .arg_target_triple("Target triple to clean output for") diff --git a/src/bin/cargo/commands/doc.rs b/src/bin/cargo/commands/doc.rs index a802e34b996..8405015dfbb 100644 --- a/src/bin/cargo/commands/doc.rs +++ b/src/bin/cargo/commands/doc.rs @@ -5,6 +5,7 @@ use cargo::ops::{self, DocOptions}; pub fn cli() -> App { subcommand("doc") .about("Build a package's documentation") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(opt( "open", "Opens the docs in a browser after the operation", diff --git a/src/bin/cargo/commands/fetch.rs b/src/bin/cargo/commands/fetch.rs index 7d364132050..b07367bb65e 100644 --- a/src/bin/cargo/commands/fetch.rs +++ b/src/bin/cargo/commands/fetch.rs @@ -6,6 +6,7 @@ use cargo::ops::FetchOptions; pub fn cli() -> App { subcommand("fetch") .about("Fetch dependencies of a package from the network") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_manifest_path() .arg_target_triple("Fetch dependencies for the target triple") .after_help( diff --git a/src/bin/cargo/commands/fix.rs b/src/bin/cargo/commands/fix.rs index bc654297439..a3e5c442ff2 100644 --- a/src/bin/cargo/commands/fix.rs +++ b/src/bin/cargo/commands/fix.rs @@ -5,6 +5,7 @@ use cargo::ops::{self, CompileFilter, FilterRule}; pub fn cli() -> App { subcommand("fix") .about("Automatically fix lint warnings reported by rustc") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_package_spec( "Package(s) to fix", "Fix all packages in the workspace", diff --git a/src/bin/cargo/commands/generate_lockfile.rs b/src/bin/cargo/commands/generate_lockfile.rs index 6e5135a1759..d18c5668303 100644 --- a/src/bin/cargo/commands/generate_lockfile.rs +++ b/src/bin/cargo/commands/generate_lockfile.rs @@ -5,6 +5,7 @@ use cargo::ops; pub fn cli() -> App { subcommand("generate-lockfile") .about("Generate the lockfile for a package") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_manifest_path() } diff --git a/src/bin/cargo/commands/git_checkout.rs b/src/bin/cargo/commands/git_checkout.rs index c229307c473..26b6fe2539a 100644 --- a/src/bin/cargo/commands/git_checkout.rs +++ b/src/bin/cargo/commands/git_checkout.rs @@ -7,6 +7,7 @@ use cargo::util::ToUrl; pub fn cli() -> App { subcommand("git-checkout") .about("Checkout a copy of a Git repository") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg( Arg::with_name("url") .long("url") diff --git a/src/bin/cargo/commands/init.rs b/src/bin/cargo/commands/init.rs index 8fb765202ca..644cec1f88b 100644 --- a/src/bin/cargo/commands/init.rs +++ b/src/bin/cargo/commands/init.rs @@ -5,6 +5,7 @@ use cargo::ops; pub fn cli() -> App { subcommand("init") .about("Create a new cargo package in an existing directory") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("path").default_value(".")) .arg(opt("registry", "Registry to use").value_name("REGISTRY")) .arg_new_opts() diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index a0a9fdfe366..de93a1cbce9 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -7,6 +7,7 @@ use cargo::util::ToUrl; pub fn cli() -> App { subcommand("install") .about("Install a Rust binary. Default location is $HOME/.cargo/bin") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("crate").empty_values(false).multiple(true)) .arg( opt("version", "Specify a version to install from crates.io") diff --git a/src/bin/cargo/commands/locate_project.rs b/src/bin/cargo/commands/locate_project.rs index 8fb1cc60021..a48e387b411 100644 --- a/src/bin/cargo/commands/locate_project.rs +++ b/src/bin/cargo/commands/locate_project.rs @@ -6,6 +6,7 @@ use serde::Serialize; pub fn cli() -> App { subcommand("locate-project") .about("Print a JSON representation of a Cargo.toml file's location") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_manifest_path() } diff --git a/src/bin/cargo/commands/login.rs b/src/bin/cargo/commands/login.rs index 5d76e7e12fd..7025433a90b 100644 --- a/src/bin/cargo/commands/login.rs +++ b/src/bin/cargo/commands/login.rs @@ -8,6 +8,7 @@ pub fn cli() -> App { "Save an api token from the registry locally. \ If token is not specified, it will be read from stdin.", ) + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("token")) .arg( opt("host", "Host to set the token for") diff --git a/src/bin/cargo/commands/metadata.rs b/src/bin/cargo/commands/metadata.rs index eb2a453bbbb..5add91db09a 100644 --- a/src/bin/cargo/commands/metadata.rs +++ b/src/bin/cargo/commands/metadata.rs @@ -10,6 +10,7 @@ pub fn cli() -> App { the concrete used versions including overrides, \ in machine-readable format", ) + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_features() .arg(opt( "no-deps", diff --git a/src/bin/cargo/commands/new.rs b/src/bin/cargo/commands/new.rs index 517b9085d04..0bb180aab7b 100644 --- a/src/bin/cargo/commands/new.rs +++ b/src/bin/cargo/commands/new.rs @@ -5,6 +5,7 @@ use cargo::ops; pub fn cli() -> App { subcommand("new") .about("Create a new cargo package at ") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("path").required(true)) .arg(opt("registry", "Registry to use").value_name("REGISTRY")) .arg_new_opts() diff --git a/src/bin/cargo/commands/owner.rs b/src/bin/cargo/commands/owner.rs index 09a76b96bb9..e2c672667b4 100644 --- a/src/bin/cargo/commands/owner.rs +++ b/src/bin/cargo/commands/owner.rs @@ -5,6 +5,7 @@ use cargo::ops::{self, OwnersOptions}; pub fn cli() -> App { subcommand("owner") .about("Manage the owners of a crate on the registry") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("crate")) .arg(multi_opt("add", "LOGIN", "Name of a user or team to invite as an owner").short("a")) .arg( diff --git a/src/bin/cargo/commands/package.rs b/src/bin/cargo/commands/package.rs index 1964e138cd9..772ea21a2c0 100644 --- a/src/bin/cargo/commands/package.rs +++ b/src/bin/cargo/commands/package.rs @@ -5,6 +5,7 @@ use cargo::ops::{self, PackageOpts}; pub fn cli() -> App { subcommand("package") .about("Assemble the local package into a distributable tarball") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg( opt( "list", diff --git a/src/bin/cargo/commands/pkgid.rs b/src/bin/cargo/commands/pkgid.rs index 2cf423d37a4..e3186ae8d7f 100644 --- a/src/bin/cargo/commands/pkgid.rs +++ b/src/bin/cargo/commands/pkgid.rs @@ -5,6 +5,7 @@ use cargo::ops; pub fn cli() -> App { subcommand("pkgid") .about("Print a fully qualified package specification") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("spec")) .arg_package("Argument to get the package ID specifier for") .arg_manifest_path() diff --git a/src/bin/cargo/commands/publish.rs b/src/bin/cargo/commands/publish.rs index 67b4ed2d2a8..be5dcffddf4 100644 --- a/src/bin/cargo/commands/publish.rs +++ b/src/bin/cargo/commands/publish.rs @@ -5,6 +5,7 @@ use cargo::ops::{self, PublishOpts}; pub fn cli() -> App { subcommand("publish") .about("Upload a package to the registry") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_index() .arg(opt("token", "Token to use when uploading").value_name("TOKEN")) .arg(opt( diff --git a/src/bin/cargo/commands/read_manifest.rs b/src/bin/cargo/commands/read_manifest.rs index b88787064aa..fe2528b18aa 100644 --- a/src/bin/cargo/commands/read_manifest.rs +++ b/src/bin/cargo/commands/read_manifest.rs @@ -11,6 +11,7 @@ Print a JSON representation of a Cargo.toml manifest. Deprecated, use `cargo metadata --no-deps` instead.\ ", ) + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_manifest_path() } diff --git a/src/bin/cargo/commands/run.rs b/src/bin/cargo/commands/run.rs index 3f37fc0910b..5a99dddbb41 100644 --- a/src/bin/cargo/commands/run.rs +++ b/src/bin/cargo/commands/run.rs @@ -9,6 +9,7 @@ pub fn cli() -> App { // .alias("r") .setting(AppSettings::TrailingVarArg) .about("Run a binary or example of the local package") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("args").multiple(true)) .arg_targets_bin_example( "Name of the bin target to run", diff --git a/src/bin/cargo/commands/rustc.rs b/src/bin/cargo/commands/rustc.rs index b0400b556b3..5cb7f94e09b 100644 --- a/src/bin/cargo/commands/rustc.rs +++ b/src/bin/cargo/commands/rustc.rs @@ -6,6 +6,7 @@ pub fn cli() -> App { subcommand("rustc") .setting(AppSettings::TrailingVarArg) .about("Compile a package and all of its dependencies") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("args").multiple(true)) .arg_package("Package to build") .arg_jobs() diff --git a/src/bin/cargo/commands/rustdoc.rs b/src/bin/cargo/commands/rustdoc.rs index ad2ed4371d0..6616dc70e18 100644 --- a/src/bin/cargo/commands/rustdoc.rs +++ b/src/bin/cargo/commands/rustdoc.rs @@ -6,6 +6,7 @@ pub fn cli() -> App { subcommand("rustdoc") .setting(AppSettings::TrailingVarArg) .about("Build a package's documentation, using specified custom flags.") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("args").multiple(true)) .arg(opt( "open", diff --git a/src/bin/cargo/commands/search.rs b/src/bin/cargo/commands/search.rs index f9cf7e25d34..15bab64312a 100644 --- a/src/bin/cargo/commands/search.rs +++ b/src/bin/cargo/commands/search.rs @@ -7,6 +7,7 @@ use cargo::ops; pub fn cli() -> App { subcommand("search") .about("Search packages in crates.io") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("query").multiple(true)) .arg_index() .arg( diff --git a/src/bin/cargo/commands/uninstall.rs b/src/bin/cargo/commands/uninstall.rs index 90d21d16b4f..4756da1cbbb 100644 --- a/src/bin/cargo/commands/uninstall.rs +++ b/src/bin/cargo/commands/uninstall.rs @@ -5,6 +5,7 @@ use cargo::ops; pub fn cli() -> App { subcommand("uninstall") .about("Remove a Rust binary") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("spec").multiple(true)) .arg_package_spec_simple("Package to uninstall") .arg(multi_opt("bin", "NAME", "Only uninstall the binary NAME")) diff --git a/src/bin/cargo/commands/update.rs b/src/bin/cargo/commands/update.rs index 27ba7dda019..3ffadcefcbe 100644 --- a/src/bin/cargo/commands/update.rs +++ b/src/bin/cargo/commands/update.rs @@ -5,6 +5,7 @@ use cargo::ops::{self, UpdateOptions}; pub fn cli() -> App { subcommand("update") .about("Update dependencies as recorded in the local lock file") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_package_spec_simple("Package to update") .arg(opt( "aggressive", diff --git a/src/bin/cargo/commands/verify_project.rs b/src/bin/cargo/commands/verify_project.rs index 0b17e4e5028..fe2b42aebed 100644 --- a/src/bin/cargo/commands/verify_project.rs +++ b/src/bin/cargo/commands/verify_project.rs @@ -8,6 +8,7 @@ use cargo::print_json; pub fn cli() -> App { subcommand("verify-project") .about("Check correctness of crate manifest") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg_manifest_path() } diff --git a/src/bin/cargo/commands/version.rs b/src/bin/cargo/commands/version.rs index d546ff7057c..2e55ab83687 100644 --- a/src/bin/cargo/commands/version.rs +++ b/src/bin/cargo/commands/version.rs @@ -4,6 +4,7 @@ use crate::cli; pub fn cli() -> App { subcommand("version").about("Show version information") + .arg(opt("quiet", "No output printed to stdout").short("q")) } pub fn exec(_config: &mut Config, args: &ArgMatches<'_>) -> CliResult { diff --git a/src/bin/cargo/commands/yank.rs b/src/bin/cargo/commands/yank.rs index a997148162d..3079c544fb9 100644 --- a/src/bin/cargo/commands/yank.rs +++ b/src/bin/cargo/commands/yank.rs @@ -5,6 +5,7 @@ use cargo::ops; pub fn cli() -> App { subcommand("yank") .about("Remove a pushed crate from the index") + .arg(opt("quiet", "No output printed to stdout").short("q")) .arg(Arg::with_name("crate")) .arg(opt("vers", "The version to yank or un-yank").value_name("VERSION")) .arg(opt( From 805acffed9d95363f39ec0dc3a9d0d1134fa5382 Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Thu, 21 Feb 2019 16:41:05 +0300 Subject: [PATCH 4/5] forward --quiet flag only if harness=true --- src/bin/cargo/commands/test.rs | 4 ---- src/cargo/core/compiler/compilation.rs | 4 ++-- src/cargo/core/compiler/context/mod.rs | 3 +-- src/cargo/ops/cargo_test.rs | 8 +++++++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index b2cff39b048..852ddc65b83 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -144,10 +144,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { .map(|s| s.to_string()), ); - if args.is_present("quiet") { - test_args.push("-q".to_string()) - } - let err = ops::run_tests(&ws, &ops, &test_args)?; match err { None => Ok(()), diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 863affc7cfe..afe2c9e4859 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use semver::Version; use super::BuildContext; -use crate::core::{Edition, Package, PackageId, Target, TargetKind}; +use crate::core::{Edition, Package, PackageId, Target}; use crate::util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder}; pub struct Doctest { @@ -22,7 +22,7 @@ pub struct Doctest { /// A structure returning the result of a compilation. pub struct Compilation<'cfg> { /// An array of all tests created during this compilation. - pub tests: Vec<(Package, TargetKind, String, PathBuf)>, + pub tests: Vec<(Package, Target, PathBuf)>, /// An array of all binaries created. pub binaries: Vec, diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index 27f8adb2068..650e7d2f552 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -167,8 +167,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { if unit.mode == CompileMode::Test { self.compilation.tests.push(( unit.pkg.clone(), - unit.target.kind().clone(), - unit.target.name().to_string(), + unit.target.clone(), output.path.clone(), )); } else if unit.target.is_bin() || unit.target.is_bin_example() { diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index d335a80a800..210da9879e4 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -2,6 +2,7 @@ use std::ffi::OsString; use crate::core::compiler::{Compilation, Doctest}; use crate::core::Workspace; +use crate::core::shell::Verbosity; use crate::ops; use crate::util::errors::CargoResult; use crate::util::{CargoTestError, ProcessError, Test}; @@ -80,10 +81,15 @@ fn run_unit_tests( let mut errors = Vec::new(); - for &(ref pkg, ref kind, ref test, ref exe) in &compilation.tests { + for &(ref pkg, ref target, ref exe) in &compilation.tests { + let kind = target.kind(); + let test = target.name().to_string(); let exe_display = exe.strip_prefix(cwd).unwrap_or(exe).display(); let mut cmd = compilation.target_process(exe, pkg)?; cmd.args(test_args); + if target.harness() && config.shell().verbosity() == Verbosity::Quiet { + cmd.arg("--quiet"); + } config .shell() .concise(|shell| shell.status("Running", &exe_display))?; From d93b2d75e6b8f43adbcf7b139bace6165f84cc0a Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Thu, 21 Feb 2019 18:16:49 +0300 Subject: [PATCH 5/5] test --quiet option with and without harness --- tests/testsuite/test.rs | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index df5b15df7d8..93e34b77776 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -144,6 +144,79 @@ fn cargo_test_overflow_checks() { p.process(&p.release_bin("foo")).with_stdout("").run(); } +#[test] +fn cargo_test_quiet_with_harness() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + + [[test]] + name = "foo" + path = "src/foo.rs" + harness = true + "#, + ) + .file( + "src/foo.rs", + r#" + fn main() {} + #[test] fn test_hello() {} + "#, + ).build(); + + p.cargo("test -q") + .with_stdout( + " +running 1 test +. +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out + +" + ).with_stderr("") + .run(); +} + +#[test] +fn cargo_test_quiet_no_harness() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + + [[bin]] + name = "foo" + test = false + + [[test]] + name = "foo" + path = "src/main.rs" + harness = false + "#, + ) + .file( + "src/main.rs", + r#" + fn main() {} + #[test] fn test_hello() {} + "#, + ).build(); + + p.cargo("test -q") + .with_stdout( + "" + ).with_stderr("") + .run(); +} + #[test] fn cargo_test_verbose() { let p = project()