Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ clap_complete_nushell = "4.6.0"
# will need regenerating.
clap-markdown = "=0.1.5"
clap_mangen = "0.2.25"
color-eyre = "0.6"
clru = "0.6.3"
criterion = "0.8.2"
ctor = "0.2"
crossterm = { version = "0.29", default-features = false, features = ["windows"] }
datatest-stable = "0.3.3"
digest = "0.10.7"
dunce = "1.0.5"
either = "1.15.0"
erased-serde = "0.4.10"
eyre = "0.6"
etcetera = "0.11.0"
futures = "0.3.32"
gix = { version = "0.80.0", default-features = false, features = [
Expand Down
3 changes: 3 additions & 0 deletions lib/testutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ readme = { workspace = true }
[dependencies]
async-trait = { workspace = true }
bstr = { workspace = true }
color-eyre = { workspace = true }
ctor = { workspace = true }
eyre = { workspace = true }
futures = { workspace = true }
gix = { workspace = true, features = [
"status",
Expand Down
20 changes: 20 additions & 0 deletions lib/testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ pub mod git;
pub mod proptest;
pub mod test_backend;

#[ctor::ctor]
fn init_color_eyre() {
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_"))
Copy link
Contributor

@ilyagr ilyagr Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice that color-eyre has filtering functionality! That could be very helpful.

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 RUST_BACKTRACE=full to get the full backtrace in the cases where this filters too much. (I haven't checked how easy that is to do).

As per my other message, I'm thinking of panic-s, not TestResult use-cases.

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%.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)

image

The filtering is especially useful with #[tokio::test]: the backtraces are much longer in that case—29 frames instead of just 7 with the #[test] for the same test failure. #[pollster::test] is a bit more at 9 frames.

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The 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 color_eyre later. So, I think that as long as COLORBT_SHOW_HIDDEN works, that's sufficient.

.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.
Expand Down