Open
Description
Problem
Hi there. In certain cases when failing a test run with cargo, I need to display a custom error message.
There doesn't seem to be a way to do this without displaying the whole panic boilerplate. For various reasons I'm running with RUST_BACKTRACE=1
, so this also displays the full backtrace and makes the custom error very hard to find (especially in CI).
Steps
- Write this test:
#[test]
fn foo () -> Result<(), String> {
Err("aaa!!!".to_owned())
}
- Get this output:
running 1 test
test foo ... FAILED
failures:
---- foo stdout ----
Error: "aaa!!!"
thread 'foo' panicked at 'assertion failed: `(left == right)`
left: `1`,
right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/test/src/lib.rs:193:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
foo
- I would really like to get this output instead:
running 1 test
test foo ... FAILED
failures:
---- foo stdout ----
aaa!!!
failures:
foo
Output of cargo version
:
cargo 1.54.0 (5ae8d74b3 2021-06-22)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status