@@ -1403,12 +1403,13 @@ fn test_check_trailing_space_fails() {
1403
1403
/// in checksum files.
1404
1404
/// These tests are excluded from Windows because it does not provide any safe
1405
1405
/// conversion between `OsString` and byte sequences for non-utf-8 strings.
1406
- #[ cfg( not( windows) ) ]
1407
1406
mod check_utf8 {
1408
- use super :: * ;
1409
1407
1408
+ // This test should pass on linux and macos.
1409
+ #[ cfg( not( windows) ) ]
1410
1410
#[ test]
1411
1411
fn test_check_non_utf8_comment ( ) {
1412
+ use super :: * ;
1412
1413
let hashes =
1413
1414
b"MD5 (empty) = 1B2M2Y8AsgTpgAmY7PhCfg==\n \
1414
1415
# Comment with a non utf8 char: >>\xff <<\n \
@@ -1431,8 +1432,12 @@ mod check_utf8 {
1431
1432
. no_stderr ( ) ;
1432
1433
}
1433
1434
1435
+ // This test should pass on linux. Windows and macos will fail to
1436
+ // create a file which name contains '\xff'.
1437
+ #[ cfg( target_os = "linux" ) ]
1434
1438
#[ test]
1435
1439
fn test_check_non_utf8_filename ( ) {
1440
+ use super :: * ;
1436
1441
use std:: { ffi:: OsString , os:: unix:: ffi:: OsStringExt } ;
1437
1442
1438
1443
let scene = TestScenario :: new ( util_name ! ( ) ) ;
@@ -1569,35 +1574,68 @@ fn test_check_mix_hex_base64() {
1569
1574
. stdout_only ( "foo1.dat: OK\n foo2.dat: OK\n " ) ;
1570
1575
}
1571
1576
1572
- #[ ignore = "not yet implemented" ]
1577
+ /// This test ensures that an improperly formatted base64 checksum in a file
1578
+ /// does not interrupt the processing of next lines.
1573
1579
#[ test]
1574
- fn test_check_incorrectly_formatted_checksum_does_not_stop_processing ( ) {
1575
- // The first line contains an incorrectly formatted checksum that can't be
1576
- // correctly decoded. This must not prevent the program from looking at the
1577
- // rest of the file.
1578
- let lines = [
1579
- "BLAKE2b-56 (foo1) = GFYEQ7HhAw=" , // Should be 2 '=' at the end
1580
- "BLAKE2b-56 (foo2) = 18560443b1e103" , // OK
1581
- ] ;
1580
+ fn test_check_incorrectly_formatted_checksum_keeps_processing_b64 ( ) {
1581
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1582
+ let at = & scene. fixtures ;
1583
+ at. touch ( "f" ) ;
1584
+
1585
+ let good_ck = "MD5 (f) = 1B2M2Y8AsgTpgAmY7PhCfg==" ; // OK
1586
+ let bad_ck = "MD5 (f) = 1B2M2Y8AsgTpgAmY7PhCfg=" ; // Missing last '='
1587
+
1588
+ // Good then Bad
1589
+ scene
1590
+ . ucmd ( )
1591
+ . arg ( "--check" )
1592
+ . pipe_in ( [ good_ck, bad_ck] . join ( "\n " ) . as_bytes ( ) . to_vec ( ) )
1593
+ . succeeds ( )
1594
+ . stdout_contains ( "f: OK" )
1595
+ . stderr_contains ( "cksum: WARNING: 1 line is improperly formatted" ) ;
1582
1596
1597
+ // Bad then Good
1598
+ scene
1599
+ . ucmd ( )
1600
+ . arg ( "--check" )
1601
+ . pipe_in ( [ bad_ck, good_ck] . join ( "\n " ) . as_bytes ( ) . to_vec ( ) )
1602
+ . succeeds ( )
1603
+ . stdout_contains ( "f: OK" )
1604
+ . stderr_contains ( "cksum: WARNING: 1 line is improperly formatted" ) ;
1605
+ }
1606
+
1607
+ /// This test ensures that an improperly formatted hexadecimal checksum in a
1608
+ /// file does not interrupt the processing of next lines.
1609
+ #[ test]
1610
+ fn test_check_incorrectly_formatted_checksum_keeps_processing_hex ( ) {
1583
1611
let scene = TestScenario :: new ( util_name ! ( ) ) ;
1584
1612
let at = & scene. fixtures ;
1613
+ at. touch ( "f" ) ;
1614
+
1615
+ let good_ck = "MD5 (f) = d41d8cd98f00b204e9800998ecf8427e" ; // OK
1616
+ let bad_ck = "MD5 (f) = d41d8cd98f00b204e9800998ecf8427" ; // Missing last
1585
1617
1586
- at. write ( "foo1" , "foo" ) ;
1587
- at. write ( "foo2" , "foo" ) ;
1588
- at. write ( "sum" , & lines. join ( "\n " ) ) ;
1618
+ // Good then Bad
1619
+ scene
1620
+ . ucmd ( )
1621
+ . arg ( "--check" )
1622
+ . pipe_in ( [ good_ck, bad_ck] . join ( "\n " ) . as_bytes ( ) . to_vec ( ) )
1623
+ . succeeds ( )
1624
+ . stdout_contains ( "f: OK" )
1625
+ . stderr_contains ( "cksum: WARNING: 1 line is improperly formatted" ) ;
1589
1626
1627
+ // Bad then Good
1590
1628
scene
1591
1629
. ucmd ( )
1592
1630
. arg ( "--check" )
1593
- . arg ( at . subdir . join ( "sum" ) )
1631
+ . pipe_in ( [ bad_ck , good_ck ] . join ( "\n " ) . as_bytes ( ) . to_vec ( ) )
1594
1632
. succeeds ( )
1595
- . stderr_contains ( "1 line is improperly formatted ")
1596
- . stdout_contains ( "foo2: OK ") ;
1633
+ . stdout_contains ( "f: OK ")
1634
+ . stderr_contains ( "cksum: WARNING: 1 line is improperly formatted ") ;
1597
1635
}
1598
1636
1599
1637
/// This module reimplements the cksum-base64.pl GNU test.
1600
- mod cksum_base64 {
1638
+ mod gnu_cksum_base64 {
1601
1639
use super :: * ;
1602
1640
use crate :: common:: util:: log_info;
1603
1641
0 commit comments