mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #6707 - dwijnand:test-bench-related-tweaks, r=Eh2406
Some test/bench-related tweaks Reaped from #6697
This commit is contained in:
commit
716b02cb4c
@ -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 {
|
||||
|
@ -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");
|
||||
|
@ -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)?;
|
||||
|
||||
@ -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))),
|
||||
@ -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;
|
||||
@ -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();
|
||||
|
@ -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)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user