Skip to content

Commit

Permalink
slice: add cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trou committed Jan 20, 2024
1 parent bf748a3 commit 8f9e450
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/sliceapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,75 @@ mod tests {

assert_eq!(d[(d.len() - 10)..], pat.process_test(Vec::new()));
}

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

let mut tmpfile = tempfile::NamedTempFile::new().unwrap();
tmpfile.write(&data).unwrap();

assert_cmd::Command::cargo_bin("rsbkb")
.expect("Could not run binary")
.args(&["slice", &tmpfile.path().to_str().unwrap(), "2", "+0x3"])
.assert()
.stdout(&b"\x02\x03\x04"[..])
.success();

assert_cmd::Command::cargo_bin("rsbkb")
.expect("Could not run binary")
.args(&["slice", &tmpfile.path().to_str().unwrap(), "2"])
.assert()
.stdout(&b"\x02\x03\x04\x05\x06\x07\x08\x09"[..])
.success();

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

assert_cmd::Command::cargo_bin("rsbkb")
.expect("Could not run binary")
.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];
for i in (0..10).into_iter() {
data[i] = i as u8;
}

assert_cmd::Command::cargo_bin("rsbkb")
.expect("Could not run binary")
.args(&["slice", "-", "2", "+3"])
.write_stdin(&data)
.assert()
.stdout(&b"\x02\x03\x04"[..])
.success();

assert_cmd::Command::cargo_bin("rsbkb")
.expect("Could not run binary")
.args(&["slice", "-", "2"])
.write_stdin(&data)
.assert()
.stdout(&b"\x02\x03\x04\x05\x06\x07\x08\x09"[..])
.success();

assert_cmd::Command::cargo_bin("rsbkb")
.expect("Could not run binary")
.args(&["slice", "-", "-2"])
.write_stdin(&data)
.assert()
.stdout("")
.failure();
}
}

0 comments on commit 8f9e450

Please # to comment.