Skip to content

Commit ba532d2

Browse files
committed
test: Check report file
1 parent 01a60ca commit ba532d2

File tree

3 files changed

+232
-1
lines changed

3 files changed

+232
-1
lines changed

Cargo.lock

+158
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/single-panic/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ release = false
1212
human-panic = { path = "../.." }
1313

1414
[dev-dependencies]
15-
snapbox = { version = "0.6.4", features = ["cmd"] }
15+
snapbox = { version = "0.6.4", features = ["cmd", "dir"] }

tests/single-panic/tests/integration.rs

+73
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#[test]
22
#[cfg_attr(debug_assertions, ignore)]
33
fn release() {
4+
let root = snapbox::dir::DirRoot::mutable_temp().unwrap();
5+
let root_path = root.path().unwrap();
6+
7+
#[cfg(unix)]
8+
let envs = [("TMPDIR", root_path)];
9+
#[cfg(not(unix))]
10+
let envs: [(&str, &str); 0] = [];
11+
412
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
13+
.envs(envs)
514
.assert()
615
.stderr_eq(snapbox::str![[r#"
716
Well, this is embarrassing.
@@ -18,12 +27,59 @@ Thank you kindly!
1827
1928
"#]])
2029
.code(101);
30+
31+
#[cfg(unix)]
32+
{
33+
let mut files = root_path
34+
.read_dir()
35+
.unwrap()
36+
.map(|e| {
37+
let e = e.unwrap();
38+
let path = e.path();
39+
let content = std::fs::read_to_string(&path);
40+
(path, content)
41+
})
42+
.collect::<Vec<_>>();
43+
assert_eq!(files.len(), 1, "{files:?}");
44+
let (_, report) = files.pop().unwrap();
45+
let report = report.unwrap();
46+
snapbox::assert_data_eq!(
47+
report,
48+
snapbox::str![[r#"
49+
"name" = "single-panic-test"
50+
"operating_system" = "[..]"
51+
"crate_version" = "0.1.0"
52+
"explanation" = """
53+
Panic occurred in file 'tests/single-panic/src/main.rs' at line [..]
54+
"""
55+
"cause" = "OMG EVERYTHING IS ON FIRE!!!"
56+
"method" = "Panic"
57+
"backtrace" = """
58+
59+
0: [..]
60+
...
61+
8: [..]"""
62+
63+
"#]]
64+
);
65+
}
66+
67+
root.close().unwrap();
2168
}
2269

2370
#[test]
2471
#[cfg_attr(not(debug_assertions), ignore)]
2572
fn debug() {
73+
let root = snapbox::dir::DirRoot::mutable_temp().unwrap();
74+
let root_path = root.path().unwrap();
75+
76+
#[cfg(unix)]
77+
let envs = [("TMPDIR", root_path)];
78+
#[cfg(not(unix))]
79+
let envs: [(&str, &str); 0] = [];
80+
2681
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
82+
.envs(envs)
2783
.assert()
2884
.stderr_eq(snapbox::str![[r#"
2985
thread 'main' panicked at tests/single-panic/src/main.rs:7:5:
@@ -32,4 +88,21 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3288
3389
"#]])
3490
.code(101);
91+
92+
#[cfg(unix)]
93+
{
94+
let files = root_path
95+
.read_dir()
96+
.unwrap()
97+
.map(|e| {
98+
let e = e.unwrap();
99+
let path = e.path();
100+
let content = std::fs::read_to_string(&path);
101+
(path, content)
102+
})
103+
.collect::<Vec<_>>();
104+
assert!(files.is_empty(), "{files:?}");
105+
}
106+
107+
root.close().unwrap();
35108
}

0 commit comments

Comments
 (0)