Skip to content

Commit 326b5d7

Browse files
committed
test(cksum): add non-UTF-8 handling tests
- add a test for non UTF-8 chars in comments - add test for non-UTF-8 chars in filenames
1 parent ce85a7c commit 326b5d7

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

tests/by-util/test_cksum.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5-
// spell-checker:ignore (words) asdf algo algos asha mgmt xffname
5+
// spell-checker:ignore (words) asdf algo algos asha mgmt xffname funkyname
66

77
use crate::common::util::TestScenario;
88

@@ -1277,3 +1277,50 @@ fn test_non_utf8_filename() {
12771277
.stdout_is_bytes(b"SHA256 (funky\xffname) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n")
12781278
.no_stderr();
12791279
}
1280+
1281+
#[cfg(target_os = "linux")]
1282+
#[test]
1283+
fn test_check_non_utf8_comment() {
1284+
let hashes =
1285+
b"MD5 (empty) = 1B2M2Y8AsgTpgAmY7PhCfg==\n\
1286+
# Comment with a non utf8 char: >>\xff<<\n\
1287+
SHA256 (empty) = 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=\n\
1288+
BLAKE2b (empty) = eGoC90IBWQPGxv2FJVLScpEvR0DhWEdhiobiF/cfVBnSXhAxr+5YUxOJZESTTrBLkDpoWxRIt1XVb3Aa/pvizg==\n"
1289+
;
1290+
1291+
let scene = TestScenario::new(util_name!());
1292+
let at = &scene.fixtures;
1293+
1294+
at.touch("empty");
1295+
at.write_bytes("check", hashes);
1296+
1297+
scene
1298+
.ucmd()
1299+
.arg("--check")
1300+
.arg(at.subdir.join("check"))
1301+
.succeeds()
1302+
.stdout_is("empty: OK\nempty: OK\nempty: OK\n")
1303+
.no_stderr();
1304+
}
1305+
1306+
#[cfg(target_os = "linux")]
1307+
#[test]
1308+
fn test_check_non_utf8_filename() {
1309+
use std::ffi::OsString;
1310+
use std::os::unix::ffi::OsStringExt;
1311+
1312+
let scene = TestScenario::new(util_name!());
1313+
let at = &scene.fixtures;
1314+
let filename: OsString = OsStringExt::from_vec(b"funky\xffname".to_vec());
1315+
1316+
at.touch(&filename);
1317+
at.write_bytes("check", b"SHA256 (funky\xffname) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n");
1318+
1319+
scene
1320+
.ucmd()
1321+
.arg("--check")
1322+
.arg(at.subdir.join("check"))
1323+
.succeeds()
1324+
.stdout_is("funkyname: OK\n")
1325+
.no_stderr();
1326+
}

0 commit comments

Comments
 (0)