mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cksum: added tests for --raw with each algorithm, not working for crc, sysv, bsd
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
// spell-checker:ignore (ToDO) fname, algo
|
||||
use clap::{crate_version, value_parser, Arg, ArgAction, Command};
|
||||
use hex::decode;
|
||||
use hex::encode;
|
||||
use std::error::Error;
|
||||
use std::ffi::OsStr;
|
||||
@@ -151,12 +152,12 @@ fn cksum<'a, I>(mut options: Options, files: I) -> UResult<()>
|
||||
where
|
||||
I: Iterator<Item = &'a OsStr>,
|
||||
{
|
||||
let files_vec: Vec<_> = files.collect();
|
||||
if options.raw && files_vec.len() > 1 {
|
||||
let files: Vec<_> = files.collect();
|
||||
if options.raw && files.len() > 1 {
|
||||
return Err(Box::new(CkSumError::RawMultipleFiles));
|
||||
}
|
||||
|
||||
for filename in files_vec {
|
||||
for filename in files {
|
||||
let filename = Path::new(filename);
|
||||
let stdin_buf;
|
||||
let file_buf;
|
||||
@@ -175,8 +176,16 @@ where
|
||||
.map_err_context(|| "failed to read input".to_string())?;
|
||||
|
||||
if options.raw {
|
||||
let bytes_str = sum.parse::<u32>().unwrap().to_be_bytes();
|
||||
stdout().write_all(&bytes_str)?;
|
||||
match decode(sum.clone()) {
|
||||
Ok(bytes) => {
|
||||
stdout().write_all(&bytes)?;
|
||||
}
|
||||
Err(_) => {
|
||||
//bsd, sysv and crc have output generated without encode()
|
||||
let bytes = sum.parse::<u32>().unwrap().to_be_bytes();
|
||||
stdout().write_all(&bytes)?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
// The BSD checksum output is 5 digit integer
|
||||
|
||||
@@ -289,14 +289,16 @@ fn test_length_is_zero() {
|
||||
|
||||
#[test]
|
||||
fn test_raw_single_file() {
|
||||
new_ucmd!()
|
||||
.arg("--raw")
|
||||
.arg("lorem_ipsum.txt")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is_fixture_bytes("raw_single_file.expected");
|
||||
for algo in ALGOS {
|
||||
new_ucmd!()
|
||||
.arg("--raw")
|
||||
.arg("lorem_ipsum.txt")
|
||||
.arg(format!("--algorithm={algo}"))
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is_fixture_bytes(format!("raw/{algo}_single_file.expected"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_raw_multiple_files() {
|
||||
new_ucmd!()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
�����`�x��f��W���Et�B��l��W^J�0�aX´��8�����5�B��9m��
|
||||
@@ -0,0 +1 @@
|
||||
�
|
||||
Vendored
Binary file not shown.
@@ -0,0 +1 @@
|
||||
�к�؈:=�m毽(%,��
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
÷Ä PPà0’P
gê^‘ �SkE‚þœC[Ù+?
|
||||
@@ -0,0 +1,3 @@
|
||||
K荵
|
||||
2吠鋳�シ�マクアト/g胤コ囹LZ{WZ3Sゥ
|
||||
守Hヒ
|
||||
@@ -0,0 +1 @@
|
||||
–Td«%VªÕ޼sØšÒ!åYyu)ì¯ÀôfÁ•ÏöÖâÆ– |T,ýBn^Oऊ¡VgºD k!=Í�ú
|
||||
@@ -0,0 +1 @@
|
||||
m)k€]þÒ(ß0�»›CyMÔíg@¡p§‚i›Â
|
||||
@@ -0,0 +1 @@
|
||||
I
|
||||
Reference in New Issue
Block a user