Skip to content

Commit

Permalink
Merge pull request #9 from rustcoreutils/hacking
Browse files Browse the repository at this point in the history
cksum: fix output bug and add test
  • Loading branch information
jgarzik authored Mar 16, 2024
2 parents 10cb78c + c8c8c79 commit 473aa43
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion xform/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ fn cksum_file(filename: &str) -> io::Result<()> {
crc = crc32::update(crc, &buffer[0..n_read]);
}

let filename_prefix = {
if filename == "" {
""
} else {
" "
}
};
println!(
"{} {} {}",
"{} {}{}{}",
crc32::finalize(crc, n_bytes as usize),
n_bytes,
filename_prefix,
filename
);

Expand Down
24 changes: 24 additions & 0 deletions xform/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

use plib::{run_test, TestPlan};

fn cksum_test(test_data: &str, expected_output: &str) {
run_test(TestPlan {
cmd: String::from("cksum"),
args: Vec::new(),
stdin_data: String::from(test_data),
expected_out: String::from(expected_output),
});
}

#[test]
fn test_cksum() {
cksum_test("foo\n", "3915528286 4\n");
}

0 comments on commit 473aa43

Please sign in to comment.