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,
|
compile_opts,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut bench_args = vec![];
|
let bench_args = args.value_of("BENCHNAME").into_iter();
|
||||||
bench_args.extend(
|
let bench_args = bench_args.chain(args.values_of("args").unwrap_or_default());
|
||||||
args.value_of("BENCHNAME")
|
let bench_args = bench_args.collect::<Vec<_>>();
|
||||||
.into_iter()
|
|
||||||
.map(|s| s.to_string()),
|
|
||||||
);
|
|
||||||
bench_args.extend(
|
|
||||||
args.values_of("args")
|
|
||||||
.unwrap_or_default()
|
|
||||||
.map(|s| s.to_string()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let err = ops::run_benches(&ws, &ops, &bench_args)?;
|
let err = ops::run_benches(&ws, &ops, &bench_args)?;
|
||||||
match err {
|
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
|
// `TESTNAME` is actually an argument of the test binary, but it's
|
||||||
// important, so we explicitly mention it and reconfigure.
|
// important, so we explicitly mention it and reconfigure.
|
||||||
let test_name: Option<&str> = args.value_of("TESTNAME");
|
let test_name: Option<&str> = args.value_of("TESTNAME");
|
||||||
let mut test_args = vec![];
|
let test_args = args.value_of("TESTNAME").into_iter();
|
||||||
test_args.extend(test_name.into_iter().map(|s| s.to_string()));
|
let test_args = test_args.chain(args.values_of("args").unwrap_or_default());
|
||||||
test_args.extend(
|
let test_args = test_args.collect::<Vec<_>>();
|
||||||
args.values_of("args")
|
|
||||||
.unwrap_or_default()
|
|
||||||
.map(|s| s.to_string()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let no_run = args.is_present("no-run");
|
let no_run = args.is_present("no-run");
|
||||||
let doc = args.is_present("doc");
|
let doc = args.is_present("doc");
|
||||||
|
@ -15,7 +15,7 @@ pub struct TestOptions<'a> {
|
|||||||
pub fn run_tests(
|
pub fn run_tests(
|
||||||
ws: &Workspace<'_>,
|
ws: &Workspace<'_>,
|
||||||
options: &TestOptions<'_>,
|
options: &TestOptions<'_>,
|
||||||
test_args: &[String],
|
test_args: &[&str],
|
||||||
) -> CargoResult<Option<CargoTestError>> {
|
) -> CargoResult<Option<CargoTestError>> {
|
||||||
let compilation = compile_tests(ws, options)?;
|
let compilation = compile_tests(ws, options)?;
|
||||||
|
|
||||||
@ -42,16 +42,19 @@ pub fn run_tests(
|
|||||||
pub fn run_benches(
|
pub fn run_benches(
|
||||||
ws: &Workspace<'_>,
|
ws: &Workspace<'_>,
|
||||||
options: &TestOptions<'_>,
|
options: &TestOptions<'_>,
|
||||||
args: &[String],
|
args: &[&str],
|
||||||
) -> CargoResult<Option<CargoTestError>> {
|
) -> CargoResult<Option<CargoTestError>> {
|
||||||
let mut args = args.to_vec();
|
|
||||||
args.push("--bench".to_string());
|
|
||||||
let compilation = compile_tests(ws, options)?;
|
let compilation = compile_tests(ws, options)?;
|
||||||
|
|
||||||
if options.no_run {
|
if options.no_run {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut args = args.to_vec();
|
||||||
|
args.push("--bench");
|
||||||
|
|
||||||
let (test, errors) = run_unit_tests(options, &args, &compilation)?;
|
let (test, errors) = run_unit_tests(options, &args, &compilation)?;
|
||||||
|
|
||||||
match errors.len() {
|
match errors.len() {
|
||||||
0 => Ok(None),
|
0 => Ok(None),
|
||||||
_ => Ok(Some(CargoTestError::new(test, errors))),
|
_ => Ok(Some(CargoTestError::new(test, errors))),
|
||||||
@ -72,7 +75,7 @@ fn compile_tests<'a>(
|
|||||||
/// Runs the unit and integration tests of a package.
|
/// Runs the unit and integration tests of a package.
|
||||||
fn run_unit_tests(
|
fn run_unit_tests(
|
||||||
options: &TestOptions<'_>,
|
options: &TestOptions<'_>,
|
||||||
test_args: &[String],
|
test_args: &[&str],
|
||||||
compilation: &Compilation<'_>,
|
compilation: &Compilation<'_>,
|
||||||
) -> CargoResult<(Test, Vec<ProcessError>)> {
|
) -> CargoResult<(Test, Vec<ProcessError>)> {
|
||||||
let config = options.compile_opts.config;
|
let config = options.compile_opts.config;
|
||||||
@ -125,7 +128,7 @@ fn run_unit_tests(
|
|||||||
|
|
||||||
fn run_doc_tests(
|
fn run_doc_tests(
|
||||||
options: &TestOptions<'_>,
|
options: &TestOptions<'_>,
|
||||||
test_args: &[String],
|
test_args: &[&str],
|
||||||
compilation: &Compilation<'_>,
|
compilation: &Compilation<'_>,
|
||||||
) -> CargoResult<(Test, Vec<ProcessError>)> {
|
) -> CargoResult<(Test, Vec<ProcessError>)> {
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
|
@ -481,10 +481,7 @@ impl<'a> ArgMatchesExt for ArgMatches<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn values(args: &ArgMatches<'_>, name: &str) -> Vec<String> {
|
pub fn values(args: &ArgMatches<'_>, name: &str) -> Vec<String> {
|
||||||
args.values_of(name)
|
args._values_of(name)
|
||||||
.unwrap_or_default()
|
|
||||||
.map(|s| s.to_string())
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, PartialOrd, Eq, Ord)]
|
#[derive(PartialEq, PartialOrd, Eq, Ord)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user