Skip to content

Commit e0e6222

Browse files
committed
Make cargo_test require only str slices for args
1 parent 8bbe1ee commit e0e6222

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

src/bin/cargo/commands/bench.rs

Lines changed: 3 additions & 11 deletions
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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 9 additions & 6 deletions
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();

0 commit comments

Comments
 (0)