Skip to content

Commit

Permalink
[broken test] Trying to test on backtrace output
Browse files Browse the repository at this point in the history
  • Loading branch information
thenorili committed Nov 26, 2023
1 parent 7603e3c commit 29d17b5
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 4 deletions.
2 changes: 1 addition & 1 deletion eyre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pyo3 = { version = "0.20", optional = true, default-features = false }
futures = { version = "0.3", default-features = false }
rustversion = "1.0"
thiserror = "1.0"
trybuild = { version = "1.0.19", features = ["diff"] }
ui_test = "0.21.0"
backtrace = "0.3.46"
anyhow = "1.0.28"
syn = { version = "2.0", features = ["full"] }
Expand Down
18 changes: 15 additions & 3 deletions eyre/tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#[rustversion::attr(not(nightly), ignore)]
#[cfg_attr(not(backtrace), ignore)]
#[cfg_attr(miri, ignore)]
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
let mut test_dir = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
test_dir.push("tests");
test_dir.push("ui");
let rust_backtrace_val = "1";
let mut config = ui_test::Config {
mode: ui_test::Mode::Run { exit_code: 0 },
filter_files: vec!["ui_test".to_owned()],

..ui_test::Config::cargo(test_dir)
};
config.program.args = vec!["run".into()];
config.program.envs = vec![("RUST_BACKTRACE".into(), Some(rust_backtrace_val.into()))];

let _ = ui_test::run_tests(config);
}
117 changes: 117 additions & 0 deletions eyre/tests/test_backtrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
mod test_backtrace {
use eyre::{eyre, Report, WrapErr};

#[allow(unused_variables)]
#[allow(dead_code)]
enum FailFrame {
None,
Low,
Med,
High,
}

fn low(frame: FailFrame) -> Result<(), Report> {

Check failure on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `low` is never used
let e: Report = eyre!("This program's goodness is suspect!");
if let FailFrame::Low = frame {
Err::<(), Report>(e).wrap_err("The low-level code has failed!")
} else {
Ok(())
}
}

fn med(frame: FailFrame) -> Result<(), Report> {

Check failure on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `med` is never used
let e: Report = eyre!("This program's goodness is suspect!");
if let FailFrame::Med = frame {
Err(e).wrap_err("The low-level code has failed!")
} else {
low(frame)
}
}
fn high(frame: FailFrame) -> Result<(), Report> {

Check failure on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `high` is never used
let e: Report = eyre!("This program's goodness is suspect!");
if let FailFrame::High = frame {
Err(e).wrap_err("The low-level code has failed!")
} else {
med(frame)
}
}

use std::panic;

static BACKTRACE_SNIPPET_HIGH: &str = "

Check failure on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

static `BACKTRACE_SNIPPET_HIGH` is never used
10: test_backtrace::test_backtrace::low
at .\\tests\\test_backtrace.rs:14
11: test_backtrace::test_backtrace::med
at .\\tests\\test_backtrace.rs:27
12: test_backtrace::test_backtrace::high
at .\\tests\\test_backtrace.rs:35
13: test_backtrace::test_backtrace::test_backtrace
";

use std::backtrace::Backtrace;

Check failure on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

unused import: `std::backtrace::Backtrace`
use std::sync::{Arc, Mutex};

/* This test does produce a backtrace for panic or error with the standard panic hook,
* but I'm at a loss for how to capture the backtrace and compare it to a snippet.
*/
#[cfg_attr(not(backtrace), ignore)]
// #[test]
// #[should_panic]
fn test_backtrace_simple() {

Check failure on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `test_backtrace_simple` is never used
let report = high(FailFrame::Low).expect_err("Must be error");
let handler: &eyre::DefaultHandler = report.handler().downcast_ref().unwrap();
eprintln!("{:?}", handler);
// let backtrace: Backtrace = handler.backtrace.unwrap();
// let
/*
let backtrace: Option<Backtrace> = handler.backtrace;
assert!(backtrace.is_some());
*/
}

#[cfg_attr(not(backtrace), ignore)]
// #[test]
fn test_backtrace() {

Check failure on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `test_backtrace` is never used
/* FIXME: check that the backtrace actually happens here
* It's not trivial to compare the *whole* output,
* but we could somehow grep the output for 'stack_backtrace',
* maybe check for this string... though including line numbers is problematic,
* and the frames could change if core changes.
*
*/

let global_buffer = Arc::new(Mutex::new(String::new()));
let old_hook = panic::take_hook();
panic::set_hook({
/* fixme: this panic hook is not working ;(
*/
let global_buffer = global_buffer.clone();
Box::new(move |info| {
let mut global_buffer = global_buffer.lock().unwrap();

if let Some(s) = info.payload().downcast_ref::<&str>() {
println!("PANIC: {}", *s);
*global_buffer = (*s).to_string()
} else {
// panic!("help!");
}
})
});

panic::catch_unwind(|| {
high(FailFrame::Low).unwrap(); //.unwrap_or(println!("test"));
})
.expect_err("Backtrace test did not panic.");
let binding = global_buffer.lock().unwrap();
let panic_output = binding.clone();
panic::set_hook(old_hook);
if !panic_output.contains(BACKTRACE_SNIPPET_HIGH) {
println!("Backtrace test fail.");
println!("Expected output to contain:");
println!("{}", BACKTRACE_SNIPPET_HIGH);
println!("Instead, outputted:");
println!("{}", panic_output);
panic!();
}
}
}
14 changes: 14 additions & 0 deletions eyre/tests/ui/ui_test_backtrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use eyre::Report;

fn fail(fail: bool) -> Result<(), Report> {
let e: Report = eyre!("Internal error message");
if fail {
Err(e).wrap_err("External error message")
} else {
Ok(())
}
}

fn main() {
fail(true);
}
1 change: 1 addition & 0 deletions eyre/tests/ui/ui_test_backtrace.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error: embedded manifest `$DIR/ui_test_backtrace.rs` requires `-Zscript`

0 comments on commit 29d17b5

Please sign in to comment.