-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panics and pretty_assert not outputting stdout
This commit fixes assay so that it actually uses the stdout from the spawned subprocess. Up to this point panics would cause tests to fail, however, it did not panic with the stdout of that subprocess. It would instead just print out the panic message from the callsite in the macro. To rectify this we now install a custom panic hook that will use the default if a special header is not passed into a panic message. In the replaced hook though we print out the output of the panic from the spawned subprocess now. With this we actually now show the proper output to the caller, almost as if we never spawned a subprocess. We now also have a way to test these by using one test to spawn broken tests which use the assay macro, but are ignored otherwise. This way we can test bad tests or failure cases and check that the output is what we expect!
- Loading branch information
Showing
5 changed files
with
143 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use assay::assay; | ||
use std::process::Command; | ||
|
||
#[assay(ignore)] | ||
fn assert_eq() { | ||
assert_eq!(1, 5); | ||
} | ||
|
||
#[assay(ignore)] | ||
fn assert_ne() { | ||
assert_ne!(["foo", "bar"], ["foo", "bar"]); | ||
} | ||
|
||
#[assay(ignore)] | ||
fn assert_eq_sorted() { | ||
assert_eq_sorted!([1, 3, 2], [1, 2, 4]); | ||
} | ||
|
||
#[test] | ||
fn pretty_assertions() { | ||
let output = Command::new("cargo") | ||
.args(["test", "--workspace", "--", "--ignored", "assert"]) | ||
.output() | ||
.unwrap(); | ||
let assert_tests = String::from_utf8(output.stdout).unwrap(); | ||
|
||
if assert_tests.contains( | ||
"---- assert_eq_sorted stdout ---- | ||
thread 'assert_eq_sorted' panicked at tests/pretty_assert.rs:16:3: | ||
assertion failed: `(left == right)` | ||
Diff < left / right > : | ||
[ | ||
1, | ||
< 3, | ||
2, | ||
> 4, | ||
]", | ||
) && assert_tests.contains( | ||
"---- assert_eq stdout ---- | ||
thread 'assert_eq' panicked at tests/pretty_assert.rs:6:3: | ||
assertion failed: `(left == right)` | ||
Diff < left / right > : | ||
<1 | ||
>5", | ||
) && assert_tests.contains( | ||
" | ||
---- assert_ne stdout ---- | ||
thread 'assert_ne' panicked at tests/pretty_assert.rs:11:3: | ||
assertion failed: `(left != right)` | ||
Both sides: | ||
[ | ||
\"foo\", | ||
\"bar\", | ||
]", | ||
) && assert_tests.contains( | ||
"failures: | ||
assert_eq | ||
assert_eq_sorted | ||
assert_ne | ||
test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 1 filtered out", | ||
) { | ||
panic!( | ||
"Unexpected output for assertions.\n\nOutput:\n{}", | ||
assert_tests | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters