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

Small refactors #664

Merged
merged 1 commit into from
Oct 12, 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
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
Loading