Skip to content

Commit

Permalink
Small refactors (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Oct 12, 2024
1 parent 4f16d70 commit a8b6cc2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
31 changes: 15 additions & 16 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,23 +832,22 @@ fn handle_unreferenced_snapshots(
UnreferencedSnapshots::Ignore => return Ok(()),
};

let mut files = HashSet::new();
match fs::read_to_string(snapshot_ref_path) {
Ok(s) => {
for line in s.lines() {
if let Ok(path) = fs::canonicalize(line) {
files.insert(path);
}
}
}
Err(err) => {
// if the file was not created, no test referenced
// snapshots.
if err.kind() != io::ErrorKind::NotFound {
return Err(err.into());
let files = fs::read_to_string(snapshot_ref_path)
.map(|s| {
s.lines()
.filter_map(|line| fs::canonicalize(line).ok())
.collect()
})
.or_else(|err| {
if err.kind() == io::ErrorKind::NotFound {
// if the file was not created, no test referenced
// snapshots (though we also check for this in the calling
// function, so maybe duplicative...)
Ok(HashSet::new())
} else {
Err(err)
}
}
}
})?;

let mut encountered_any = false;

Expand Down
2 changes: 1 addition & 1 deletion cargo-insta/tests/functional/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl TestProject {
format!("{} {}", style(&stdout_name).green(), line)
}))
.stderr(OutputFormatter(move |line| {
format!("{} {}", style(&stderr_name).red(), line)
format!("{} {}", style(&stderr_name).yellow(), line)
}));

command
Expand Down
2 changes: 1 addition & 1 deletion 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 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());
elog!("A snapshot uses a legacy snapshot format; please update it to the new format with `cargo insta test --force-update-snapshots --accept`.\nSnapshot is at: {}", p.to_string_lossy());
rv
};

Expand Down

0 comments on commit a8b6cc2

Please sign in to comment.