Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some test/bench-related tweaks #6707

Merged
merged 2 commits into from
Mar 2, 2019
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
14 changes: 3 additions & 11 deletions src/bin/cargo/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
compile_opts,
};

let mut bench_args = vec![];
bench_args.extend(
args.value_of("BENCHNAME")
.into_iter()
.map(|s| s.to_string()),
);
bench_args.extend(
args.values_of("args")
.unwrap_or_default()
.map(|s| s.to_string()),
);
let bench_args = args.value_of("BENCHNAME").into_iter();
let bench_args = bench_args.chain(args.values_of("args").unwrap_or_default());
let bench_args = bench_args.collect::<Vec<_>>();

let err = ops::run_benches(&ws, &ops, &bench_args)?;
match err {
Expand Down
10 changes: 3 additions & 7 deletions src/bin/cargo/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
// `TESTNAME` is actually an argument of the test binary, but it's
// important, so we explicitly mention it and reconfigure.
let test_name: Option<&str> = args.value_of("TESTNAME");
let mut test_args = vec![];
test_args.extend(test_name.into_iter().map(|s| s.to_string()));
test_args.extend(
args.values_of("args")
.unwrap_or_default()
.map(|s| s.to_string()),
);
let test_args = args.value_of("TESTNAME").into_iter();
let test_args = test_args.chain(args.values_of("args").unwrap_or_default());
let test_args = test_args.collect::<Vec<_>>();

let no_run = args.is_present("no-run");
let doc = args.is_present("doc");
Expand Down
15 changes: 9 additions & 6 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct TestOptions<'a> {
pub fn run_tests(
ws: &Workspace<'_>,
options: &TestOptions<'_>,
test_args: &[String],
test_args: &[&str],
) -> CargoResult<Option<CargoTestError>> {
let compilation = compile_tests(ws, options)?;

Expand All @@ -42,16 +42,19 @@ pub fn run_tests(
pub fn run_benches(
ws: &Workspace<'_>,
options: &TestOptions<'_>,
args: &[String],
args: &[&str],
) -> CargoResult<Option<CargoTestError>> {
let mut args = args.to_vec();
args.push("--bench".to_string());
let compilation = compile_tests(ws, options)?;

if options.no_run {
return Ok(None);
}

let mut args = args.to_vec();
args.push("--bench");

let (test, errors) = run_unit_tests(options, &args, &compilation)?;

match errors.len() {
0 => Ok(None),
_ => Ok(Some(CargoTestError::new(test, errors))),
Expand All @@ -72,7 +75,7 @@ fn compile_tests<'a>(
/// Runs the unit and integration tests of a package.
fn run_unit_tests(
options: &TestOptions<'_>,
test_args: &[String],
test_args: &[&str],
compilation: &Compilation<'_>,
) -> CargoResult<(Test, Vec<ProcessError>)> {
let config = options.compile_opts.config;
Expand Down Expand Up @@ -125,7 +128,7 @@ fn run_unit_tests(

fn run_doc_tests(
options: &TestOptions<'_>,
test_args: &[String],
test_args: &[&str],
compilation: &Compilation<'_>,
) -> CargoResult<(Test, Vec<ProcessError>)> {
let mut errors = Vec::new();
Expand Down
5 changes: 1 addition & 4 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,7 @@ impl<'a> ArgMatchesExt for ArgMatches<'a> {
}

pub fn values(args: &ArgMatches<'_>, name: &str) -> Vec<String> {
args.values_of(name)
.unwrap_or_default()
.map(|s| s.to_string())
.collect()
args._values_of(name)
}

#[derive(PartialEq, PartialOrd, Eq, Ord)]
Expand Down