Skip to content

Commit 716b02c

Browse files
committed
Auto merge of #6707 - dwijnand:test-bench-related-tweaks, r=Eh2406
Some test/bench-related tweaks Reaped from #6697
2 parents 25bf8cc + e0e6222 commit 716b02c

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

src/bin/cargo/commands/bench.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
8282
compile_opts,
8383
};
8484

85-
let mut bench_args = vec![];
86-
bench_args.extend(
87-
args.value_of("BENCHNAME")
88-
.into_iter()
89-
.map(|s| s.to_string()),
90-
);
91-
bench_args.extend(
92-
args.values_of("args")
93-
.unwrap_or_default()
94-
.map(|s| s.to_string()),
95-
);
85+
let bench_args = args.value_of("BENCHNAME").into_iter();
86+
let bench_args = bench_args.chain(args.values_of("args").unwrap_or_default());
87+
let bench_args = bench_args.collect::<Vec<_>>();
9688

9789
let err = ops::run_benches(&ws, &ops, &bench_args)?;
9890
match err {

src/bin/cargo/commands/test.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
9797
// `TESTNAME` is actually an argument of the test binary, but it's
9898
// important, so we explicitly mention it and reconfigure.
9999
let test_name: Option<&str> = args.value_of("TESTNAME");
100-
let mut test_args = vec![];
101-
test_args.extend(test_name.into_iter().map(|s| s.to_string()));
102-
test_args.extend(
103-
args.values_of("args")
104-
.unwrap_or_default()
105-
.map(|s| s.to_string()),
106-
);
100+
let test_args = args.value_of("TESTNAME").into_iter();
101+
let test_args = test_args.chain(args.values_of("args").unwrap_or_default());
102+
let test_args = test_args.collect::<Vec<_>>();
107103

108104
let no_run = args.is_present("no-run");
109105
let doc = args.is_present("doc");

src/cargo/ops/cargo_test.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct TestOptions<'a> {
1515
pub fn run_tests(
1616
ws: &Workspace<'_>,
1717
options: &TestOptions<'_>,
18-
test_args: &[String],
18+
test_args: &[&str],
1919
) -> CargoResult<Option<CargoTestError>> {
2020
let compilation = compile_tests(ws, options)?;
2121

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

5149
if options.no_run {
5250
return Ok(None);
5351
}
52+
53+
let mut args = args.to_vec();
54+
args.push("--bench");
55+
5456
let (test, errors) = run_unit_tests(options, &args, &compilation)?;
57+
5558
match errors.len() {
5659
0 => Ok(None),
5760
_ => Ok(Some(CargoTestError::new(test, errors))),
@@ -72,7 +75,7 @@ fn compile_tests<'a>(
7275
/// Runs the unit and integration tests of a package.
7376
fn run_unit_tests(
7477
options: &TestOptions<'_>,
75-
test_args: &[String],
78+
test_args: &[&str],
7679
compilation: &Compilation<'_>,
7780
) -> CargoResult<(Test, Vec<ProcessError>)> {
7881
let config = options.compile_opts.config;
@@ -125,7 +128,7 @@ fn run_unit_tests(
125128

126129
fn run_doc_tests(
127130
options: &TestOptions<'_>,
128-
test_args: &[String],
131+
test_args: &[&str],
129132
compilation: &Compilation<'_>,
130133
) -> CargoResult<(Test, Vec<ProcessError>)> {
131134
let mut errors = Vec::new();

src/cargo/util/command_prelude.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,7 @@ impl<'a> ArgMatchesExt for ArgMatches<'a> {
481481
}
482482

483483
pub fn values(args: &ArgMatches<'_>, name: &str) -> Vec<String> {
484-
args.values_of(name)
485-
.unwrap_or_default()
486-
.map(|s| s.to_string())
487-
.collect()
484+
args._values_of(name)
488485
}
489486

490487
#[derive(PartialEq, PartialOrd, Eq, Ord)]

0 commit comments

Comments
 (0)