-
Notifications
You must be signed in to change notification settings - Fork 61
/
lib.rs
44 lines (34 loc) · 1014 Bytes
/
lib.rs
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
#![cfg(test)]
#![feature(error_generic_member_access, provide_any)]
use snafu::{prelude::*, IntoError};
#[test]
fn does_not_capture_a_backtrace_when_source_provides_a_backtrace() {
#[derive(Debug, Snafu)]
struct InnerError {
backtrace: snafu::Backtrace,
}
#[derive(Debug, Snafu)]
struct OuterError {
source: InnerError,
backtrace: Option<snafu::Backtrace>,
}
enable_backtrace_capture();
let e = OuterSnafu.into_error(InnerSnafu.build());
assert!(e.backtrace.is_none());
}
#[test]
fn does_capture_a_backtrace_when_source_does_not_provide_a_backtrace() {
#[derive(Debug, Snafu)]
struct InnerError;
#[derive(Debug, Snafu)]
struct OuterError {
source: InnerError,
backtrace: Option<snafu::Backtrace>,
}
enable_backtrace_capture();
let e = OuterSnafu.into_error(InnerSnafu.build());
assert!(e.backtrace.is_some());
}
fn enable_backtrace_capture() {
std::env::set_var("RUST_LIB_BACKTRACE", "1");
}