@@ -939,3 +939,70 @@ fn test_check_b2sum_strict_check() {
939
939
. succeeds ( )
940
940
. stdout_only ( & output) ;
941
941
}
942
+
943
+ #[ test]
944
+ fn test_check_md5_comment_line ( ) {
945
+ // A comment in a checksum file shall be discarded unnoticed.
946
+
947
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
948
+ let at = & scene. fixtures ;
949
+
950
+ at. write ( "foo" , "foo-content\n " ) ;
951
+ at. write (
952
+ "MD5SUM" ,
953
+ "\
954
+ # This is a comment\n \
955
+ 8411029f3f5b781026a93db636aca721 foo\n \
956
+ # next comment is empty\n #",
957
+ ) ;
958
+
959
+ scene
960
+ . ccmd ( "md5sum" )
961
+ . arg ( "--check" )
962
+ . arg ( "MD5SUM" )
963
+ . succeeds ( )
964
+ . stdout_contains ( "foo: OK" ) ;
965
+ }
966
+
967
+ #[ test]
968
+ fn test_check_md5_comment_only ( ) {
969
+ // A file only filled with comments is equivalent to an empty file,
970
+ // and therefore produces an error.
971
+
972
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
973
+ let at = & scene. fixtures ;
974
+
975
+ at. write ( "foo" , "foo-content\n " ) ;
976
+ at. write ( "MD5SUM" , "# This is a comment\n " ) ;
977
+
978
+ scene
979
+ . ccmd ( "md5sum" )
980
+ . arg ( "--check" )
981
+ . arg ( "MD5SUM" )
982
+ . fails ( )
983
+ . stderr_contains ( "no properly formatted checksum lines found" ) ;
984
+ }
985
+
986
+ #[ test]
987
+ fn test_check_md5_comment_leading_space ( ) {
988
+ // A file only filled with comments is equivalent to an empty file,
989
+ // and therefore produces an error.
990
+
991
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
992
+ let at = & scene. fixtures ;
993
+
994
+ at. write ( "foo" , "foo-content\n " ) ;
995
+ at. write (
996
+ "MD5SUM" ,
997
+ " # This is a comment\n \
998
+ 8411029f3f5b781026a93db636aca721 foo\n ",
999
+ ) ;
1000
+
1001
+ scene
1002
+ . ccmd ( "md5sum" )
1003
+ . arg ( "--check" )
1004
+ . arg ( "MD5SUM" )
1005
+ . succeeds ( )
1006
+ . stdout_contains ( "foo: OK" )
1007
+ . stderr_contains ( "WARNING: 1 line is improperly formatted" ) ;
1008
+ }
0 commit comments