Skip to content

Commit

Permalink
ignore broken pipe + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
trou committed Jan 21, 2024
1 parent 4a17c19 commit 6e287d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,18 @@ fn main() -> Result<()> {

if selected_app.returns_data() {
let mut stdout = io::stdout();
stdout.write_all(&res).expect("Write failed");
let write_res = stdout.write_all(&res);

// Ignore broken pipe
match write_res {
Err(err) if err.kind() != std::io::ErrorKind::BrokenPipe => {
return Err(err.into());
}
Err(_) => {
return Ok(());
}
Ok(_) => (),
};

/* Only add a newline when outputing to a terminal */
if atty::is(Stream::Stdout) {
Expand Down
12 changes: 9 additions & 3 deletions src/sliceapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ mod tests {

#[test]
fn test_cli_file() {
let mut data : [u8; 10] = [0; 10];
let mut data: [u8; 10] = [0; 10];
for i in (0..10).into_iter() {
data[i] = i as u8;
}
Expand Down Expand Up @@ -273,15 +273,21 @@ mod tests {

assert_cmd::Command::cargo_bin("rsbkb")
.expect("Could not run binary")
.args(&["slice", "--", &tmpfile.path().to_str().unwrap(), "-0x2", "+1"])
.args(&[
"slice",
"--",
&tmpfile.path().to_str().unwrap(),
"-0x2",
"+1",
])
.assert()
.stdout(&b"\x08"[..])
.success();
}

#[test]
fn test_cli_stdin() {
let mut data : [u8; 10] = [0; 10];
let mut data: [u8; 10] = [0; 10];
for i in (0..10).into_iter() {
data[i] = i as u8;
}
Expand Down

0 comments on commit 6e287d1

Please sign in to comment.