Skip to content

Commit 4545098

Browse files
committed
Add some integration tests
1 parent 0f116f3 commit 4545098

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/panic_handling.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extern crate stacker;
2+
3+
const RED_ZONE: usize = 100*1024; // 100k
4+
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
5+
6+
pub fn ensure_sufficient_stack<R, F: FnOnce() -> R + std::panic::UnwindSafe>(
7+
f: F
8+
) -> R {
9+
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
10+
}
11+
12+
#[inline(never)]
13+
fn recurse(n: usize) {
14+
let x = [42u8; 50000];
15+
if n == 0 {
16+
panic!("an inconvenient time");
17+
} else {
18+
ensure_sufficient_stack(|| recurse(n - 1));
19+
}
20+
drop(x);
21+
}
22+
23+
#[test]
24+
#[should_panic]
25+
fn foo() {
26+
recurse(10000);
27+
}

tests/simple.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extern crate stacker;
2+
3+
const RED_ZONE: usize = 100*1024; // 100k
4+
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
5+
6+
pub fn ensure_sufficient_stack<R, F: FnOnce() -> R + std::panic::UnwindSafe>(
7+
f: F
8+
) -> R {
9+
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
10+
}
11+
12+
#[inline(never)]
13+
fn recurse(n: usize) {
14+
let x = [42u8; 50000];
15+
if n != 0 {
16+
ensure_sufficient_stack(|| recurse(n - 1));
17+
}
18+
drop(x);
19+
}
20+
21+
#[test]
22+
fn foo() {
23+
recurse(10000);
24+
}

0 commit comments

Comments
 (0)