Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cksum: fix output bug and add test #9

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}