Skip to content

Commit

Permalink
Another small simplification of prepare_test_runner
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Oct 13, 2024
1 parent b7dea9b commit cdab1fb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ fn process_snapshots(
/// Run the tests
fn test_run(mut cmd: TestCommand, color: ColorWhen) -> Result<(), Box<dyn Error>> {
let loc = handle_target_args(&cmd.target_args, &cmd.test_runner_options.package)?;

// Based on any configs in the config file, update the test command.
// (Arguably slightly delicate code to ensure we're giving the correct
// relative prioritization to CLI vs. config file. We could do this in a
// single location to make it clearer...)
match loc.tool_config.snapshot_update() {
SnapshotUpdate::Auto => {
if is_ci() {
Expand Down Expand Up @@ -709,7 +714,7 @@ fn test_run(mut cmd: TestCommand, color: ColorWhen) -> Result<(), Box<dyn Error>
);

let (mut proc, snapshot_ref_file, prevents_doc_run) =
prepare_test_runner(test_runner, cmd.unreferenced, &cmd, color, &[], None, &loc)?;
prepare_test_runner(&cmd, test_runner, color, &[], None, &loc)?;

if !cmd.keep_pending {
process_snapshots(true, None, &loc, Some(Operation::Reject))?;
Expand All @@ -723,16 +728,16 @@ fn test_run(mut cmd: TestCommand, color: ColorWhen) -> Result<(), Box<dyn Error>
let status = proc.status()?;
let mut success = status.success();

// nextest currently cannot run doctests, run them with regular tests.
// nextest currently cannot run doctests, run them with regular tests. We'd
// like to deprecate this; see discussion at https://github.com/mitsuhiko/insta/pull/438
//
// Note that unlike `cargo test`, `cargo test --doctest` will run doctests
// even on crates that specify `doctests = false`. But I don't think there's
// a way to replicate the `cargo test` behavior.
if matches!(cmd.test_runner, TestRunner::Nextest) && !prevents_doc_run {
let (mut proc, _, _) = prepare_test_runner(
&TestRunner::CargoTest,
cmd.unreferenced,
&cmd,
&TestRunner::CargoTest,
color,
&["--doc"],
snapshot_ref_file.as_deref(),
Expand Down Expand Up @@ -915,9 +920,8 @@ fn handle_unreferenced_snapshots(
#[allow(clippy::type_complexity)]
#[allow(clippy::too_many_arguments)]
fn prepare_test_runner<'snapshot_ref>(
test_runner: &TestRunner,
unreferenced: UnreferencedSnapshots,
cmd: &TestCommand,
test_runner: &TestRunner,
color: ColorWhen,
extra_args: &[&str],
snapshot_ref_file: Option<&'snapshot_ref Path>,
Expand All @@ -938,7 +942,7 @@ fn prepare_test_runner<'snapshot_ref>(
proc.env("INSTA_CARGO_INSTA", "1");
proc.env("INSTA_CARGO_INSTA_VERSION", cargo_insta_version());

let snapshot_ref_file = if unreferenced != UnreferencedSnapshots::Ignore {
let snapshot_ref_file = if cmd.unreferenced != UnreferencedSnapshots::Ignore {
match snapshot_ref_file {
Some(path) => Some(Cow::Borrowed(path)),
None => {
Expand Down

0 comments on commit cdab1fb

Please sign in to comment.