Skip to content

Commit

Permalink
extract display_no_run_information
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke committed Jan 31, 2022
1 parent eca63cf commit 4969b19
Showing 1 changed file with 70 additions and 78 deletions.
148 changes: 70 additions & 78 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -171,41 +130,6 @@ fn run_unit_tests(
}
}

fn cmd_builds(
config: &Config,
cwd: &Path,
unit: &Unit,
path: &PathBuf,
script_meta: &Option<Metadata>,
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,
Expand Down Expand Up @@ -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<Metadata>,
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))
}

0 comments on commit 4969b19

Please sign in to comment.