-
Notifications
You must be signed in to change notification settings - Fork 978
tests: replace many .unwrap()s with ?s using eyre #9111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
465c748
b202110
dbdc038
c9b89b3
80ee629
e758f76
3b5a9a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,33 @@ pub mod git; | |
| pub mod proptest; | ||
| pub mod test_backend; | ||
|
|
||
| #[ctor::ctor] | ||
| fn init_color_eyre() { | ||
| // Enable backtrace capture by default in tests | ||
| if std::env::var("RUST_BACKTRACE").is_err() { | ||
| unsafe { | ||
| std::env::set_var("RUST_BACKTRACE", "1"); | ||
| } | ||
| } | ||
|
|
||
| drop( | ||
| color_eyre::config::HookBuilder::default() | ||
| .add_frame_filter(Box::new(|frames| { | ||
| frames.retain(|frame| { | ||
| frame | ||
| .name | ||
| .as_ref() | ||
| .map(|name| name.starts_with("jj_")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's nice that I don't know if this filter is correct for all use-cases, though. Ideally, there's be a message letting you know that you can set As per my other message, I'm thinking of Aside: My PR has an example of a more complicated-looking filter that's similar to default panic handler frame filtering logic, for comparison. I'm not sure that's necessarily better; this stricter filter could be good in 90% of the cases if there was a way to disable it in the other 10%.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an env var to set to disable the filtering, and it's displayed with the backtrace—see the screenshots in #9111 (comment)
The filtering is especially useful with I like the way the error chains are displayed, but eyre alone already displays them well. It may not be perfect every time, but it should work in most cases, produce much more compact and readable backtraces, also work with panics, and the filtering is easily deactivable when needed. I like it :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested that it works, that your code doesn't override it? It's fine if the filtering is not completely perfect, as long as it can be disabled; we can always fine-tune or even change our mind about using |
||
| .unwrap_or(false) | ||
| }); | ||
| })) | ||
| .install(), | ||
| ); | ||
| } | ||
|
|
||
| /// Convenient return type for test functions. | ||
| pub type TestResult<T = ()> = eyre::Result<T>; | ||
|
|
||
| pub const HERMETIC_GIT_CONFIGS: &[(&str, &str)] = &[ | ||
| // gitoxide uses "main" as the default branch name, whereas git uses "master". This also | ||
| // prevents git CLI from issuing the initial branch name advice. | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Probably no action needed) I have two worries about this:
ctorsupport this on all systems? AFAIU, it's only supposed to use libc. OTOH, if this passes CI, it probably works.