Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[broken test] Trying to test on backtrace output
Browse files Browse the repository at this point in the history
thenorili committed Nov 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 85c1562 commit 7bb9083
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
@@ -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"] }
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);
}
17 changes: 13 additions & 4 deletions eyre/tests/test_backtrace.rs
Original file line number Diff line number Diff line change
@@ -48,20 +48,29 @@ mod test_backtrace {
13: test_backtrace::test_backtrace::test_backtrace
";

use 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() {
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() {
/* FIXME: check that the backtrace actually happens here
* It's not trivial to compare the *whole* output,
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.