22//
33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
5+
56use std:: io:: IsTerminal ;
6- #[ cfg( target_family = "unix" ) ]
7- use uutests:: at_and_ucmd;
8- use uutests:: new_ucmd;
9- use uutests:: util:: TestScenario ;
10- use uutests:: util_name;
117
8+ use uutests:: { at_and_ucmd, new_ucmd, util:: TestScenario , util_name} ;
9+
10+ #[ cfg( unix) ]
1211#[ test]
13- fn test_more_no_arg ( ) {
12+ fn test_no_arg ( ) {
1413 if std:: io:: stdout ( ) . is_terminal ( ) {
15- new_ucmd ! ( ) . fails ( ) . stderr_contains ( "more: bad usage" ) ;
14+ new_ucmd ! ( )
15+ . terminal_simulation ( true )
16+ . fails ( )
17+ . stderr_contains ( "more: bad usage" ) ;
1618 }
1719}
1820
1921#[ test]
2022fn test_valid_arg ( ) {
2123 if std:: io:: stdout ( ) . is_terminal ( ) {
22- let scene = TestScenario :: new ( util_name ! ( ) ) ;
23- let at = & scene. fixtures ;
24-
25- let file = "test_file" ;
26- at. touch ( file) ;
27-
28- scene. ucmd ( ) . arg ( file) . arg ( "-c" ) . succeeds ( ) ;
29- scene. ucmd ( ) . arg ( file) . arg ( "--print-over" ) . succeeds ( ) ;
30-
31- scene. ucmd ( ) . arg ( file) . arg ( "-p" ) . succeeds ( ) ;
32- scene. ucmd ( ) . arg ( file) . arg ( "--clean-print" ) . succeeds ( ) ;
33-
34- scene. ucmd ( ) . arg ( file) . arg ( "-s" ) . succeeds ( ) ;
35- scene. ucmd ( ) . arg ( file) . arg ( "--squeeze" ) . succeeds ( ) ;
36-
37- scene. ucmd ( ) . arg ( file) . arg ( "-u" ) . succeeds ( ) ;
38- scene. ucmd ( ) . arg ( file) . arg ( "--plain" ) . succeeds ( ) ;
39-
40- scene. ucmd ( ) . arg ( file) . arg ( "-n" ) . arg ( "10" ) . succeeds ( ) ;
41- scene. ucmd ( ) . arg ( file) . arg ( "--lines" ) . arg ( "0" ) . succeeds ( ) ;
42- scene. ucmd ( ) . arg ( file) . arg ( "--number" ) . arg ( "0" ) . succeeds ( ) ;
24+ let args_list: Vec < & [ & str ] > = vec ! [
25+ & [ "-c" ] ,
26+ & [ "--clean-print" ] ,
27+ & [ "-p" ] ,
28+ & [ "--print-over" ] ,
29+ & [ "-s" ] ,
30+ & [ "--squeeze" ] ,
31+ & [ "-u" ] ,
32+ & [ "--plain" ] ,
33+ & [ "-n" , "10" ] ,
34+ & [ "--lines" , "0" ] ,
35+ & [ "--number" , "0" ] ,
36+ & [ "-F" , "10" ] ,
37+ & [ "--from-line" , "0" ] ,
38+ & [ "-P" , "something" ] ,
39+ & [ "--pattern" , "-1" ] ,
40+ ] ;
41+ for args in args_list {
42+ test_alive ( args) ;
43+ }
44+ }
45+ }
4346
44- scene. ucmd ( ) . arg ( file) . arg ( "-F" ) . arg ( "10" ) . succeeds ( ) ;
45- scene
46- . ucmd ( )
47- . arg ( file)
48- . arg ( "--from-line" )
49- . arg ( "0" )
50- . succeeds ( ) ;
47+ fn test_alive ( args : & [ & str ] ) {
48+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
49+ let file = "test_file" ;
50+ at. touch ( file) ;
5151
52- scene. ucmd ( ) . arg ( file) . arg ( "-P" ) . arg ( "something" ) . succeeds ( ) ;
53- scene. ucmd ( ) . arg ( file) . arg ( "--pattern" ) . arg ( "-1" ) . succeeds ( ) ;
54- }
52+ ucmd. args ( args)
53+ . arg ( file)
54+ . run_no_wait ( )
55+ . make_assertion ( )
56+ . is_alive ( ) ;
5557}
5658
5759#[ test]
@@ -67,101 +69,32 @@ fn test_invalid_arg() {
6769}
6870
6971#[ test]
70- fn test_argument_from_file ( ) {
71- if std:: io:: stdout ( ) . is_terminal ( ) {
72- let scene = TestScenario :: new ( util_name ! ( ) ) ;
73- let at = & scene. fixtures ;
74-
75- let file = "test_file" ;
76-
77- at. write ( file, "1\n 2" ) ;
78-
79- // output all lines
80- scene
81- . ucmd ( )
82- . arg ( "-F" )
83- . arg ( "0" )
84- . arg ( file)
85- . succeeds ( )
86- . no_stderr ( )
87- . stdout_contains ( "1" )
88- . stdout_contains ( "2" ) ;
89-
90- // output only the second line
91- scene
92- . ucmd ( )
93- . arg ( "-F" )
94- . arg ( "2" )
95- . arg ( file)
96- . succeeds ( )
97- . no_stderr ( )
98- . stdout_contains ( "2" )
99- . stdout_does_not_contain ( "1" ) ;
100- }
101- }
102-
103- #[ test]
104- fn test_more_dir_arg ( ) {
72+ fn test_file_arg ( ) {
10573 // Run the test only if there's a valid terminal, else do nothing
10674 // Maybe we could capture the error, i.e. "Device not found" in that case
10775 // but I am leaving this for later
10876 if std:: io:: stdout ( ) . is_terminal ( ) {
109- new_ucmd ! ( )
110- . arg ( "." )
77+ // Directory as argument
78+ let mut ucmd = TestScenario :: new ( util_name ! ( ) ) . ucmd ( ) ;
79+ ucmd. arg ( "." )
11180 . succeeds ( )
11281 . stderr_contains ( "'.' is a directory." ) ;
113- }
114- }
115-
116- #[ test]
117- #[ cfg( target_family = "unix" ) ]
118- fn test_more_invalid_file_perms ( ) {
119- use std:: fs:: { Permissions , set_permissions} ;
120- use std:: os:: unix:: fs:: PermissionsExt ;
12182
122- if std :: io :: stdout ( ) . is_terminal ( ) {
83+ // Single argument errors
12384 let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
124- let permissions = Permissions :: from_mode ( 0o244 ) ;
125- at. make_file ( "invalid-perms.txt" ) ;
126- set_permissions ( at. plus ( "invalid-perms.txt" ) , permissions) . unwrap ( ) ;
127- ucmd. arg ( "invalid-perms.txt" )
128- . succeeds ( )
129- . stderr_contains ( "permission denied" ) ;
130- }
131- }
132-
133- #[ test]
134- fn test_more_error_on_single_arg ( ) {
135- if std:: io:: stdout ( ) . is_terminal ( ) {
136- let ts = TestScenario :: new ( "more" ) ;
137- ts. fixtures . mkdir_all ( "folder" ) ;
138- ts. ucmd ( )
139- . arg ( "folder" )
85+ at. mkdir_all ( "folder" ) ;
86+ ucmd. arg ( "folder" )
14087 . succeeds ( )
14188 . stderr_contains ( "is a directory" ) ;
142- ts. ucmd ( )
143- . arg ( "file1" )
89+
90+ ucmd = TestScenario :: new ( util_name ! ( ) ) . ucmd ( ) ;
91+ ucmd. arg ( "nonexistent_file" )
14492 . succeeds ( )
14593 . stderr_contains ( "No such file or directory" ) ;
146- }
147- }
14894
149- #[ test]
150- fn test_more_error_on_multiple_files ( ) {
151- if std:: io:: stdout ( ) . is_terminal ( ) {
152- let ts = TestScenario :: new ( "more" ) ;
153- ts. fixtures . mkdir_all ( "folder" ) ;
154- ts. fixtures . make_file ( "file1" ) ;
155- ts. ucmd ( )
156- . arg ( "folder" )
157- . arg ( "file2" )
158- . arg ( "file1" )
159- . succeeds ( )
160- . stderr_contains ( "folder" )
161- . stderr_contains ( "file2" )
162- . stdout_contains ( "file1" ) ;
163- ts. ucmd ( )
164- . arg ( "file2" )
95+ // Multiple nonexistent files
96+ ucmd = TestScenario :: new ( util_name ! ( ) ) . ucmd ( ) ;
97+ ucmd. arg ( "file2" )
16598 . arg ( "file3" )
16699 . succeeds ( )
167100 . stderr_contains ( "file2" )
@@ -170,48 +103,18 @@ fn test_more_error_on_multiple_files() {
170103}
171104
172105#[ test]
173- fn test_more_pattern_found ( ) {
174- if std:: io:: stdout ( ) . is_terminal ( ) {
175- let scene = TestScenario :: new ( util_name ! ( ) ) ;
176- let at = & scene. fixtures ;
177-
178- let file = "test_file" ;
179-
180- at. write ( file, "line1\n line2" ) ;
181-
182- // output only the second line "line2"
183- scene
184- . ucmd ( )
185- . arg ( "-P" )
186- . arg ( "line2" )
187- . arg ( file)
188- . succeeds ( )
189- . no_stderr ( )
190- . stdout_does_not_contain ( "line1" )
191- . stdout_contains ( "line2" ) ;
192- }
193- }
194-
195- #[ test]
196- fn test_more_pattern_not_found ( ) {
106+ #[ cfg( target_family = "unix" ) ]
107+ fn test_invalid_file_perms ( ) {
197108 if std:: io:: stdout ( ) . is_terminal ( ) {
198- let scene = TestScenario :: new ( util_name ! ( ) ) ;
199- let at = & scene . fixtures ;
109+ use std :: fs :: { Permissions , set_permissions } ;
110+ use std :: os :: unix :: fs :: PermissionsExt ;
200111
201- let file = "test_file" ;
202-
203- let file_content = "line1\n line2" ;
204- at. write ( file, file_content) ;
205-
206- scene
207- . ucmd ( )
208- . arg ( "-P" )
209- . arg ( "something" )
210- . arg ( file)
112+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
113+ let permissions = Permissions :: from_mode ( 0o244 ) ;
114+ at. make_file ( "invalid-perms.txt" ) ;
115+ set_permissions ( at. plus ( "invalid-perms.txt" ) , permissions) . unwrap ( ) ;
116+ ucmd. arg ( "invalid-perms.txt" )
211117 . succeeds ( )
212- . no_stderr ( )
213- . stdout_contains ( "Pattern not found" )
214- . stdout_contains ( "line1" )
215- . stdout_contains ( "line2" ) ;
118+ . stderr_contains ( "permission denied" ) ;
216119 }
217120}
0 commit comments