mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
cksum: added tests for --raw with each algorithm, not working for crc, sysv, bsd
This commit is contained in:
parent
28b5224725
commit
96271ffa3c
13 changed files with 33 additions and 12 deletions
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) fname, algo
|
// spell-checker:ignore (ToDO) fname, algo
|
||||||
use clap::{crate_version, value_parser, Arg, ArgAction, Command};
|
use clap::{crate_version, value_parser, Arg, ArgAction, Command};
|
||||||
|
use hex::decode;
|
||||||
use hex::encode;
|
use hex::encode;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
@ -151,12 +152,12 @@ fn cksum<'a, I>(mut options: Options, files: I) -> UResult<()>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = &'a OsStr>,
|
I: Iterator<Item = &'a OsStr>,
|
||||||
{
|
{
|
||||||
let files_vec: Vec<_> = files.collect();
|
let files: Vec<_> = files.collect();
|
||||||
if options.raw && files_vec.len() > 1 {
|
if options.raw && files.len() > 1 {
|
||||||
return Err(Box::new(CkSumError::RawMultipleFiles));
|
return Err(Box::new(CkSumError::RawMultipleFiles));
|
||||||
}
|
}
|
||||||
|
|
||||||
for filename in files_vec {
|
for filename in files {
|
||||||
let filename = Path::new(filename);
|
let filename = Path::new(filename);
|
||||||
let stdin_buf;
|
let stdin_buf;
|
||||||
let file_buf;
|
let file_buf;
|
||||||
|
@ -175,8 +176,16 @@ where
|
||||||
.map_err_context(|| "failed to read input".to_string())?;
|
.map_err_context(|| "failed to read input".to_string())?;
|
||||||
|
|
||||||
if options.raw {
|
if options.raw {
|
||||||
let bytes_str = sum.parse::<u32>().unwrap().to_be_bytes();
|
match decode(sum.clone()) {
|
||||||
stdout().write_all(&bytes_str)?;
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
// The BSD checksum output is 5 digit integer
|
// The BSD checksum output is 5 digit integer
|
||||||
|
|
|
@ -289,14 +289,16 @@ fn test_length_is_zero() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_raw_single_file() {
|
fn test_raw_single_file() {
|
||||||
new_ucmd!()
|
for algo in ALGOS {
|
||||||
.arg("--raw")
|
new_ucmd!()
|
||||||
.arg("lorem_ipsum.txt")
|
.arg("--raw")
|
||||||
.succeeds()
|
.arg("lorem_ipsum.txt")
|
||||||
.no_stderr()
|
.arg(format!("--algorithm={algo}"))
|
||||||
.stdout_is_fixture_bytes("raw_single_file.expected");
|
.succeeds()
|
||||||
|
.no_stderr()
|
||||||
|
.stdout_is_fixture_bytes(format!("raw/{algo}_single_file.expected"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_raw_multiple_files() {
|
fn test_raw_multiple_files() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
1
tests/fixtures/cksum/raw/blake2b_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/blake2b_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<0E><><EFBFBD><EFBFBD><EFBFBD>`<60>x<EFBFBD><0B>f<><1E>W<EFBFBD><57><EFBFBD>Et<45>B<><42>l<EFBFBD><6C>W^J<>0<EFBFBD>aX´<08><>8<EFBFBD><38><EFBFBD><EFBFBD><EFBFBD>5<15>B<EFBFBD><42>9m<11><>
|
1
tests/fixtures/cksum/raw/bsd_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/bsd_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<1F>
|
BIN
tests/fixtures/cksum/raw/md5_single_file.expected
vendored
Normal file
BIN
tests/fixtures/cksum/raw/md5_single_file.expected
vendored
Normal file
Binary file not shown.
1
tests/fixtures/cksum/raw/sha1_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sha1_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<EFBFBD>к<>؈:=<18>m毽(%,<2C><>
|
BIN
tests/fixtures/cksum/raw/sha224_single_file.expected
vendored
Normal file
BIN
tests/fixtures/cksum/raw/sha224_single_file.expected
vendored
Normal file
Binary file not shown.
1
tests/fixtures/cksum/raw/sha256_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sha256_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
÷Ä PPà0’P
gê^‘ <09>SkE‚þœC[Ù+?
|
3
tests/fixtures/cksum/raw/sha384_single_file.expected
vendored
Normal file
3
tests/fixtures/cksum/raw/sha384_single_file.expected
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
K荵
|
||||||
|
2吠鋳<19>シ<EFBFBD>マクアト/g胤コ囹LZ{WZ3Sゥ
|
||||||
|
守Hヒ
|
1
tests/fixtures/cksum/raw/sha512_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sha512_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
–Td«%VªÕ޼sØšÒ!åYyu)ì¯ÀôfÁ•ÏöÖâÆ– |T,ýBn^Oऊ¡VgºD k!=Í<03>ú
|
1
tests/fixtures/cksum/raw/sm3_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sm3_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
m)k€]þÒ(ß0<C39F>»›CyMÔíg@¡p§‚i›Â
|
1
tests/fixtures/cksum/raw/sysv_single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/raw/sysv_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
I
|
Loading…
Add table
Add a link
Reference in a new issue