Skip to content

Commit 351a0ec

Browse files
committed
uniq: Flush BufWriter, make error context GNU-like
1 parent b12b442 commit 351a0ec

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/uu/uniq/src/uniq.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Uniq {
110110
{
111111
write_line_terminator!(writer, line_terminator)?;
112112
}
113+
writer.flush().map_err_context(|| "write error".into())?;
113114
Ok(())
114115
}
115116

@@ -226,7 +227,7 @@ impl Uniq {
226227
} else {
227228
writer.write_all(line)
228229
}
229-
.map_err_context(|| "Failed to write line".to_string())?;
230+
.map_err_context(|| "write error".to_string())?;
230231

231232
write_line_terminator!(writer, line_terminator)
232233
}

tests/by-util/test_uniq.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,3 +1181,16 @@ fn test_stdin_w1_multibyte() {
11811181
.succeeds()
11821182
.stdout_is(\ná\n");
11831183
}
1184+
1185+
#[cfg(target_os = "linux")]
1186+
#[test]
1187+
fn test_failed_write_is_reported() {
1188+
use std::fs::File;
1189+
1190+
new_ucmd!()
1191+
.pipe_in("hello")
1192+
.args(&["-z"])
1193+
.set_stdout(File::create("/dev/full").unwrap())
1194+
.fails()
1195+
.stderr_is("uniq: write error: No space left on device\n");
1196+
}

0 commit comments

Comments
 (0)