Skip to content

Commit

Permalink
test(cksum): add non-UTF-8 handling tests
Browse files Browse the repository at this point in the history
- add a test for non UTF-8 chars in comments
- add test for non-UTF-8 chars in filenames
  • Loading branch information
RenjiSann committed Sep 17, 2024
1 parent 527f61b commit 3533b6e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,3 +1277,50 @@ fn test_non_utf8_filename() {
.stdout_is_bytes(b"SHA256 (funky\xffname) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n")
.no_stderr();
}

#[cfg(target_os = "linux")]
#[test]
fn test_check_non_utf8_comment() {
let hashes =
b"MD5 (empty) = 1B2M2Y8AsgTpgAmY7PhCfg==\n\
# Comment with a non utf8 char: >>\xff<<\n\
SHA256 (empty) = 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=\n\
BLAKE2b (empty) = eGoC90IBWQPGxv2FJVLScpEvR0DhWEdhiobiF/cfVBnSXhAxr+5YUxOJZESTTrBLkDpoWxRIt1XVb3Aa/pvizg==\n"
;

let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.touch("empty");
at.write_bytes("check", hashes);

scene
.ucmd()
.arg("--check")
.arg(at.subdir.join("check"))
.succeeds()
.stdout_is("empty: OK\nempty: OK\nempty: OK\n")
.no_stderr();
}

#[cfg(target_os = "linux")]
#[test]
fn test_check_non_utf8_filename() {
use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;

let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let filename: OsString = OsStringExt::from_vec(b"funky\xffname".to_vec());

at.touch(&filename);
at.write_bytes("check", b"SHA256 (funky\xffname) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n");

scene
.ucmd()
.arg("--check")
.arg(at.subdir.join("check"))
.succeeds()
.stdout_is("funkyname: OK\n")
.no_stderr();
}

0 comments on commit 3533b6e

Please sign in to comment.