1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

dd: move unit tests into dd.rs and test_dd.rs

Clean up unit tests in the `dd` crate to make them easier to
manage. This commit does a few things.

* move test cases that test the complete functionality of the `dd`
  program from the `dd_unit_tests` module up to the
  `tests/by-util/test_dd.rs` module so that they can take advantage of
  the testing framework and common testing tools provided by uutils,
* move test cases that test internal functions of the `dd`
  implementation into the `tests` module within `dd.rs` so that they
  live closer to the code they are testing,
* replace test cases defined by macros with test cases defined by
  plain old functions to make the test cases easier to read at a
  glance.
This commit is contained in:
Jeffrey Finkelstein 2022-02-14 21:20:12 -05:00
parent e598bf0835
commit ba1ce7179b
60 changed files with 813 additions and 1100 deletions

View file

@ -702,5 +702,364 @@ fn test_partial_records_out() {
.stderr_is("1+1 records in\n1+1 records out\n");
}
// conv=[ascii,ebcdic,ibm], conv=[ucase,lcase], conv=[block,unblock], conv=sync
// TODO: Move conv tests from unit test module
#[test]
fn test_block_cbs16() {
new_ucmd!()
.args(&["conv=block", "cbs=16"])
.pipe_in_fixture("dd-block-cbs16.test")
.succeeds()
.stdout_is_fixture_bytes("dd-block-cbs16.spec");
}
#[test]
fn test_block_cbs16_as_cbs8() {
new_ucmd!()
.args(&["conv=block", "cbs=8"])
.pipe_in_fixture("dd-block-cbs16.test")
.succeeds()
.stdout_is_fixture_bytes("dd-block-cbs8.spec");
}
#[test]
fn test_block_consecutive_nl() {
new_ucmd!()
.args(&["conv=block", "cbs=16"])
.pipe_in_fixture("dd-block-consecutive-nl.test")
.succeeds()
.stdout_is_fixture_bytes("dd-block-consecutive-nl-cbs16.spec");
}
#[test]
fn test_unblock_multi_16() {
new_ucmd!()
.args(&["conv=unblock", "cbs=16"])
.pipe_in_fixture("dd-unblock-cbs16.test")
.succeeds()
.stdout_is_fixture_bytes("dd-unblock-cbs16.spec");
}
#[test]
fn test_unblock_multi_16_as_8() {
new_ucmd!()
.args(&["conv=unblock", "cbs=8"])
.pipe_in_fixture("dd-unblock-cbs16.test")
.succeeds()
.stdout_is_fixture_bytes("dd-unblock-cbs8.spec");
}
#[test]
fn test_atoe_conv_spec_test() {
new_ucmd!()
.args(&["conv=ebcdic"])
.pipe_in_fixture("seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test")
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-atoe-seq-byte-values.spec");
}
#[test]
fn test_etoa_conv_spec_test() {
new_ucmd!()
.args(&["conv=ascii"])
.pipe_in_fixture("seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test")
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-etoa-seq-byte-values.spec");
}
#[test]
fn test_atoibm_conv_spec_test() {
new_ucmd!()
.args(&["conv=ibm"])
.pipe_in_fixture("seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test")
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-atoibm-seq-byte-values.spec");
}
#[test]
fn test_lcase_ascii_to_ucase_ascii() {
new_ucmd!()
.args(&["conv=ucase"])
.pipe_in_fixture("lcase-ascii.test")
.succeeds()
.stdout_is_fixture_bytes("ucase-ascii.test");
}
#[test]
fn test_ucase_ascii_to_lcase_ascii() {
new_ucmd!()
.args(&["conv=lcase"])
.pipe_in_fixture("ucase-ascii.test")
.succeeds()
.stdout_is_fixture_bytes("lcase-ascii.test");
}
#[test]
fn test_atoe_and_ucase_conv_spec_test() {
new_ucmd!()
.args(&["conv=ebcdic,ucase"])
.pipe_in_fixture("seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test")
.succeeds()
.stdout_is_fixture_bytes("ucase-ebcdic.test");
}
#[test]
fn test_atoe_and_lcase_conv_spec_test() {
new_ucmd!()
.args(&["conv=ebcdic,lcase"])
.pipe_in_fixture("seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test")
.succeeds()
.stdout_is_fixture_bytes("lcase-ebcdic.test");
}
// TODO I think uppercase and lowercase are unintentionally swapped in
// the code that parses the command-line arguments. See this line from
// `parseargs.rs`:
//
// (ConvFlag::FmtAtoI, ConvFlag::UCase) => Some(&ASCII_TO_IBM_UCASE_TO_LCASE),
// (ConvFlag::FmtAtoI, ConvFlag::LCase) => Some(&ASCII_TO_IBM_LCASE_TO_UCASE),
//
// If my reading is correct and that is a typo, then the
// UCASE_TO_LCASE and LCASE_TO_UCASE in those lines should be swapped,
// and the expected output for the following two tests should be
// updated accordingly.
#[test]
fn test_atoibm_and_ucase_conv_spec_test() {
new_ucmd!()
.args(&["conv=ibm,ucase"])
.pipe_in_fixture("seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test")
.succeeds()
.stdout_is_fixture_bytes("lcase-ibm.test");
}
#[test]
fn test_atoibm_and_lcase_conv_spec_test() {
new_ucmd!()
.args(&["conv=ibm,lcase"])
.pipe_in_fixture("seq-byte-values-b632a992d3aed5d8d1a59cc5a5a455ba.test")
.succeeds()
.stdout_is_fixture_bytes("ucase-ibm.test");
}
#[test]
fn test_swab_256_test() {
new_ucmd!()
.args(&["conv=swab"])
.pipe_in_fixture("seq-byte-values.test")
.succeeds()
.stdout_is_fixture_bytes("seq-byte-values-swapped.test");
}
#[test]
fn test_swab_257_test() {
new_ucmd!()
.args(&["conv=swab"])
.pipe_in_fixture("seq-byte-values-odd.test")
.succeeds()
.stdout_is_fixture_bytes("seq-byte-values-odd.spec");
}
#[test]
fn test_zeros_4k_conv_sync_obs_gt_ibs() {
new_ucmd!()
.args(&["conv=sync", "ibs=521", "obs=1031"])
.pipe_in_fixture("zeros-620f0b67a91f7f74151bc5be745b7110.test")
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-sync-ibs-521-obs-1031-zeros.spec");
}
#[test]
fn test_zeros_4k_conv_sync_ibs_gt_obs() {
new_ucmd!()
.args(&["conv=sync", "ibs=1031", "obs=521"])
.pipe_in_fixture("zeros-620f0b67a91f7f74151bc5be745b7110.test")
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-sync-ibs-1031-obs-521-zeros.spec");
}
#[test]
fn test_deadbeef_32k_conv_sync_obs_gt_ibs() {
new_ucmd!()
.args(&[
"conv=sync",
"ibs=521",
"obs=1031",
"if=deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-sync-ibs-521-obs-1031-deadbeef.spec");
}
#[test]
fn test_deadbeef_32k_conv_sync_ibs_gt_obs() {
new_ucmd!()
.args(&[
"conv=sync",
"ibs=1031",
"obs=521",
"if=deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-sync-ibs-1031-obs-521-deadbeef.spec");
}
#[test]
fn test_random_73k_test_bs_prime_obs_gt_ibs_sync() {
new_ucmd!()
.args(&[
"conv=sync",
"ibs=521",
"obs=1031",
"if=random-5828891cb1230748e146f34223bbd3b5.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-sync-ibs-521-obs-1031-random.spec");
}
#[test]
fn test_random_73k_test_bs_prime_ibs_gt_obs_sync() {
new_ucmd!()
.args(&[
"conv=sync",
"ibs=1031",
"obs=521",
"if=random-5828891cb1230748e146f34223bbd3b5.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-conv-sync-ibs-1031-obs-521-random.spec");
}
#[test]
fn test_identity() {
new_ucmd!()
.args(&["if=zeros-620f0b67a91f7f74151bc5be745b7110.test"])
.succeeds()
.stdout_is_fixture_bytes("zeros-620f0b67a91f7f74151bc5be745b7110.test");
new_ucmd!()
.args(&["if=ones-6ae59e64850377ee5470c854761551ea.test"])
.succeeds()
.stdout_is_fixture_bytes("ones-6ae59e64850377ee5470c854761551ea.test");
new_ucmd!()
.args(&["if=deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test"])
.succeeds()
.stdout_is_fixture_bytes("deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test");
new_ucmd!()
.args(&["if=random-5828891cb1230748e146f34223bbd3b5.test"])
.succeeds()
.stdout_is_fixture_bytes("random-5828891cb1230748e146f34223bbd3b5.test");
}
#[test]
fn test_random_73k_test_not_a_multiple_obs_gt_ibs() {
new_ucmd!()
.args(&[
"ibs=521",
"obs=1031",
"if=random-5828891cb1230748e146f34223bbd3b5.test",
])
.succeeds()
.stdout_is_fixture_bytes("random-5828891cb1230748e146f34223bbd3b5.test");
}
#[test]
fn test_random_73k_test_obs_lt_not_a_multiple_ibs() {
new_ucmd!()
.args(&[
"ibs=1031",
"obs=521",
"if=random-5828891cb1230748e146f34223bbd3b5.test",
])
.succeeds()
.stdout_is_fixture_bytes("random-5828891cb1230748e146f34223bbd3b5.test");
}
#[test]
fn test_deadbeef_all_32k_test_count_reads() {
new_ucmd!()
.args(&[
"bs=1024",
"count=32",
"if=deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test",
])
.succeeds()
.stdout_is_fixture_bytes("deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test");
}
#[test]
fn test_deadbeef_all_32k_test_count_bytes() {
new_ucmd!()
.args(&[
"ibs=531",
"obs=1031",
"count=32x1024",
"oflag=count_bytes",
"if=deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test",
])
.succeeds()
.stdout_is_fixture_bytes("deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test");
}
#[test]
fn test_deadbeef_32k_to_16k_test_count_reads() {
new_ucmd!()
.args(&[
"ibs=1024",
"obs=1031",
"count=16",
"if=deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-deadbeef-first-16k.spec");
}
#[test]
fn test_deadbeef_32k_to_12345_test_count_bytes() {
new_ucmd!()
.args(&[
"ibs=531",
"obs=1031",
"count=12345",
"iflag=count_bytes",
"if=deadbeef-18d99661a1de1fc9af21b0ec2cd67ba3.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-deadbeef-first-12345.spec");
}
#[test]
fn test_random_73k_test_count_reads() {
new_ucmd!()
.args(&[
"bs=1024",
"count=32",
"if=random-5828891cb1230748e146f34223bbd3b5.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-random-first-32k.spec");
}
#[test]
fn test_random_73k_test_count_bytes() {
new_ucmd!()
.args(&[
"ibs=521",
"obs=1031",
"count=32x1024",
"iflag=count_bytes",
"if=random-5828891cb1230748e146f34223bbd3b5.test",
])
.succeeds()
.stdout_is_fixture_bytes("gnudd-random-first-32k.spec");
}
#[test]
fn test_all_valid_ascii_ebcdic_ascii_roundtrip_conv_test() {
let tmp = new_ucmd!()
.args(&["ibs=128", "obs=1024", "conv=ebcdic"])
.pipe_in_fixture("all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test")
.succeeds()
.stdout_move_bytes();
new_ucmd!()
.args(&["ibs=256", "obs=1024", "conv=ascii"])
.pipe_in(tmp)
.succeeds()
.stdout_is_fixture_bytes("all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test");
}