Skip to content

Commit

Permalink
cksum/hashsum: fix the windows tests + improve some
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jun 2, 2024
1 parent b1b6f28 commit 773d8cf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/uucore/src/lib/features/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ pub fn escape_filename(filename: &Path) -> (String, &'static str) {
let prefix = if escaped == original { "" } else { "\\" };
(escaped, prefix)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
11 changes: 10 additions & 1 deletion tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,17 @@ fn test_check_directory_error() {
"f",
"BLAKE2b (d) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce\n"
);
let err_msg: &str;
#[cfg(not(windows))]
{
err_msg = "cksum: d: Is a directory\n";
}
#[cfg(windows)]
{
err_msg = "cksum: d: Permission denied\n";
}
ucmd.arg("--check")
.arg(at.subdir.join("f"))
.fails()
.stderr_contains("cksum: d: Is a directory\n");
.stderr_contains(err_msg);
}
37 changes: 33 additions & 4 deletions tests/by-util/test_hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ fn test_sha1_with_md5sum_should_fail() {
}

#[test]
// Disabled on Windows because of the "*"
#[cfg(not(windows))]
fn test_check_one_two_space_star() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
Expand Down Expand Up @@ -724,6 +726,8 @@ fn test_check_one_two_space_star() {
}

#[test]
// Disabled on Windows because of the "*"
#[cfg(not(windows))]
fn test_check_space_star_or_not() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
Expand Down Expand Up @@ -833,12 +837,21 @@ fn test_check_directory_error() {

at.mkdir("d");
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427f d\n");
let err_msg: &str;
#[cfg(not(windows))]
{
err_msg = "md5sum: d: Is a directory\n";
}
#[cfg(windows)]
{
err_msg = "md5sum: d: Permission denied\n";
}
scene
.ccmd("md5sum")
.arg("--check")
.arg(at.subdir.join("in.md5"))
.fails()
.stderr_contains("md5sum: d: Is a directory\n");
.stderr_contains(err_msg);
}

#[test]
Expand All @@ -854,8 +867,7 @@ fn test_check_quiet() {
.arg("--check")
.arg(at.subdir.join("in.md5"))
.succeeds()
.stderr_is("")
.stdout_is("");
.no_output();

// incorrect md5
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427f f\n");
Expand All @@ -875,12 +887,29 @@ fn test_star_to_start() {
let at = &scene.fixtures;

at.touch("f");
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427e */dev/null\n");
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427e *f\n");
scene
.ccmd("md5sum")
.arg("--check")
.arg(at.subdir.join("in.md5"))
.succeeds()
.stdout_only("f: OK\n");
}

#[test]
fn test_b2sum_128() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.touch("f");
at.write("in.b2sum", "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce /dev/null\n");
scene
.ccmd("b2sum")
.arg("--check")
.arg("-l")
.arg("128")
.arg(at.subdir.join("in.b2sum"))
.succeeds()
.stderr_is("")
.stdout_is("/dev/null: OK\n");
}

0 comments on commit 773d8cf

Please sign in to comment.