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
|
#[macro_use]
extern crate trackable;
#[macro_use]
extern crate trackable_derive;
#[test]
fn derive_works() {
use trackable::error::{ErrorKind as TrackableErrorKind, ErrorKindExt, TrackableError};
#[derive(Debug, Clone, TrackableError)]
pub struct Error(TrackableError<ErrorKind>);
#[derive(Debug, Clone)]
pub enum ErrorKind {
Other,
}
impl TrackableErrorKind for ErrorKind {}
let error = track!(Error::from(ErrorKind::Other.cause("something wrong")));
let error = track!(error, "I passed here");
assert_eq!(
format!("\nError: {}", error).replace('\\', "/"),
r#"
Error: Other (cause; something wrong)
HISTORY:
[0] at tests/derive.rs:19
[1] at tests/derive.rs:20 -- I passed here
"#
);
}
#[test]
fn error_kind_attribute_works() {
use trackable::error::{ErrorKind as TrackableErrorKind, ErrorKindExt, TrackableError};
#[derive(Debug, Clone, TrackableError)]
#[trackable(error_kind = "Failed")]
pub struct Error(TrackableError<Failed>);
#[derive(Debug, Clone)]
pub struct Failed;
impl TrackableErrorKind for Failed {}
let error = track!(Error::from(Failed.cause("something wrong")));
let error = track!(error, "I passed here");
assert_eq!(
format!("\nError: {}", error).replace('\\', "/"),
r#"
Error: Failed (cause; something wrong)
HISTORY:
[0] at tests/derive.rs:44
[1] at tests/derive.rs:45 -- I passed here
"#
);
}
|