@@ -1155,23 +1155,63 @@ fn test_invalid_num() {
11551155 . fails ( )
11561156 . stderr_str ( )
11571157 . starts_with ( "tail: invalid number of lines: '1024R'" ) ;
1158+ // 1Y overflows to u64::MAX (like GNU tail 9.9.x), so it succeeds
11581159 new_ucmd ! ( )
1159- . args ( & [ "-c" , "1Y" , "emptyfile.txt" ] )
1160- . fails ( )
1161- . stderr_str ( )
1162- . starts_with ( "tail: invalid number of bytes: '1Y': Value too large for defined data type ") ;
1160+ . args ( & [ "-c" , "1Y" ] )
1161+ . pipe_in ( "x" )
1162+ . succeeds ( )
1163+ . stdout_is ( "x ") ;
11631164 new_ucmd ! ( )
1164- . args ( & [ "-n" , "1Y" , "emptyfile.txt" ] )
1165- . fails ( )
1166- . stderr_str ( )
1167- . starts_with ( "tail: invalid number of lines: '1Y': Value too large for defined data type ") ;
1165+ . args ( & [ "-n" , "1Y" ] )
1166+ . pipe_in ( "x \n " )
1167+ . succeeds ( )
1168+ . stdout_is ( "x \n ") ;
11681169 new_ucmd ! ( )
11691170 . args ( & [ "-c" , "-³" ] )
11701171 . fails ( )
11711172 . stderr_str ( )
11721173 . starts_with ( "tail: invalid number of bytes: '³'" ) ;
11731174}
11741175
1176+ #[ test]
1177+ fn test_oversized_num ( ) {
1178+ const BIG : & str = "99999999999999999999999999999" ;
1179+ const DATA : & str = "abcd" ;
1180+ // -c <big> and -n <big>: output all (request more than available)
1181+ new_ucmd ! ( )
1182+ . args ( & [ "-c" , BIG ] )
1183+ . pipe_in ( DATA )
1184+ . succeeds ( )
1185+ . stdout_is ( DATA ) ;
1186+ new_ucmd ! ( )
1187+ . args ( & [ "-n" , BIG ] )
1188+ . pipe_in ( "a\n b\n " )
1189+ . succeeds ( )
1190+ . stdout_is ( "a\n b\n " ) ;
1191+ // +<big>: skip beyond input (empty output)
1192+ new_ucmd ! ( )
1193+ . args ( & [ "-c" , & format ! ( "+{BIG}" ) ] )
1194+ . pipe_in ( DATA )
1195+ . succeeds ( )
1196+ . no_stdout ( ) ;
1197+ new_ucmd ! ( )
1198+ . args ( & [ "-n" , & format ! ( "+{BIG}" ) ] )
1199+ . pipe_in ( "a\n b\n " )
1200+ . succeeds ( )
1201+ . no_stdout ( ) ;
1202+ // Obsolete syntax
1203+ new_ucmd ! ( )
1204+ . arg ( format ! ( "+{BIG}c" ) )
1205+ . pipe_in ( DATA )
1206+ . succeeds ( )
1207+ . no_stdout ( ) ;
1208+ new_ucmd ! ( )
1209+ . arg ( format ! ( "-{BIG}c" ) )
1210+ . pipe_in ( DATA )
1211+ . succeeds ( )
1212+ . stdout_is ( DATA ) ;
1213+ }
1214+
11751215#[ test]
11761216fn test_num_with_undocumented_sign_bytes ( ) {
11771217 // tail: '-' is not documented (8.32 man pages)
@@ -4767,13 +4807,13 @@ fn test_gnu_args_err() {
47674807 . fails_with_code ( 1 )
47684808 . no_stdout ( )
47694809 . stderr_is ( "tail: option used in invalid context -- 2\n " ) ;
4770- // err-5
4810+ // err-5: large numbers now clamp to u64::MAX
47714811 scene
47724812 . ucmd ( )
47734813 . arg ( "-c99999999999999999999" )
4774- . fails_with_code ( 1 )
4775- . no_stdout ( )
4776- . stderr_is ( "tail: invalid number of bytes: '99999999999999999999' \n ") ;
4814+ . pipe_in ( "x" )
4815+ . succeeds ( )
4816+ . stdout_is ( "x ") ;
47774817 // err-6
47784818 scene
47794819 . ucmd ( )
@@ -4787,20 +4827,19 @@ fn test_gnu_args_err() {
47874827 . fails_with_code ( 1 )
47884828 . no_stdout ( )
47894829 . stderr_is ( "tail: option used in invalid context -- 5\n " ) ;
4830+ // Large obsolete-syntax numbers clamp to u64::MAX
47904831 scene
47914832 . ucmd ( )
47924833 . arg ( "-9999999999999999999b" )
4793- . fails_with_code ( 1 )
4794- . no_stdout ( )
4795- . stderr_is ( "tail: invalid number: '-9999999999999999999b' \n ") ;
4834+ . pipe_in ( "x" )
4835+ . succeeds ( )
4836+ . stdout_is ( "x ") ;
47964837 scene
47974838 . ucmd ( )
47984839 . arg ( "-999999999999999999999b" )
4799- . fails_with_code ( 1 )
4800- . no_stdout ( )
4801- . stderr_is (
4802- "tail: invalid number: '-999999999999999999999b': Numerical result out of range\n " ,
4803- ) ;
4840+ . pipe_in ( "x" )
4841+ . succeeds ( )
4842+ . stdout_is ( "x" ) ;
48044843}
48054844
48064845#[ test]
0 commit comments