Skip to content

Commit 1f9ee0f

Browse files
authored
Only delete unreferenced snapshots after a successful test run (#440)
1 parent 0974fe8 commit 1f9ee0f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

cargo-insta/src/cli.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ struct TestCommand {
186186
/// Update all snapshots even if they are still matching.
187187
#[structopt(long)]
188188
force_update_snapshots: bool,
189-
/// Controls what happens with unreferenced snapshots.
189+
/// Handle unreferenced snapshots after a successful test run.
190190
#[structopt(long, default_value="ignore", possible_values=&["ignore", "warn", "reject", "delete", "auto"])]
191191
unreferenced: String,
192-
/// Delete unreferenced snapshots after the test run.
192+
/// Delete unreferenced snapshots after a successful test run.
193193
#[structopt(long, hidden = true)]
194194
delete_unreferenced_snapshots: bool,
195195
/// Filters to apply to the insta glob feature.
@@ -641,9 +641,12 @@ fn test_run(mut cmd: TestCommand, color: &str) -> Result<(), Box<dyn Error>> {
641641
return Err(QuietExit(1).into());
642642
}
643643

644-
// handle unreferenced snapshots if we were instructed to do so
645-
if let Some(ref path) = snapshot_ref_file {
646-
handle_unreferenced_snapshots(path.borrow(), &loc, unreferenced, &cmd.package[..])?;
644+
// handle unreferenced snapshots if we were instructed to do so and the
645+
// tests ran successfully
646+
if success {
647+
if let Some(ref path) = snapshot_ref_file {
648+
handle_unreferenced_snapshots(path.borrow(), &loc, unreferenced, &cmd.package[..])?;
649+
}
647650
}
648651

649652
if cmd.review || cmd.accept {

0 commit comments

Comments
 (0)