Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression test println!() panic message on ErrorKind::BrokenPipe #108980

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/ui/process/println-with-broken-pipe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// run-pass
// check-run-results
// ignore-windows
// ignore-emscripten
// ignore-fuchsia
// ignore-horizon
// ignore-android
// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:LL:CC"

// Test what the error message looks like when `println!()` panics because of
// `std::io::ErrorKind::BrokenPipe`

#![feature(unix_sigpipe)]

use std::env;
use std::process::{Command, Stdio};

#[unix_sigpipe = "sig_ign"]
fn main() {
let mut args = env::args();
let me = args.next().unwrap();
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...cute.


if let Some(arg) = args.next() {
// More than enough iterations to fill any pipe buffer. Normally this
// loop will end with a panic more or less immediately.
for _ in 0..65536 * 64 {
println!("{arg}");
}
unreachable!("should have panicked because of BrokenPipe");
}

// Set up a pipeline with a short-lived consumer and wait for it to finish.
// This will produce the `println!()` panic message on stderr.
let mut producer = Command::new(&me)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extremely cute.

.arg("this line shall appear exactly once on stdout")
.env("RUST_BACKTRACE", "0")
.stdout(Stdio::piped())
.spawn()
.unwrap();
let mut consumer =
Command::new("head").arg("-n1").stdin(producer.stdout.take().unwrap()).spawn().unwrap();
consumer.wait().unwrap();
producer.wait().unwrap();
}
2 changes: 2 additions & 0 deletions tests/ui/process/println-with-broken-pipe.run.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:LL:CC
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 change: 1 addition & 0 deletions tests/ui/process/println-with-broken-pipe.run.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this line shall appear exactly once on stdout
Loading