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 20, 2023
1 parent 85c1562 commit 7bb9083
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 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
14 changes: 11 additions & 3 deletions eyre/tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#[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 eyre_root_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let mut config = ui_test::Config::cargo(eyre_root_dir);
let rust_backtrace_val = "1";
config
.program
.envs
.push(("RUST_BACKTRACE".into(), Some(rust_backtrace_val.into())));
config.mode = ui_test::Mode::Run { exit_code: 0 };
config.filter_files = vec!["ui_test".to_owned()];
ui_test::run_tests(config);

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

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

unused `Result` that must be used

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

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

unused `Result` that must be used

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

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

unused `Result` that must be used

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

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

unused `Result` that must be used

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

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

unused `Result` that must be used

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

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

unused `Result` that must be used

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

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

unused `Result` that must be used

Check warning on line 14 in eyre/tests/compiletest.rs

View workflow job for this annotation

GitHub Actions / Miri

unused `std::result::Result` that must be used
}
17 changes: 13 additions & 4 deletions eyre/tests/test_backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,29 @@ mod test_backtrace {
13: test_backtrace::test_backtrace::test_backtrace
";

use 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 (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, --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 (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 / 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 (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 (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 (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 (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 (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 (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 / 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 (windows-latest)

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]
// #[test]
// #[should_panic]
fn test_backtrace_simple() {

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

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 (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 (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 / 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 (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 (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 (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 (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 (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 (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 (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 / 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 (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 (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 (windows-latest)

function `test_backtrace_simple` is never used
high(FailFrame::Low).unwrap();
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]
// #[test]
fn test_backtrace() {

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

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 (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 (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 / 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 (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 (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 (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 (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 (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 / Miri

function `test_backtrace` is never used
/* FIXME: check that the backtrace actually happens here
* It's not trivial to compare the *whole* output,
Expand Down
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 7bb9083

Please sign in to comment.