Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another small simplification of prepare_test_runner #667

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ 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. Default
// is `SnapshotUpdate::Auto`.
match loc.tool_config.snapshot_update() {
SnapshotUpdate::Auto => {
if is_ci() {
Expand Down Expand Up @@ -709,7 +712,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 +726,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 +918,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 +940,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
Loading