use super::{FailureKind, SaveFailure, copy_failed_text};
fn failure(kind: FailureKind, subject: &str, reason: &str) -> SaveFailure {
return SaveFailure { subject: String::from(subject), reason: String::from(reason), kind };
}
#[test]
fn every_failure_names_the_path_the_reason_and_what_to_do() {
for (kind, subject, reason, advice) in [
(FailureKind::Io, "a.rs", "No space left on device", "Free the space"),
(FailureKind::Ancestor, "dir", "is a symbolic link", "Move `dir` out of the way"),
(FailureKind::Changed, "a.rs", "changed while it was copied", "Run it again once nothing is writing to the file"),
] {
let text: String = copy_failed_text(&failure(kind, subject, reason));
assert!(text.contains(subject) && text.contains(reason), "{kind:?}: {text}");
assert!(text.contains(advice), "{kind:?}: {text}");
assert!(text.contains("nothing was changed") && text.contains("--no-enforce-worktree"), "{kind:?}: {text}");
}
}