@@ -1443,7 +1443,7 @@ mod check_utf8 {
14431443 let scene = TestScenario :: new ( util_name ! ( ) ) ;
14441444 let at = & scene. fixtures ;
14451445 let filename: OsString = OsStringExt :: from_vec ( b"funky\xff name" . to_vec ( ) ) ;
1446- at. touch ( & filename) ;
1446+ at. touch ( filename) ;
14471447
14481448 // Checksum match
14491449 at. write_bytes ( "check" ,
@@ -1544,7 +1544,6 @@ fn test_check_confusing_base64() {
15441544
15451545/// This test checks that when a file contains several checksum lines
15461546/// with different encoding, the decoding still works.
1547- #[ ignore = "not yet implemented" ]
15481547#[ test]
15491548fn test_check_mix_hex_base64 ( ) {
15501549 let b64 = "BLAKE2b-128 (foo1.dat) = BBNuJPhdRwRlw9tm5Y7VbA==" ;
@@ -1769,3 +1768,81 @@ mod gnu_cksum_base64 {
17691768 }
17701769 }
17711770}
1771+
1772+ /// The tests in this module check the behavior of cksum when given different
1773+ /// checksum formats and algorithms in the same file, while specifying an
1774+ /// algorithm on CLI or not.
1775+ mod format_mix {
1776+ use super :: * ;
1777+
1778+ // First line is algo-based, second one is not
1779+ const INPUT_ALGO_NON_ALGO : & str = "\
1780+ BLAKE2b (bar) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce\n \
1781+ 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce foo";
1782+
1783+ // First line is non algo-based, second one is
1784+ const INPUT_NON_ALGO_ALGO : & str = "\
1785+ 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce foo\n \
1786+ BLAKE2b (bar) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
1787+
1788+ /// Make a simple scene with foo and bar empty files
1789+ fn make_scene ( ) -> TestScenario {
1790+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
1791+ let at = & scene. fixtures ;
1792+
1793+ at. touch ( "foo" ) ;
1794+ at. touch ( "bar" ) ;
1795+
1796+ scene
1797+ }
1798+
1799+ #[ test]
1800+ fn test_check_cli_algo_non_algo ( ) {
1801+ let scene = make_scene ( ) ;
1802+ scene
1803+ . ucmd ( )
1804+ . arg ( "--check" )
1805+ . arg ( "--algo=blake2b" )
1806+ . pipe_in ( INPUT_ALGO_NON_ALGO )
1807+ . succeeds ( )
1808+ . stdout_contains ( "bar: OK\n foo: OK" )
1809+ . no_stderr ( ) ;
1810+ }
1811+
1812+ #[ test]
1813+ fn test_check_cli_non_algo_algo ( ) {
1814+ let scene = make_scene ( ) ;
1815+ scene
1816+ . ucmd ( )
1817+ . arg ( "--check" )
1818+ . arg ( "--algo=blake2b" )
1819+ . pipe_in ( INPUT_NON_ALGO_ALGO )
1820+ . succeeds ( )
1821+ . stdout_contains ( "foo: OK\n bar: OK" )
1822+ . no_stderr ( ) ;
1823+ }
1824+
1825+ #[ test]
1826+ fn test_check_algo_non_algo ( ) {
1827+ let scene = make_scene ( ) ;
1828+ scene
1829+ . ucmd ( )
1830+ . arg ( "--check" )
1831+ . pipe_in ( INPUT_ALGO_NON_ALGO )
1832+ . succeeds ( )
1833+ . stdout_contains ( "bar: OK" )
1834+ . stderr_contains ( "cksum: WARNING: 1 line is improperly formatted" ) ;
1835+ }
1836+
1837+ #[ test]
1838+ fn test_check_non_algo_algo ( ) {
1839+ let scene = make_scene ( ) ;
1840+ scene
1841+ . ucmd ( )
1842+ . arg ( "--check" )
1843+ . pipe_in ( INPUT_NON_ALGO_ALGO )
1844+ . succeeds ( )
1845+ . stdout_contains ( "bar: OK" )
1846+ . stderr_contains ( "cksum: WARNING: 1 line is improperly formatted" ) ;
1847+ }
1848+ }
0 commit comments