From d15e762a9032dcf246cf14c1bb5d35edca5b520d Mon Sep 17 00:00:00 2001 From: Christopher Dryden Date: Thu, 12 Feb 2026 12:01:05 +0000 Subject: [PATCH] date,comm,tty: add integration tests for write error handling --- tests/by-util/test_comm.rs | 15 +++++++++++++++ tests/by-util/test_date.rs | 12 ++++++++++++ tests/by-util/test_tty.rs | 8 ++++++++ 3 files changed, 35 insertions(+) diff --git a/tests/by-util/test_comm.rs b/tests/by-util/test_comm.rs index e314cfaf1..500899a20 100644 --- a/tests/by-util/test_comm.rs +++ b/tests/by-util/test_comm.rs @@ -727,3 +727,18 @@ fn test_read_error() { .fails() .stderr_contains("comm: /proc/self/mem: Input/output error"); } + +#[test] +#[cfg(unix)] +fn test_comm_write_error_dev_full() { + use std::fs::OpenOptions; + let scene = TestScenario::new(util_name!()); + scene.fixtures.write("a", "a\n"); + let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap(); + scene + .ucmd() + .args(&["a", "a"]) + .set_stdout(dev_full) + .fails() + .stderr_contains("No space left on device"); +} diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index 7a5625a01..11d42b9c5 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -2066,3 +2066,15 @@ fn test_percent_percent_not_replaced() { .stdout_is(expected); } } + +#[test] +#[cfg(unix)] +fn test_date_write_error_dev_full() { + use std::fs::OpenOptions; + let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap(); + new_ucmd!() + .arg("+%s") + .set_stdout(dev_full) + .fails() + .stderr_contains("write error"); +} diff --git a/tests/by-util/test_tty.rs b/tests/by-util/test_tty.rs index 9e1db7a21..b5aa23aa7 100644 --- a/tests/by-util/test_tty.rs +++ b/tests/by-util/test_tty.rs @@ -87,3 +87,11 @@ fn test_stdout_fail() { let status = proc.wait().unwrap(); assert_eq!(status.code(), Some(3)); } + +#[test] +#[cfg(unix)] +fn test_version_pipe_no_stderr() { + let mut child = new_ucmd!().arg("--version").run_no_wait(); + child.close_stdout(); + child.wait().unwrap().no_stderr(); +}