mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-28 21:41:58 +00:00
fix: make theme test more lenient
The test now only considers our part of the backtrace, allowing for changes in rust std library to not break the test
This commit is contained in:
parent
eb26e0202f
commit
8ebc308a0a
@ -7,17 +7,17 @@ Error:
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
[96m ⋮ 5 frames hidden ⋮ [0m
|
||||
6: [91mtheme::get_error::create_report[0m[90m::h43540daddae98383[0m
|
||||
at [35m/home/freja/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m17[0m
|
||||
at [35m/home/username/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m17[0m
|
||||
7: [91mtheme::get_error::{{closure}}[0m[90m::h40bbef2f4cd93fab[0m
|
||||
at [35m/home/freja/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m26[0m
|
||||
at [35m/home/username/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m26[0m
|
||||
8: [32mcore::option::Option<T>::ok_or_else[0m[90m::h8aa47839ff49cfbe[0m
|
||||
at [35m/rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/option.rs[0m:[35m1087[0m
|
||||
9: [91mtheme::get_error[0m[90m::h78b5b4d52bfbbad0[0m
|
||||
at [35m/home/freja/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m26[0m
|
||||
at [35m/home/username/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m26[0m
|
||||
10: [91mtheme::test_error_backwards_compatibility[0m[90m::h9de398ce80defffa[0m
|
||||
at [35m/home/freja/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m45[0m
|
||||
at [35m/home/username/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m45[0m
|
||||
11: [91mtheme::test_error_backwards_compatibility::{{closure}}[0m[90m::hbe7b8ad2562c4dc4[0m
|
||||
at [35m/home/freja/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m43[0m
|
||||
at [35m/home/username/dev/rust/eyre/color-eyre/tests/theme.rs[0m:[35m43[0m
|
||||
12: [32mcore::ops::function::FnOnce::call_once[0m[90m::hfc715417a1b707c5[0m
|
||||
at [35m/rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs[0m:[35m248[0m
|
||||
13: [32mcore::ops::function::FnOnce::call_once[0m[90m::h9ee1367930602049[0m
|
||||
@ -43,4 +43,4 @@ Error:
|
||||
[96mSuggestion[0m: suggestion
|
||||
|
||||
Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
|
||||
Run with RUST_BACKTRACE=full to include source snippets.
|
||||
Run with RUST_BACKTRACE=full to include source snippets.
|
||||
|
@ -1,5 +1,5 @@
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.07s
|
||||
Running `/home/freja/dev/rust/eyre/target/debug/examples/theme_test_helper`
|
||||
Running `/home/username/dev/rust/eyre/target/debug/examples/theme_test_helper`
|
||||
[31mThe application panicked (crashed).[0m
|
||||
Message: [36m<non string panic payload>[0m
|
||||
Location: [35mcolor-eyre/examples/theme_test_helper.rs[0m:[35m38[0m
|
||||
@ -9,7 +9,7 @@ Location: [35mcolor-eyre/examples/theme_test_helper.rs[0m:[35m38[0m
|
||||
7: [32mstd::panic::panic_any[0m[90m::h4a05c03c4d0c389c[0m
|
||||
at [35m/rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs[0m:[35m61[0m
|
||||
8: [91mtheme_test_helper::main[0m[90m::hfc653b28cad3659d[0m
|
||||
at [35m/home/freja/dev/rust/eyre/color-eyre/examples/theme_test_helper.rs[0m:[35m38[0m
|
||||
at [35m/home/username/dev/rust/eyre/color-eyre/examples/theme_test_helper.rs[0m:[35m38[0m
|
||||
9: [32mcore::ops::function::FnOnce::call_once[0m[90m::hb0110cdf4417a5ed[0m
|
||||
at [35m/rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs[0m:[35m248[0m
|
||||
[96m ⋮ 16 frames hidden ⋮ [0m
|
||||
|
@ -150,9 +150,9 @@ fn test_backwards_compatibility(target: String, file_name: &str) {
|
||||
// `unwrap` should never fail with files generated by this function
|
||||
let control = String::from_utf8(fs::read(file_path).unwrap()).unwrap();
|
||||
|
||||
fn f(s: &str) -> (Vec<Output>, Vec<AnsiSequence>) {
|
||||
let all: Vec<_> = s.ansi_parse().collect();
|
||||
let ansi: Vec<_> = s
|
||||
fn split_ansi_output(input: &str) -> (Vec<Output>, Vec<AnsiSequence>) {
|
||||
let all: Vec<_> = input.ansi_parse().collect();
|
||||
let ansi: Vec<_> = input
|
||||
.ansi_parse()
|
||||
.filter_map(|x| {
|
||||
if let Output::Escape(ansi) = x {
|
||||
@ -165,8 +165,26 @@ fn test_backwards_compatibility(target: String, file_name: &str) {
|
||||
(all, ansi)
|
||||
}
|
||||
|
||||
let (_control_tokens, control_ansi) = f(&control);
|
||||
let (_target_tokens, target_ansi) = f(&target);
|
||||
fn normalize_backtrace(input: &str) -> String {
|
||||
input
|
||||
.lines()
|
||||
.take_while(|v| !v.contains("core::panic"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
let control = normalize_backtrace(&control);
|
||||
let target = normalize_backtrace(&target);
|
||||
let (_control_tokens, control_ansi) = split_ansi_output(&control);
|
||||
let (_target_tokens, target_ansi) = split_ansi_output(&target);
|
||||
|
||||
fn section(title: &str, content: impl AsRef<str>) -> String {
|
||||
format!(
|
||||
"{}\n{}",
|
||||
format!("-------- {title} --------").red(),
|
||||
content.as_ref()
|
||||
)
|
||||
}
|
||||
|
||||
// pretty_assertions::assert_eq!(target, control);
|
||||
let msg = [
|
||||
@ -175,23 +193,21 @@ fn test_backwards_compatibility(target: String, file_name: &str) {
|
||||
format!("{}", "\x1b[0m\n\nANSI escape sequences are not identical to control!".red()),
|
||||
// ^ `\x1b[0m` clears previous ANSI escape sequences
|
||||
|
||||
format!("{}", "CONTROL:".red()),
|
||||
format!("{}{}", "CONTROL STRING =\n".red(), &control),
|
||||
//format!("{}{:?}", "CONTROL DEBUG STRING =\n".red(), &control),
|
||||
//format!("{}{:?}", "CONTROL ANSI PARSER OUTPUT =\n".red(), &_control_tokens),
|
||||
//format!("{}{:?}", "CONTROL ANSI PARSER ANSI =\n".red(), &control_ansi),
|
||||
section("CONTROL STRING", &control),
|
||||
// section("CONTROL DEBUG STRING", format!("{control:?}")),
|
||||
// section("CONTROL ANSI PARSER OUTPUT", format!("{_control_tokens:?}")),
|
||||
// section("CONTROL ANSI PARSER ANSI", format!("{control_ansi:?}")),
|
||||
|
||||
format!("{}", "CURRENT:".red()),
|
||||
format!("{}{}", "CURRENT STRING =\n".red(), &target),
|
||||
//format!("{}{:?}", "CURRENT DEBUG STRING =\n".red(), &target),
|
||||
//format!("{}{:?}", "CURRENT ANSI PARSER OUTPUT =\n".red(), &_target_tokens),
|
||||
//format!("{}{:?}", "CURRENT ANSI PARSER ANSI =\n".red(), &target_ansi),
|
||||
section("CURRENT STRING", &target),
|
||||
// section("CURRENT DEBUG STRING", format!("{target:?}")),
|
||||
// section("CURRENT ANSI PARSER OUTPUT", format!("{_target_tokens:?}")),
|
||||
// section("CURRENT ANSI PARSER ANSI", format!("{target_ansi:?}")),
|
||||
|
||||
format!("{}", "See the src of this test for more information about the test and ways to include/exclude debugging information.\n\n".red()),
|
||||
|
||||
].join("\n\n");
|
||||
|
||||
assert_eq!(target_ansi, control_ansi, "{}", &msg);
|
||||
pretty_assertions::assert_eq!(target_ansi, control_ansi, "{}", &msg);
|
||||
|
||||
/*
|
||||
# Tips for debugging test failures
|
||||
|
Loading…
x
Reference in New Issue
Block a user