@@ -55,11 +55,10 @@ fn test_help() {
5555#[ test]
5656#[ cfg( target_os = "linux" ) ]
5757fn test_oldest ( ) {
58+ let re = & Regex :: new ( SINGLE_PID ) . unwrap ( ) ;
59+
5860 for arg in [ "-o" , "--oldest" ] {
59- new_ucmd ! ( )
60- . arg ( arg)
61- . succeeds ( )
62- . stdout_matches ( & Regex :: new ( SINGLE_PID ) . unwrap ( ) ) ;
61+ new_ucmd ! ( ) . arg ( arg) . succeeds ( ) . stdout_matches ( re) ;
6362 }
6463}
6564
@@ -77,11 +76,10 @@ fn test_oldest_non_matching_pattern() {
7776#[ test]
7877#[ cfg( target_os = "linux" ) ]
7978fn test_newest ( ) {
79+ let re = & Regex :: new ( SINGLE_PID ) . unwrap ( ) ;
80+
8081 for arg in [ "-n" , "--newest" ] {
81- new_ucmd ! ( )
82- . arg ( arg)
83- . succeeds ( )
84- . stdout_matches ( & Regex :: new ( SINGLE_PID ) . unwrap ( ) ) ;
82+ new_ucmd ! ( ) . arg ( arg) . succeeds ( ) . stdout_matches ( re) ;
8583 }
8684}
8785
@@ -99,12 +97,10 @@ fn test_newest_non_matching_pattern() {
9997#[ test]
10098#[ cfg( target_os = "linux" ) ]
10199fn test_older ( ) {
100+ let re = & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ;
101+
102102 for arg in [ "-O" , "--older" ] {
103- new_ucmd ! ( )
104- . arg ( arg)
105- . arg ( "0" )
106- . succeeds ( )
107- . stdout_matches ( & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ) ;
103+ new_ucmd ! ( ) . arg ( arg) . arg ( "0" ) . succeeds ( ) . stdout_matches ( re) ;
108104 }
109105}
110106
@@ -199,13 +195,16 @@ fn test_ignore_case() {
199195#[ test]
200196#[ cfg( target_os = "linux" ) ]
201197fn test_list_full ( ) {
198+ // (?m) enables multi-line mode
199+ let re = & Regex :: new ( "(?m)^[1-9][0-9]* .+$" ) . unwrap ( ) ;
200+
202201 for arg in [ "-a" , "--list-full" ] {
203202 new_ucmd ! ( )
204203 . arg ( "sh" )
205204 . arg ( arg)
206205 . succeeds ( )
207206 // (?m) enables multi-line mode
208- . stdout_matches ( & Regex :: new ( "(?m)^[1-9][0-9]* .+$" ) . unwrap ( ) ) ;
207+ . stdout_matches ( re ) ;
209208 }
210209}
211210
@@ -246,13 +245,15 @@ fn test_count_with_non_matching_pattern() {
246245#[ test]
247246#[ cfg( target_os = "linux" ) ]
248247fn test_terminal ( ) {
248+ let re = & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ;
249+
249250 for arg in [ "-t" , "--terminal" ] {
250251 new_ucmd ! ( )
251252 . arg ( arg)
252253 . arg ( "tty1" )
253254 . arg ( "--inverse" ) // XXX hack to make test pass in CI
254255 . succeeds ( )
255- . stdout_matches ( & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ) ;
256+ . stdout_matches ( re ) ;
256257 }
257258}
258259
@@ -286,12 +287,10 @@ fn test_terminal_invalid_terminal() {
286287#[ test]
287288#[ cfg( target_os = "linux" ) ]
288289fn test_runstates ( ) {
290+ let re = & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ;
291+
289292 for arg in [ "-r" , "--runstates" ] {
290- new_ucmd ! ( )
291- . arg ( arg)
292- . arg ( "S" )
293- . succeeds ( )
294- . stdout_matches ( & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ) ;
293+ new_ucmd ! ( ) . arg ( arg) . arg ( "S" ) . succeeds ( ) . stdout_matches ( re) ;
295294 }
296295}
297296
@@ -308,12 +307,10 @@ fn test_runstates_invalid_runstate() {
308307#[ test]
309308#[ cfg( target_os = "linux" ) ]
310309fn test_parent ( ) {
310+ let re = & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ;
311+
311312 for arg in [ "-P" , "--parent" ] {
312- new_ucmd ! ( )
313- . arg ( arg)
314- . arg ( "0" )
315- . succeeds ( )
316- . stdout_matches ( & Regex :: new ( MULTIPLE_PIDS ) . unwrap ( ) ) ;
313+ new_ucmd ! ( ) . arg ( arg) . arg ( "0" ) . succeeds ( ) . stdout_matches ( re) ;
317314 }
318315}
319316
0 commit comments