22//
33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
5- #![ allow( unused_imports) ]
6- mod common;
7-
8- use common:: util:: TestScenario ;
5+ use uutests:: util:: TestScenario ;
96
107#[ cfg( unix) ]
118use std:: os:: unix:: fs:: symlink as symlink_file;
12- #[ cfg( windows) ]
13- use std:: os:: windows:: fs:: symlink_file;
149
1510#[ test]
1611#[ cfg( feature = "ls" ) ]
1712fn execution_phrase_double ( ) {
1813 use std:: process:: Command ;
1914
2015 let scenario = TestScenario :: new ( "ls" ) ;
16+ println ! ( "scenario.bin_path: {:?}" , scenario. bin_path) ;
17+ if !scenario. bin_path . exists ( ) {
18+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
19+ return ;
20+ }
2121 let output = Command :: new ( & scenario. bin_path )
2222 . arg ( "ls" )
2323 . arg ( "--some-invalid-arg" )
@@ -28,25 +28,6 @@ fn execution_phrase_double() {
2828 . contains( & format!( "Usage: {} ls" , scenario. bin_path. display( ) , ) ) ) ;
2929}
3030
31- #[ test]
32- #[ cfg( feature = "ls" ) ]
33- #[ cfg( any( unix, windows) ) ]
34- fn execution_phrase_single ( ) {
35- use std:: process:: Command ;
36-
37- let scenario = TestScenario :: new ( "ls" ) ;
38- symlink_file ( & scenario. bin_path , scenario. fixtures . plus ( "uu-ls" ) ) . unwrap ( ) ;
39- let output = Command :: new ( scenario. fixtures . plus ( "uu-ls" ) )
40- . arg ( "--some-invalid-arg" )
41- . output ( )
42- . unwrap ( ) ;
43- dbg ! ( String :: from_utf8( output. stderr. clone( ) ) . unwrap( ) ) ;
44- assert ! ( String :: from_utf8( output. stderr) . unwrap( ) . contains( & format!(
45- "Usage: {}" ,
46- scenario. fixtures. plus( "uu-ls" ) . display( )
47- ) ) ) ;
48- }
49-
5031#[ test]
5132#[ cfg( feature = "sort" ) ]
5233fn util_name_double ( ) {
@@ -56,6 +37,11 @@ fn util_name_double() {
5637 } ;
5738
5839 let scenario = TestScenario :: new ( "sort" ) ;
40+ println ! ( "scenario.bin_path: {:?}" , scenario. bin_path) ;
41+ if !scenario. bin_path . exists ( ) {
42+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
43+ return ;
44+ }
5945 let mut child = Command :: new ( & scenario. bin_path )
6046 . arg ( "sort" )
6147 . stdin ( Stdio :: piped ( ) )
@@ -65,19 +51,25 @@ fn util_name_double() {
6551 // input invalid utf8 to cause an error
6652 child. stdin . take ( ) . unwrap ( ) . write_all ( & [ 255 ] ) . unwrap ( ) ;
6753 let output = child. wait_with_output ( ) . unwrap ( ) ;
54+ println ! ( "output.stderr = {:?}" , output. stderr) ;
6855 assert ! ( String :: from_utf8( output. stderr) . unwrap( ) . contains( "sort: " ) ) ;
6956}
7057
7158#[ test]
7259#[ cfg( feature = "sort" ) ]
73- #[ cfg( any ( unix, windows ) ) ]
60+ #[ cfg( unix) ]
7461fn util_name_single ( ) {
7562 use std:: {
7663 io:: Write ,
7764 process:: { Command , Stdio } ,
7865 } ;
7966
8067 let scenario = TestScenario :: new ( "sort" ) ;
68+ if !scenario. bin_path . exists ( ) {
69+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
70+ return ;
71+ }
72+
8173 symlink_file ( & scenario. bin_path , scenario. fixtures . plus ( "uu-sort" ) ) . unwrap ( ) ;
8274 let mut child = Command :: new ( scenario. fixtures . plus ( "uu-sort" ) )
8375 . stdin ( Stdio :: piped ( ) )
@@ -94,14 +86,15 @@ fn util_name_single() {
9486}
9587
9688#[ test]
97- #[ cfg( any ( unix, windows ) ) ]
89+ #[ cfg( unix) ]
9890fn util_invalid_name_help ( ) {
99- use std:: {
100- io:: Write ,
101- process:: { Command , Stdio } ,
102- } ;
91+ use std:: process:: { Command , Stdio } ;
10392
10493 let scenario = TestScenario :: new ( "invalid_name" ) ;
94+ if !scenario. bin_path . exists ( ) {
95+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
96+ return ;
97+ }
10598 symlink_file ( & scenario. bin_path , scenario. fixtures . plus ( "invalid_name" ) ) . unwrap ( ) ;
10699 let child = Command :: new ( scenario. fixtures . plus ( "invalid_name" ) )
107100 . arg ( "--help" )
@@ -130,14 +123,17 @@ fn util_non_utf8_name_help() {
130123 // Make sure we don't crash even if the util name is invalid UTF-8.
131124 use std:: {
132125 ffi:: OsStr ,
133- io:: Write ,
134126 os:: unix:: ffi:: OsStrExt ,
135- path:: Path ,
136127 process:: { Command , Stdio } ,
137128 } ;
138129
139130 let scenario = TestScenario :: new ( "invalid_name" ) ;
140131 let non_utf8_path = scenario. fixtures . plus ( OsStr :: from_bytes ( b"\xff " ) ) ;
132+ if !scenario. bin_path . exists ( ) {
133+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
134+ return ;
135+ }
136+
141137 symlink_file ( & scenario. bin_path , & non_utf8_path) . unwrap ( ) ;
142138 let child = Command :: new ( & non_utf8_path)
143139 . arg ( "--help" )
@@ -158,15 +154,17 @@ fn util_non_utf8_name_help() {
158154}
159155
160156#[ test]
161- #[ cfg( any ( unix, windows ) ) ]
157+ #[ cfg( unix) ]
162158fn util_invalid_name_invalid_command ( ) {
163- use std:: {
164- io:: Write ,
165- process:: { Command , Stdio } ,
166- } ;
159+ use std:: process:: { Command , Stdio } ;
167160
168161 let scenario = TestScenario :: new ( "invalid_name" ) ;
169162 symlink_file ( & scenario. bin_path , scenario. fixtures . plus ( "invalid_name" ) ) . unwrap ( ) ;
163+ if !scenario. bin_path . exists ( ) {
164+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
165+ return ;
166+ }
167+
170168 let child = Command :: new ( scenario. fixtures . plus ( "invalid_name" ) )
171169 . arg ( "definitely_invalid" )
172170 . stdin ( Stdio :: piped ( ) )
@@ -186,12 +184,15 @@ fn util_invalid_name_invalid_command() {
186184#[ test]
187185#[ cfg( feature = "true" ) ]
188186fn util_completion ( ) {
189- use std:: {
190- io:: Write ,
191- process:: { Command , Stdio } ,
192- } ;
187+ use std:: process:: { Command , Stdio } ;
193188
194189 let scenario = TestScenario :: new ( "completion" ) ;
190+ println ! ( "scenario.bin_path: {:?}" , scenario. bin_path) ;
191+ if !scenario. bin_path . exists ( ) {
192+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
193+ return ;
194+ }
195+
195196 let child = Command :: new ( & scenario. bin_path )
196197 . arg ( "completion" )
197198 . arg ( "true" )
@@ -214,12 +215,15 @@ fn util_completion() {
214215#[ test]
215216#[ cfg( feature = "true" ) ]
216217fn util_manpage ( ) {
217- use std:: {
218- io:: Write ,
219- process:: { Command , Stdio } ,
220- } ;
218+ use std:: process:: { Command , Stdio } ;
221219
222220 let scenario = TestScenario :: new ( "completion" ) ;
221+ println ! ( "scenario.bin_path: {:?}" , scenario. bin_path) ;
222+ if !scenario. bin_path . exists ( ) {
223+ println ! ( "Skipping test: Binary not found at {:?}" , scenario. bin_path) ;
224+ return ;
225+ }
226+
223227 let child = Command :: new ( & scenario. bin_path )
224228 . arg ( "manpage" )
225229 . arg ( "true" )
0 commit comments