From ea8332fb88d124016e000f07f1e88f818f4de026 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Sun, 6 Oct 2024 10:49:32 -0700 Subject: [PATCH] Better deprecation warning for `--no-force-pass` (#643) Not sure the old code was working, this is simpler --- cargo-insta/src/cli.rs | 20 ++++++-------------- insta/src/snapshot.rs | 4 ++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/cargo-insta/src/cli.rs b/cargo-insta/src/cli.rs index f2e5a341..5783ff55 100644 --- a/cargo-insta/src/cli.rs +++ b/cargo-insta/src/cli.rs @@ -644,11 +644,12 @@ fn test_run(mut cmd: TestCommand, color: ColorWhen) -> Result<(), Box cmd.force_update_snapshots = true; } } - - // --check always implies --no-force-pass as otherwise this command does not - // make a lot of sense. - if cmd.check { - cmd.no_force_pass = true + if cmd.no_force_pass { + cmd.check = true; + eprintln!( + "{}: `--no-force-pass` is deprecated. Please use --check to immediately raise an error on any non-matching snapshots.", + style("warning").bold().yellow() + ) } // the tool config can also indicate that --accept-unseen should be picked @@ -998,15 +999,6 @@ fn prepare_test_runner<'snapshot_ref>( } if !cmd.check { proc.env("INSTA_FORCE_PASS", "1"); - } else if !cmd.no_force_pass { - proc.env("INSTA_FORCE_PASS", "1"); - // If we're not running under cargo insta, raise a warning that this option - // is deprecated. (cargo insta still uses it when running under `--check`, - // but this will stop soon too) - eprintln!( - "{}: `--no-force-pass` is deprecated. Please use --check to immediately raise an error on any non-matching snapshots.", - style("warning").bold().yellow() - ); } proc.env( diff --git a/insta/src/snapshot.rs b/insta/src/snapshot.rs index 8086faa7..0130f546 100644 --- a/insta/src/snapshot.rs +++ b/insta/src/snapshot.rs @@ -385,7 +385,7 @@ impl Snapshot { } } } - elog!("A snapshot uses an old snapshot format; please update it to the new format with `cargo insta test --force-update-snapshots --accept`.\n\nSnapshot is at: {}", p.to_string_lossy()); + elog!("A snapshot uses a legacy snapshot format; please update it to the new format with `cargo insta test --force-update-snapshots --accept`.\n\nSnapshot is at: {}", p.to_string_lossy()); rv }; @@ -752,7 +752,7 @@ impl PartialEq for SnapshotContents { if this.matches_latest(other) { true } else if this.matches_legacy(other) { - elog!("{} {}\n{}",style("Snapshot passes but is a legacy format. Please run `cargo insta test --force-update-snapshots --accept` to update to a newer format.").yellow().bold(),"Snapshot contents:", this.to_string()); + elog!("{} {}\n{}",style("Snapshot test passes but the existing value is in a legacy format. Please run `cargo insta test --force-update-snapshots` to update to a newer format.").yellow().bold(),"Snapshot contents:", this.to_string()); true } else { false