Skip to content

Commit

Permalink
test: Check report file
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 10, 2024
1 parent 01a60ca commit c85564f
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 1 deletion.
158 changes: 158 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/single-panic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ release = false
human-panic = { path = "../.." }

[dev-dependencies]
snapbox = { version = "0.6.4", features = ["cmd"] }
snapbox = { version = "0.6.4", features = ["cmd", "dir"] }
72 changes: 72 additions & 0 deletions tests/single-panic/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#[test]
#[cfg_attr(debug_assertions, ignore)]
fn release() {
let root = snapbox::dir::DirRoot::mutable_temp().unwrap();
let root_path = root.path().unwrap();

#[cfg(unix)]
let envs = [("TMPDIR", root_path)];
#[cfg(not(unix))]
let envs: [(&str, &str); 0] = [];

snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
.envs(envs)
.assert()
.stderr_eq(snapbox::str![[r#"
Well, this is embarrassing.
Expand All @@ -18,12 +27,58 @@ Thank you kindly!
"#]])
.code(101);

#[cfg(unix)]
{
let mut files = root_path
.read_dir()
.unwrap()
.map(|e| {
let e = e.unwrap();
let path = e.path();
let content = std::fs::read_to_string(&path);
(path, content)
})
.collect::<Vec<_>>();
assert_eq!(files.len(), 1, "{files:?}");
let (_, report) = files.pop().unwrap();
let report = report.unwrap();
snapbox::assert_data_eq!(
report,
snapbox::str![[r#"
"name" = "single-panic-test"
"operating_system" = "[..]"
"crate_version" = "0.1.0"
"explanation" = """
Panic occurred in file 'tests/single-panic/src/main.rs' at line [..]
"""
"cause" = "OMG EVERYTHING IS ON FIRE!!!"
"method" = "Panic"
"backtrace" = """
...
[..]"""
"#]]
);
}

root.close().unwrap();
}

#[test]
#[cfg_attr(not(debug_assertions), ignore)]
fn debug() {
let root = snapbox::dir::DirRoot::mutable_temp().unwrap();
let root_path = root.path().unwrap();

#[cfg(unix)]
let envs = [("TMPDIR", root_path)];
#[cfg(not(unix))]
let envs: [(&str, &str); 0] = [];

snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
.envs(envs)
.assert()
.stderr_eq(snapbox::str![[r#"
thread 'main' panicked at tests/single-panic/src/main.rs:7:5:
Expand All @@ -32,4 +87,21 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
"#]])
.code(101);

#[cfg(unix)]
{
let files = root_path
.read_dir()
.unwrap()
.map(|e| {
let e = e.unwrap();
let path = e.path();
let content = std::fs::read_to_string(&path);
(path, content)
})
.collect::<Vec<_>>();
assert!(files.is_empty(), "{files:?}");
}

root.close().unwrap();
}

0 comments on commit c85564f

Please sign in to comment.