diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 9e58d61bc54..2524b44901a 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -22,30 +22,7 @@ pub fn run_tests( let compilation = compile_tests(ws, options)?; if options.no_run { - let config = ws.config(); - let cwd = config.cwd(); - for UnitOutput { - unit, - path, - script_meta, - } in compilation.tests.iter() - { - let (exe_display, cmd) = cmd_builds( - config, - cwd, - unit, - path, - script_meta, - test_args, - &compilation, - )?; - config - .shell() - .concise(|shell| shell.status("Executable", &exe_display))?; - config - .shell() - .verbose(|shell| shell.status("Executable", &cmd))?; - } + display_no_run_information(ws, test_args, &compilation)?; return Ok(None); } let (test, mut errors) = run_unit_tests(ws.config(), options, test_args, &compilation)?; @@ -73,23 +50,7 @@ pub fn run_benches( let compilation = compile_tests(ws, options)?; if options.no_run { - let config = ws.config(); - let cwd = config.cwd(); - for UnitOutput { - unit, - path, - script_meta, - } in compilation.tests.iter() - { - let (exe_display, cmd) = - cmd_builds(config, cwd, unit, path, script_meta, args, &compilation)?; - config - .shell() - .concise(|shell| shell.status("Executable", &exe_display))?; - config - .shell() - .verbose(|shell| shell.status("Executable", &cmd))?; - } + display_no_run_information(ws, args, &compilation)?; return Ok(None); } @@ -126,8 +87,6 @@ fn run_unit_tests( script_meta, } in compilation.tests.iter() { - let _test = unit.target.name().to_string(); - let (exe_display, cmd) = cmd_builds(config, cwd, unit, path, script_meta, test_args, compilation)?; config @@ -171,41 +130,6 @@ fn run_unit_tests( } } -fn cmd_builds( - config: &Config, - cwd: &Path, - unit: &Unit, - path: &PathBuf, - script_meta: &Option, - test_args: &[&str], - compilation: &Compilation<'_>, -) -> CargoResult<(String, ProcessBuilder)> { - let test_path = unit.target.src_path().path().unwrap(); - let exe_display = if let TargetKind::Test = unit.target.kind() { - format!( - "{} ({})", - test_path - .strip_prefix(unit.pkg.root()) - .unwrap_or(test_path) - .display(), - path.strip_prefix(cwd).unwrap_or(path).display() - ) - } else { - format!( - "unittests ({})", - path.strip_prefix(cwd).unwrap_or(path).display() - ) - }; - - let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?; - cmd.args(test_args); - if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet { - cmd.arg("--quiet"); - } - - Ok((exe_display, cmd)) -} - fn run_doc_tests( ws: &Workspace<'_>, options: &TestOptions, @@ -323,3 +247,71 @@ fn run_doc_tests( } Ok((Test::Doc, errors)) } + +fn display_no_run_information( + ws: &Workspace<'_>, + test_args: &[&str], + compilation: &Compilation<'_>, +) -> CargoResult<()> { + let config = ws.config(); + let cwd = config.cwd(); + for UnitOutput { + unit, + path, + script_meta, + } in compilation.tests.iter() + { + let (exe_display, cmd) = cmd_builds( + config, + cwd, + unit, + path, + script_meta, + test_args, + &compilation, + )?; + config + .shell() + .concise(|shell| shell.status("Executable", &exe_display))?; + config + .shell() + .verbose(|shell| shell.status("Executable", &cmd))?; + } + + return Ok(()); +} + +fn cmd_builds( + config: &Config, + cwd: &Path, + unit: &Unit, + path: &PathBuf, + script_meta: &Option, + test_args: &[&str], + compilation: &Compilation<'_>, +) -> CargoResult<(String, ProcessBuilder)> { + let test_path = unit.target.src_path().path().unwrap(); + let exe_display = if let TargetKind::Test = unit.target.kind() { + format!( + "{} ({})", + test_path + .strip_prefix(unit.pkg.root()) + .unwrap_or(test_path) + .display(), + path.strip_prefix(cwd).unwrap_or(path).display() + ) + } else { + format!( + "unittests ({})", + path.strip_prefix(cwd).unwrap_or(path).display() + ) + }; + + let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?; + cmd.args(test_args); + if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet { + cmd.arg("--quiet"); + } + + Ok((exe_display, cmd)) +}