Skip to content

Commit

Permalink
fix: remove anyhow feature flag from OptionExt location test (#148)
Browse files Browse the repository at this point in the history
# 1. Clarify trait usage in location test


[`8522f02`](8522f02)

Both `WrapErr` and `ContextCompat` expose `anyhow` compatibility
methods.

- `ContextCompat` is completely feature gated behind the `anyhow` flag.

- `WrapErr`, on the other hand, feature-gates individual functions
behind the `anyhow` flag.

This has led to [confusion][confusion] in the past.

This change moves the `use eyre::WrapErr` statement from the top of the
module into each individual test, as [identically named
functions](#149) (`wrap_err.*`)
are exposed both by `WrapErr` and `ContextCompat`.

With `use eyre::WrapErr` moved directly into the tests, it becomes clear
which trait-provided `fn` is being called.

[confusion]:
#138 (comment)

# 2. Remove `anyhow` feature flag from `OptionExt` location test 


[`68744f1`](68744f1)

This bug was introduced (by me) in
34bd1d9#diff-1ff47dac6cf55e34ff587968c5b1f1ec6b6ae39d2668a66ecba3633163a21fc5R86
- partly due to the confusion fixed with the above commit.

Fixes #147
  • Loading branch information
LeoniePhiline committed Mar 14, 2024
1 parent e570151 commit 75beaae
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions eyre/tests/test_location.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::panic::Location;

use eyre::WrapErr;

struct LocationHandler {
actual: Option<&'static str>,
expected: &'static str,
Expand Down Expand Up @@ -46,6 +44,7 @@ fn test_wrap_err() {
Box::new(LocationHandler::new(expected_location))
}));

use eyre::WrapErr;
let err = read_path("totally_fake_path")
.wrap_err("oopsie")
.unwrap_err();
Expand Down Expand Up @@ -75,6 +74,7 @@ fn test_wrap_err_with() {
Box::new(LocationHandler::new(expected_location))
}));

use eyre::WrapErr;
let err = read_path("totally_fake_path")
.wrap_err_with(|| "oopsie")
.unwrap_err();
Expand All @@ -83,7 +83,6 @@ fn test_wrap_err_with() {
println!("{:?}", err);
}

#[cfg(feature = "anyhow")]
#[test]
fn test_option_ok_or_eyre() {
let _ = eyre::set_hook(Box::new(|_e| {
Expand All @@ -106,6 +105,7 @@ fn test_context() {
Box::new(LocationHandler::new(expected_location))
}));

use eyre::WrapErr;
let err = read_path("totally_fake_path")
.context("oopsie")
.unwrap_err();
Expand All @@ -122,6 +122,7 @@ fn test_with_context() {
Box::new(LocationHandler::new(expected_location))
}));

use eyre::WrapErr;
let err = read_path("totally_fake_path")
.with_context(|| "oopsie")
.unwrap_err();
Expand Down

0 comments on commit 75beaae

Please sign in to comment.