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
use crate::env::read_bool_env_var;
pub const OUT_EXT: &str = "out";
pub const EXP_EXT: &str = "exp";
pub const UPDATE_BASELINE: &str = "UPDATE_BASELINE";
pub const UPBL: &str = "UPBL";
pub const UB: &str = "UB";
pub const PRETTY: &str = "PRETTY";
pub const FILTER: &str = "FILTER";
pub fn read_env_update_baseline() -> bool {
read_bool_env_var(UPDATE_BASELINE) || read_bool_env_var(UPBL) || read_bool_env_var(UB)
}
pub fn add_update_baseline_fix(s: impl AsRef<str>) -> String {
format!(
"{}\n\
Run with `env {}=1` (or `env {}=1`) to save the current output as \
the new expected output",
s.as_ref(),
UB,
UPDATE_BASELINE
)
}
pub fn format_diff(expected: impl AsRef<str>, actual: impl AsRef<str>) -> String {
use difference::*;
let changeset = Changeset::new(expected.as_ref(), actual.as_ref(), "\n");
let mut ret = String::new();
for seq in changeset.diffs {
match &seq {
Difference::Same(x) => {
ret.push_str(x);
ret.push('\n');
}
Difference::Add(x) => {
ret.push_str("\x1B[92m");
ret.push_str(x);
ret.push_str("\x1B[0m");
ret.push('\n');
}
Difference::Rem(x) => {
ret.push_str("\x1B[91m");
ret.push_str(x);
ret.push_str("\x1B[0m");
ret.push('\n');
}
}
}
ret
}