forked from assert-rs/assert_cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.rs
More file actions
67 lines (64 loc) · 1.87 KB
/
errors.rs
File metadata and controls
67 lines (64 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use output;
use std::ffi::OsString;
const ERROR_PREFIX: &'static str = "CLI assertion failed";
fn format_cmd(cmd: &[OsString]) -> String {
let result: Vec<String> = cmd.iter()
.map(|s| s.to_string_lossy().into_owned())
.collect();
result.join(" ")
}
error_chain! {
links {
Output(output::Error, output::ErrorKind);
}
foreign_links {
Io(::std::io::Error);
Fmt(::std::fmt::Error);
}
errors {
SpawnFailed(cmd: Vec<OsString>) {
description("Spawn failed")
display(
"{}: (command `{}` failed to run)",
ERROR_PREFIX,
format_cmd(cmd),
)
}
AssertionFailed(cmd: Vec<OsString>) {
description("Assertion failed")
display(
"{}: (command `{}` failed)",
ERROR_PREFIX,
format_cmd(cmd),
)
}
StatusMismatch(expected: bool, out: String, err: String) {
description("Wrong status")
display(
"Expected to {}\nstatus={}\nstdout=```{}```\nstderr=```{}```",
expected = if *expected { "succeed" } else { "fail" },
got = if *expected { "failed" } else { "succeeded" },
out = out,
err = err,
)
}
ExitCodeMismatch(
expected: Option<i32>,
got: Option<i32>,
out: String,
err: String
) {
description("Wrong exit code")
display(
"Expected exit code to be `{expected:?}`)\n\
exit code=`{code:?}`\n\
stdout=```{stdout}```\n\
stderr=```{stderr}```",
expected=expected,
code=got,
stdout=out,
stderr=err,
)
}
}
}