use super::*;
#[test]
fn message_without_cause_is_unchanged() {
let failure: WorktreeCopyError = failure_with_cause("cli-git: could not inspect.", None);
assert_eq!(
failure,
WorktreeCopyError(String::from("cli-git: could not inspect."))
);
}
#[test]
fn cause_follows_message_with_separator() {
let cause: std::io::Error = std::io::Error::other("disk gone");
let failure: WorktreeCopyError =
failure_with_cause("cli-git: could not inspect.", Some(&cause));
assert_eq!(failure.0, "cli-git: could not inspect. Cause: disk gone");
}
#[test]
fn raw_failures_are_worded_only_once() {
let cause: std::io::Error = std::io::Error::other("boom");
let raw: WorktreeCopyError = raw_failure(&cause);
assert_eq!(raw.0, "boom");
assert!(is_raw_failure(&raw));
let worded: WorktreeCopyError = wrap_raw(raw, "cli-git: could not inspect.");
assert_eq!(worded.0, "cli-git: could not inspect. Cause: boom");
assert_eq!(wrap_raw(worded.clone(), "cli-git: other."), worded);
}
#[test]
fn lifecycle_uses_generic_sentence_for_raw_failures_only() {
let raw: WorktreeCopyError = raw_failure(&std::io::Error::other("boom"));
assert_eq!(
lifecycle_failure(raw).0,
"cli-git: automatic ignored-state worktree copy failed. Cause: boom"
);
let owned: WorktreeCopyError = WorktreeCopyError(String::from("cli-git: owned."));
assert_eq!(lifecycle_failure(owned.clone()), owned);
}