rust/library/std/src
Dylan DPC 302bf31826
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 }
```
2022-10-10 13:43:41 +05:30
..
backtrace Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
collections Make Hash{Set,Map}::with_hasher unstably const 2022-10-02 13:07:13 +01:00
env std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
error remove fn backtrace 2022-08-01 20:10:40 +00:00
f32 Semicolon after macro_rules definition. 2022-08-15 12:33:00 +02:00
f64 Semicolon after macro_rules definition. 2022-08-15 12:33:00 +02:00
ffi Guarantee try_reserve preserves the contents on error 2022-08-10 01:51:38 +09:00
fs Ignore hiberfil_sys test in CI 2022-07-18 15:06:07 +01:00
io Rollup merge of #102794 - dtolnay:termination, r=thomcc 2022-10-10 13:43:41 +05:30
net Simplify clippy fix. 2022-09-12 19:46:51 +02:00
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os Standard library OS support for Apple WatchOS 2022-09-30 11:25:38 +01:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path make many std tests work in Miri 2022-08-18 18:07:39 -04:00
personality Move personality functions to std 2022-08-23 16:12:58 +08:00
prelude Finish bumping stage0 2022-05-27 07:36:17 -04:00
process Add test for issue #95178 2022-03-23 05:33:44 +00:00
sync Auto merge of #99505 - joboet:futex_once, r=thomcc 2022-10-08 03:50:07 +00:00
sys Auto merge of #102850 - JohnTitor:rollup-lze1w03, r=JohnTitor 2022-10-09 18:15:26 +00:00
sys_common Auto merge of #93668 - SUPERCILEX:path_alloc, r=joshtriplett 2022-10-09 15:07:10 +00:00
thread Rollup merge of #102313 - anirudh24seven:update_sleep_ms_doc, r=Mark-Simulacrum 2022-10-02 03:16:38 +02:00
time make many std tests work in Miri 2022-08-18 18:07:39 -04:00
alloc.rs Forbid mixing System with sytem allocator calls 2022-09-03 16:47:12 -05:00
ascii.rs Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
backtrace.rs replace stabilization placeholders 2022-09-26 10:13:44 +02:00
env.rs env::temp_dir: fix a typo 2022-09-28 21:51:09 +02:00
error.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
f32.rs Improve primitive/std docs separation and headers 2022-08-20 16:50:29 -05:00
f64.rs Improve primitive/std docs separation and headers 2022-08-20 16:50:29 -05:00
fs.rs updated description of File struct in std::fs 2022-09-03 11:09:06 -07:00
keyword_docs.rs review feedback 2022-10-07 15:21:47 +02:00
lib.rs Remove empty core::lazy and std::lazy 2022-10-08 15:55:15 +02:00
macros.rs stdio: Document no support for writing to non-blocking stdio/stderr 2022-09-07 14:22:57 +01:00
num.rs Add Saturating type (based on Wrapping type) 2021-08-10 19:27:01 +02:00
panic.rs Adding backtrace off option for fuchsia targets 2022-09-14 23:54:40 +00:00
panicking.rs Update doc after renaming fn is_zero 2022-09-23 14:16:35 +02:00
path.rs Clarify Path::extension() semantics in docs abstract 2022-09-20 11:12:03 -05:00
personality.rs Move personality functions to std 2022-08-23 16:12:58 +08:00
primitive_docs.rs array docs - advertise how to get array from slice 2022-09-10 19:37:07 -07:00
process.rs Make tests capture the error printed by a Result return 2022-10-07 18:25:32 -07:00
rt.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
time.rs Support setting file accessed/modified timestamps 2022-07-15 02:54:06 -07:00