diff --git a/xform/src/cksum.rs b/xform/src/cksum.rs index e20cabfa..dcd217e6 100644 --- a/xform/src/cksum.rs +++ b/xform/src/cksum.rs @@ -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 ); diff --git a/xform/tests/integration.rs b/xform/tests/integration.rs new file mode 100644 index 00000000..ef646723 --- /dev/null +++ b/xform/tests/integration.rs @@ -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"); +}