about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-10-10 13:43:41 +0530
committerGitHub <noreply@github.com>2022-10-10 13:43:41 +0530
commit302bf31826cdbbbe9a8ed9e0c4c7149d9010bfdd (patch)
tree990e2de1a6a4f332c0197341b7e734e0f583b865 /compiler/rustc_llvm/llvm-wrapper
parent58d533dfc12f9ecd2bf1afa2837b6221a8ddbfdf (diff)
parent293f662ca94d6f1eac749da55f5ff924c87fd1d5 (diff)
downloadrust-302bf31826cdbbbe9a8ed9e0c4c7149d9010bfdd.tar.gz
rust-302bf31826cdbbbe9a8ed9e0c4c7149d9010bfdd.zip
Rollup merge of #102794 - dtolnay:termination, r=thomcc
Make tests capture the error printed by a Result return

An error returned by tests previously would get written directly to stderr, instead of to the capture buffer set up by the test harness. This PR makes it write to the capture buffer so that it can be integrated as part of the test output by build tools such as `buck test`, since being able to read the error message returned by a test is pretty critical to debugging why the test failed.

<br>

**Before:**

```rust
// tests/test.rs

#[test]
fn test() -> Result<(), &'static str> {
    println!("STDOUT");
    eprintln!("STDERR");
    Err("RESULT")
}
```

```console
$ cargo build --test test
$ target/debug/deps/test-???????????????? -Z unstable-options --format=json
{ "type": "suite", "event": "started", "test_count": 1 }
{ "type": "test", "event": "started", "name": "test" }
Error: "RESULT"
{ "type": "test", "name": "test", "event": "failed", "stdout": "STDOUT\nSTDERR\n" }
{ "type": "suite", "event": "failed", "passed": 0, "failed": 1, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.00040313 }
```

**After:**

```console
$ target/debug/deps/test-???????????????? -Z unstable-options --format=json
{ "type": "suite", "event": "started", "test_count": 1 }
{ "type": "test", "event": "started", "name": "test" }
{ "type": "test", "name": "test", "event": "failed", "stdout": "STDOUT\nSTDERR\nError: \"RESULT\"" }
{ "type": "suite", "event": "failed", "passed": 0, "failed": 1, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.000261894 }
```
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper')
0 files changed, 0 insertions, 0 deletions