Skip to content

Commit

Permalink
Update Error tests with new request API
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaBluejay committed Aug 15, 2023
1 parent 073bb71 commit 166e901
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 183 deletions.
11 changes: 6 additions & 5 deletions impl/doc/error.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ Backtraces don't work though, because the `Backtrace` type is only available in
## Example usage

```rust
# #![cfg_attr(nightly, feature(error_generic_member_access, provide_any))]
# #![cfg_attr(nightly, feature(error_generic_member_access, error_in_core))]
// Nightly requires enabling these features:
// #![feature(error_generic_member_access, provide_any)]
// #![feature(error_generic_member_access, error_in_core)]
# #[cfg(not(nightly))] fn main() {}
# #[cfg(nightly)] fn main() {
# use std::{any, error::Error as _, backtrace::Backtrace};
# use core::error::{request_ref, request_value, Error as __};
# use std::backtrace::Backtrace;
#
# use derive_more::{Display, Error, From};

Expand Down Expand Up @@ -129,7 +130,7 @@ enum CompoundError {
}

assert!(Simple.source().is_none());
assert!(any::request_ref::<Backtrace>(&Simple).is_none());
assert!(request_ref::<Backtrace>(&Simple).is_none());
assert!(WithSource::default().source().is_some());
assert!(WithExplicitSource::default().source().is_some());
assert!(Tuple::default().source().is_some());
Expand All @@ -139,7 +140,7 @@ let with_source_and_backtrace = WithSourceAndBacktrace {
backtrace: Backtrace::capture(),
};
assert!(with_source_and_backtrace.source().is_some());
assert!(any::request_ref::<Backtrace>(&with_source_and_backtrace).is_some());
assert!(request_ref::<Backtrace>(&with_source_and_backtrace).is_some());

assert!(CompoundError::Simple.source().is_none());
assert!(CompoundError::from(Simple).source().is_some());
Expand Down
80 changes: 40 additions & 40 deletions tests/error/nightly/derives_for_enums_with_backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]

use std::any;
use core::error::{request_ref, request_value};

use super::*;

Expand Down Expand Up @@ -146,7 +146,7 @@ impl TestErr {
}

fn get_source_backtrace(&self) -> &Backtrace {
any::request_ref(match self {
request_ref(match self {
Self::NamedExplicitBacktraceFromSource { err }
| Self::NamedExplicitDifferentSourceAndBacktrace { err, .. }
| Self::NamedImplicitDifferentSourceAndBacktrace { err, .. }
Expand All @@ -163,14 +163,14 @@ type MyBacktrace = Backtrace;

#[test]
fn unit() {
assert!(any::request_ref::<Backtrace>(&TestErr::Unit).is_none());
assert!(request_ref::<Backtrace>(&TestErr::Unit).is_none());
}

#[test]
fn named_implicit_no_backtrace() {
let err = TestErr::NamedImplicitNoBacktrace { field: 0 };

assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
}

#[test]
Expand All @@ -180,7 +180,7 @@ fn named_implicit_backtrace_by_field_name() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

Expand All @@ -191,7 +191,7 @@ fn named_implicit_backtrace_by_field_type() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

Expand All @@ -202,7 +202,7 @@ fn named_explicit_no_backtrace_by_field_name() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
}

#[test]
Expand All @@ -212,7 +212,7 @@ fn named_explicit_no_backtrace_by_field_type() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
}

#[test]
Expand All @@ -222,7 +222,7 @@ fn named_explicit_backtrace() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

Expand All @@ -233,7 +233,7 @@ fn named_explicit_no_backtrace_redundant() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
}

#[test]
Expand All @@ -243,7 +243,7 @@ fn named_explicit_backtrace_by_field_name_redundant() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

Expand All @@ -254,7 +254,7 @@ fn named_explicit_backtrace_by_field_type_redundant() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

Expand All @@ -266,7 +266,7 @@ fn named_explicit_suppresses_implicit() {
field: 0,
};

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
assert_bt!(!=, err, .get_unused_backtrace);
}
Expand All @@ -280,8 +280,8 @@ fn named_implicit_no_backtrace_from_source() {
};

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(any::request_value::<i32>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
assert!(request_value::<i32>(&err).is_none());
}

#[test]
Expand All @@ -293,8 +293,8 @@ fn named_explicit_no_backtrace_from_source() {
};

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(any::request_value::<i32>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
assert!(request_value::<i32>(&err).is_none());
}

#[test]
Expand All @@ -306,8 +306,8 @@ fn named_explicit_backtrace_from_source() {
};

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_some());
assert_eq!(any::request_value::<i32>(&err), Some(42));
assert!(request_ref::<Backtrace>(&err).is_some());
assert_eq!(request_value::<i32>(&err), Some(42));
assert_bt!(==, err, .get_source_backtrace);
}

Expand All @@ -321,8 +321,8 @@ fn named_implicit_different_source_and_backtrace() {
};

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_some());
assert_eq!(any::request_value::<i32>(&err), Some(42));
assert!(request_ref::<Backtrace>(&err).is_some());
assert_eq!(request_value::<i32>(&err), Some(42));
assert_bt!(==, err, .get_stored_backtrace);
assert_bt!(!=, err, .get_source_backtrace);
}
Expand All @@ -337,8 +337,8 @@ fn named_explicit_different_source_and_backtrace() {
};

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_some());
assert_eq!(any::request_value::<i32>(&err), Some(42));
assert!(request_ref::<Backtrace>(&err).is_some());
assert_eq!(request_value::<i32>(&err), Some(42));
assert_bt!(==, err, .get_stored_backtrace);
assert_bt!(!=, err, .get_source_backtrace);
}
Expand All @@ -347,29 +347,29 @@ fn named_explicit_different_source_and_backtrace() {
fn unnamed_implicit_no_backtrace() {
let err = TestErr::UnnamedImplicitNoBacktrace(0, 0);

assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
}

#[test]
fn unnamed_implicit_backtrace() {
let err = TestErr::UnnamedImplicitBacktrace(Backtrace::force_capture(), 0, 0);

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

#[test]
fn unnamed_explicit_no_backtrace() {
let err = TestErr::UnnamedExplicitNoBacktrace(Backtrace::force_capture(), 0);

assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
}

#[test]
fn unnamed_explicit_backtrace() {
let err = TestErr::UnnamedExplicitBacktrace(Backtrace::force_capture(), 0, 0);

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

Expand All @@ -378,15 +378,15 @@ fn unnamed_explicit_no_backtrace_redundant() {
let err =
TestErr::UnnamedExplicitNoBacktraceRedundant(Backtrace::force_capture(), 0);

assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
}

#[test]
fn unnamed_explicit_backtrace_redundant() {
let err =
TestErr::UnnamedExplicitBacktraceRedundant(Backtrace::force_capture(), 0, 0);

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
}

Expand All @@ -398,7 +398,7 @@ fn unnamed_explicit_suppresses_implicit() {
0,
);

assert!(any::request_ref::<Backtrace>(&err).is_some());
assert!(request_ref::<Backtrace>(&err).is_some());
assert_bt!(==, err, .get_stored_backtrace);
assert_bt!(!=, err, .get_unused_backtrace);
}
Expand All @@ -410,8 +410,8 @@ fn unnamed_implicit_no_backtrace_from_source() {
});

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(any::request_value::<i32>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
assert!(request_value::<i32>(&err).is_none());
}

#[test]
Expand All @@ -421,8 +421,8 @@ fn unnamed_explicit_no_backtrace_from_source() {
});

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_none());
assert!(any::request_value::<i32>(&err).is_none());
assert!(request_ref::<Backtrace>(&err).is_none());
assert!(request_value::<i32>(&err).is_none());
}

#[test]
Expand All @@ -432,8 +432,8 @@ fn unnamed_explicit_backtrace_from_source() {
});

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_some());
assert_eq!(any::request_value::<i32>(&err), Some(42));
assert!(request_ref::<Backtrace>(&err).is_some());
assert_eq!(request_value::<i32>(&err), Some(42));
assert_bt!(==, err, .get_source_backtrace);
}

Expand All @@ -447,8 +447,8 @@ fn unnamed_implicit_different_source_and_backtrace() {
);

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_some());
assert_eq!(any::request_value::<i32>(&err), Some(42));
assert!(request_ref::<Backtrace>(&err).is_some());
assert_eq!(request_value::<i32>(&err), Some(42));
assert_bt!(==, err, .get_stored_backtrace);
assert_bt!(!=, err, .get_source_backtrace);
}
Expand All @@ -463,8 +463,8 @@ fn unnamed_explicit_different_source_and_backtrace() {
);

assert!(err.source().is_some());
assert!(any::request_ref::<Backtrace>(&err).is_some());
assert_eq!(any::request_value::<i32>(&err), Some(42));
assert!(request_ref::<Backtrace>(&err).is_some());
assert_eq!(request_value::<i32>(&err), Some(42));
assert_bt!(==, err, .get_stored_backtrace);
assert_bt!(!=, err, .get_source_backtrace);
}
Loading

0 comments on commit 166e901

Please sign in to comment.