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

Better deprecation warning for --no-force-pass #643

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 6 additions & 14 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,12 @@ fn test_run(mut cmd: TestCommand, color: ColorWhen) -> Result<(), Box<dyn Error>
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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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
Expand Down
Loading