-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_output.rs
More file actions
125 lines (116 loc) · 3.97 KB
/
test_output.rs
File metadata and controls
125 lines (116 loc) · 3.97 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
mod common;
use common::project::TempRustProject;
use common::utils::assert_matches_regex;
const FAILING_TEST_CODE: &str = r#"
use hegel::generators;
fn main() {
hegel::hegel(|tc| {
let x = tc.draw(generators::integers::<i32>());
panic!("intentional failure: {}", x);
});
}
"#;
#[test]
fn test_failing_test_output() {
let output = TempRustProject::new()
.main_file(FAILING_TEST_CODE)
.expect_failure("intentional failure")
.cargo_run(&[]);
// For example:
// Draw 1: 0
// thread 'main' (1) panicked at src/main.rs:7:9:
// intentional failure: 0
// note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
assert_matches_regex(
&output.stderr,
concat!(
r"Draw 1: -?\d+\n",
r"thread '.*' \(\d+\) panicked at src/main\.rs:\d+:\d+:\n",
r"intentional failure: -?\d+",
),
);
}
#[test]
fn test_failing_test_output_with_backtrace() {
let output = TempRustProject::new()
.main_file(FAILING_TEST_CODE)
.env("RUST_BACKTRACE", "1")
.expect_failure("intentional failure")
.cargo_run(&[]);
// Rust >= 1.92 uses {closure#0}, older stable uses {{closure}}
let closure_name = r"(\{closure#0\}|\{\{closure\}\})";
// For example:
// Draw 1: 0
// thread 'main' (1) panicked at src/main.rs:7:9:
// intentional failure: 0
// stack backtrace:
// 0: __rustc::rust_begin_unwind
// 1: core::panicking::panic_fmt
// 2: temp_hegel_test_N::main::{{closure}}
// ...
// N: hegel::runner::handle_connection
// ...
// M: temp_hegel_test_N::main
// ...
// note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
assert_matches_regex(
&output.stderr,
&format!(
concat!(
r"(?s)",
r"Draw 1: -?\d+\n",
r"thread 'main' \(\d+\) panicked at src/main\.rs:\d+:\d+:\n",
r"intentional failure: -?\d+\n",
r"stack backtrace:\n",
r"\s+0: .*\n", // frame 0: panic machinery
r".*",
r"\s+1: core::panicking::panic_fmt\n", // frame 1: panic_fmt
r".*",
r"\s+2: temp_hegel_test_\d+::main::{closure_name}\n", // frame 2: user's closure
r".*",
r"hegel::runner::", // hegel internals appear
r".*",
r"temp_hegel_test_\d+::main\n", // user's main (not closure)
r".*",
r"note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace\.",
),
closure_name = closure_name,
),
);
}
#[test]
fn test_failing_test_output_with_full_backtrace() {
let output = TempRustProject::new()
.main_file(FAILING_TEST_CODE)
.env("RUST_BACKTRACE", "full")
.expect_failure("intentional failure")
.cargo_run(&[]);
// Rust >= 1.92 uses {closure#0}, older stable uses {{closure}}
let closure_name = r"(\{closure#0\}|\{\{closure\}\})";
assert_matches_regex(
&output.stderr,
&format!(
concat!(
r"(?s)",
r"Draw 1: -?\d+\n",
r"thread 'main' \(\d+\) panicked at src/main\.rs:\d+:\d+:\n",
r"intentional failure: -?\d+\n",
r"stack backtrace:\n",
r"\s+0: .*\n", // starts at frame 0
r".*",
r"temp_hegel_test_\d+::main::{closure_name}", // user's closure
r".*",
r"hegel::runner::", // hegel internals
r".*",
r"temp_hegel_test_\d+::main\n", // user's main
r".*$",
),
closure_name = closure_name,
),
);
assert!(
!output.stderr.contains("Some details are omitted"),
"Actual: {}",
output.stderr
);
}