@@ -12,6 +12,44 @@ fn generate(from: u32, to: u32) -> String {
1212 ( from..to) . fold ( String :: new ( ) , |acc, v| format ! ( "{acc}{v}\n " ) )
1313}
1414
15+ #[ test]
16+ fn test_line_numbers_suppress_matched_final_empty ( ) {
17+ // Repro for #7286
18+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
19+ ucmd. args ( & [ "--suppress-matched" , "-" , "2" , "4" , "6" ] ) // stdin, split at 2/4/6
20+ . pipe_in ( "1\n 2\n 3\n 4\n 5\n 6\n " )
21+ . succeeds ( )
22+ . stdout_only ( "2\n 2\n 2\n 0\n " ) ;
23+
24+ // Expect four files: xx00:"1\n", xx01:"3\n", xx02:"5\n", xx03:""
25+ let count = glob ( & at. plus_as_string ( "xx*" ) )
26+ . expect ( "there should be splits created" )
27+ . count ( ) ;
28+ assert_eq ! ( count, 4 ) ;
29+ assert_eq ! ( at. read( "xx00" ) , "1\n " ) ;
30+ assert_eq ! ( at. read( "xx01" ) , "3\n " ) ;
31+ assert_eq ! ( at. read( "xx02" ) , "5\n " ) ;
32+ assert_eq ! ( at. read( "xx03" ) , "" ) ;
33+ }
34+
35+ #[ test]
36+ fn test_line_numbers_suppress_matched_final_empty_elided_with_z ( ) {
37+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
38+ ucmd. args ( & [ "--suppress-matched" , "-z" , "-" , "2" , "4" , "6" ] ) // elide empty
39+ . pipe_in ( "1\n 2\n 3\n 4\n 5\n 6\n " )
40+ . succeeds ( )
41+ . stdout_only ( "2\n 2\n 2\n " ) ;
42+
43+ // Expect three files: xx00:"1\n", xx01:"3\n", xx02:"5\n"
44+ let count = glob ( & at. plus_as_string ( "xx*" ) )
45+ . expect ( "there should be splits created" )
46+ . count ( ) ;
47+ assert_eq ! ( count, 3 ) ;
48+ assert_eq ! ( at. read( "xx00" ) , "1\n " ) ;
49+ assert_eq ! ( at. read( "xx01" ) , "3\n " ) ;
50+ assert_eq ! ( at. read( "xx02" ) , "5\n " ) ;
51+ }
52+
1553#[ test]
1654fn test_invalid_arg ( ) {
1755 new_ucmd ! ( ) . arg ( "--definitely-invalid" ) . fails_with_code ( 1 ) ;
0 commit comments