Skip to content

Commit 539d6e0

Browse files
committed
test: Verify CI behavior
1 parent 5842930 commit 539d6e0

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

tests/custom-panic/tests/integration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#[cfg_attr(debug_assertions, ignore)]
33
fn release() {
44
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("custom-panic-test"))
5+
.env_remove("CI")
56
.assert()
67
.stderr_eq(snapbox::str![[r#"
78
Well, this is embarrassing.
@@ -29,6 +30,7 @@ Thank you kindly!
2930
#[cfg_attr(not(debug_assertions), ignore)]
3031
fn debug() {
3132
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("custom-panic-test"))
33+
.env_remove("CI")
3234
.assert()
3335
.stderr_eq(snapbox::str![[r#"
3436

tests/single-panic/tests/integration.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn release() {
1111

1212
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
1313
.envs(envs)
14+
.env_remove("CI")
1415
.assert()
1516
.stderr_eq(snapbox::str![[r#"
1617
Well, this is embarrassing.
@@ -78,6 +79,7 @@ fn release_with_backtraces() {
7879

7980
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
8081
.envs(envs)
82+
.env_remove("CI")
8183
.env("RUST_BACKTRACE", "1")
8284
.assert()
8385
.stderr_eq(snapbox::str![[r#"
@@ -109,6 +111,74 @@ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose bac
109111
root.close().unwrap();
110112
}
111113

114+
#[test]
115+
#[cfg_attr(debug_assertions, ignore)]
116+
fn release_with_ci() {
117+
let root = snapbox::dir::DirRoot::mutable_temp().unwrap();
118+
let root_path = root.path().unwrap();
119+
120+
#[cfg(unix)]
121+
let envs = [("TMPDIR", root_path)];
122+
#[cfg(not(unix))]
123+
let envs: [(&str, &str); 0] = [];
124+
125+
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
126+
.envs(envs)
127+
.env("CI", "1")
128+
.assert()
129+
.stderr_eq(snapbox::str![[r#"
130+
Well, this is embarrassing.
131+
132+
single-panic-test had a problem and crashed. To help us diagnose the problem you can send us a crash report.
133+
134+
We have generated a report file at "[..].toml". Submit an issue or email with the subject of "single-panic-test Crash Report" and include the report as an attachment.
135+
136+
- Authors: Human Panic Authors <human-panic-crate@example.com>
137+
138+
We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.
139+
140+
Thank you kindly!
141+
142+
"#]])
143+
.code(101);
144+
145+
#[cfg(unix)]
146+
{
147+
let mut files = root_path
148+
.read_dir()
149+
.unwrap()
150+
.map(|e| {
151+
let e = e.unwrap();
152+
let path = e.path();
153+
let content = std::fs::read_to_string(&path);
154+
(path, content)
155+
})
156+
.collect::<Vec<_>>();
157+
assert_eq!(files.len(), 1, "{files:?}");
158+
let (_, report) = files.pop().unwrap();
159+
let report = report.unwrap();
160+
snapbox::assert_data_eq!(
161+
report,
162+
snapbox::str![[r#"
163+
name = "single-panic-test"
164+
operating_system = "[..]"
165+
crate_version = "0.1.0"
166+
explanation = """
167+
Panic occurred in file 'tests/single-panic/src/main.rs' at line [..]
168+
"""
169+
cause = "OMG EVERYTHING IS ON FIRE!!!"
170+
method = "Panic"
171+
backtrace = """
172+
...
173+
"""
174+
175+
"#]]
176+
);
177+
}
178+
179+
root.close().unwrap();
180+
}
181+
112182
#[test]
113183
#[cfg_attr(not(debug_assertions), ignore)]
114184
fn debug() {
@@ -122,6 +192,7 @@ fn debug() {
122192

123193
snapbox::cmd::Command::new(snapbox::cmd::cargo_bin!("single-panic-test"))
124194
.envs(envs)
195+
.env_remove("CI")
125196
.assert()
126197
.stderr_eq(snapbox::str![[r#"
127198

0 commit comments

Comments
 (0)