@@ -4,15 +4,23 @@ use super::{Command, Output, Stdio};
44use crate :: io:: ErrorKind ;
55use crate :: str;
66
7- // FIXME(#10380) these tests should not all be ignored on android.
7+ #[ cfg( target_os = "android" ) ]
8+ fn shell_cmd ( ) -> Command {
9+ Command :: new ( "/system/bin/sh" )
10+ }
11+
12+ #[ cfg( not( target_os = "android" ) ) ]
13+ fn shell_cmd ( ) -> Command {
14+ Command :: new ( "/bin/sh" )
15+ }
816
917#[ test]
10- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
18+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
1119fn smoke ( ) {
1220 let p = if cfg ! ( target_os = "windows" ) {
1321 Command :: new ( "cmd" ) . args ( & [ "/C" , "exit 0" ] ) . spawn ( )
1422 } else {
15- Command :: new ( "true" ) . spawn ( )
23+ shell_cmd ( ) . arg ( "-c" ) . arg ( "true" ) . spawn ( )
1624 } ;
1725 assert ! ( p. is_ok( ) ) ;
1826 let mut p = p. unwrap ( ) ;
@@ -29,12 +37,12 @@ fn smoke_failure() {
2937}
3038
3139#[ test]
32- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
40+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
3341fn exit_reported_right ( ) {
3442 let p = if cfg ! ( target_os = "windows" ) {
3543 Command :: new ( "cmd" ) . args ( & [ "/C" , "exit 1" ] ) . spawn ( )
3644 } else {
37- Command :: new ( "false" ) . spawn ( )
45+ shell_cmd ( ) . arg ( "-c" ) . arg ( "false" ) . spawn ( )
3846 } ;
3947 assert ! ( p. is_ok( ) ) ;
4048 let mut p = p. unwrap ( ) ;
@@ -44,12 +52,11 @@ fn exit_reported_right() {
4452
4553#[ test]
4654#[ cfg( unix) ]
47- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
55+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
4856fn signal_reported_right ( ) {
4957 use crate :: os:: unix:: process:: ExitStatusExt ;
5058
51- let mut p =
52- Command :: new ( "/bin/sh" ) . arg ( "-c" ) . arg ( "read a" ) . stdin ( Stdio :: piped ( ) ) . spawn ( ) . unwrap ( ) ;
59+ let mut p = shell_cmd ( ) . arg ( "-c" ) . arg ( "read a" ) . stdin ( Stdio :: piped ( ) ) . spawn ( ) . unwrap ( ) ;
5360 p. kill ( ) . unwrap ( ) ;
5461 match p. wait ( ) . unwrap ( ) . signal ( ) {
5562 Some ( 9 ) => { }
@@ -69,31 +76,31 @@ pub fn run_output(mut cmd: Command) -> String {
6976}
7077
7178#[ test]
72- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
79+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
7380fn stdout_works ( ) {
7481 if cfg ! ( target_os = "windows" ) {
7582 let mut cmd = Command :: new ( "cmd" ) ;
7683 cmd. args ( & [ "/C" , "echo foobar" ] ) . stdout ( Stdio :: piped ( ) ) ;
7784 assert_eq ! ( run_output( cmd) , "foobar\r \n " ) ;
7885 } else {
79- let mut cmd = Command :: new ( "echo" ) ;
80- cmd. arg ( "foobar" ) . stdout ( Stdio :: piped ( ) ) ;
86+ let mut cmd = shell_cmd ( ) ;
87+ cmd. arg ( "-c" ) . arg ( "echo foobar") . stdout ( Stdio :: piped ( ) ) ;
8188 assert_eq ! ( run_output( cmd) , "foobar\n " ) ;
8289 }
8390}
8491
8592#[ test]
86- #[ cfg_attr( any( windows, target_os = "android" , target_os = " vxworks") , ignore) ]
93+ #[ cfg_attr( any( windows, target_os = "vxworks" ) , ignore) ]
8794fn set_current_dir_works ( ) {
88- let mut cmd = Command :: new ( "/bin/sh" ) ;
95+ let mut cmd = shell_cmd ( ) ;
8996 cmd. arg ( "-c" ) . arg ( "pwd" ) . current_dir ( "/" ) . stdout ( Stdio :: piped ( ) ) ;
9097 assert_eq ! ( run_output( cmd) , "/\n " ) ;
9198}
9299
93100#[ test]
94- #[ cfg_attr( any( windows, target_os = "android" , target_os = " vxworks") , ignore) ]
101+ #[ cfg_attr( any( windows, target_os = "vxworks" ) , ignore) ]
95102fn stdin_works ( ) {
96- let mut p = Command :: new ( "/bin/sh" )
103+ let mut p = shell_cmd ( )
97104 . arg ( "-c" )
98105 . arg ( "read line; echo $line" )
99106 . stdin ( Stdio :: piped ( ) )
@@ -109,19 +116,19 @@ fn stdin_works() {
109116}
110117
111118#[ test]
112- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
119+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
113120fn test_process_status ( ) {
114121 let mut status = if cfg ! ( target_os = "windows" ) {
115122 Command :: new ( "cmd" ) . args ( & [ "/C" , "exit 1" ] ) . status ( ) . unwrap ( )
116123 } else {
117- Command :: new ( "false" ) . status ( ) . unwrap ( )
124+ shell_cmd ( ) . arg ( "-c" ) . arg ( "false" ) . status ( ) . unwrap ( )
118125 } ;
119126 assert ! ( status. code( ) == Some ( 1 ) ) ;
120127
121128 status = if cfg ! ( target_os = "windows" ) {
122129 Command :: new ( "cmd" ) . args ( & [ "/C" , "exit 0" ] ) . status ( ) . unwrap ( )
123130 } else {
124- Command :: new ( "true" ) . status ( ) . unwrap ( )
131+ shell_cmd ( ) . arg ( "-c" ) . arg ( "true" ) . status ( ) . unwrap ( )
125132 } ;
126133 assert ! ( status. success( ) ) ;
127134}
@@ -135,12 +142,12 @@ fn test_process_output_fail_to_start() {
135142}
136143
137144#[ test]
138- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
145+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
139146fn test_process_output_output ( ) {
140147 let Output { status, stdout, stderr } = if cfg ! ( target_os = "windows" ) {
141148 Command :: new ( "cmd" ) . args ( & [ "/C" , "echo hello" ] ) . output ( ) . unwrap ( )
142149 } else {
143- Command :: new ( "echo ") . arg ( "hello" ) . output ( ) . unwrap ( )
150+ shell_cmd ( ) . arg ( "-c ") . arg ( "echo hello" ) . output ( ) . unwrap ( )
144151 } ;
145152 let output_str = str:: from_utf8 ( & stdout) . unwrap ( ) ;
146153
@@ -150,49 +157,50 @@ fn test_process_output_output() {
150157}
151158
152159#[ test]
153- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
160+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
154161fn test_process_output_error ( ) {
155162 let Output { status, stdout, stderr } = if cfg ! ( target_os = "windows" ) {
156163 Command :: new ( "cmd" ) . args ( & [ "/C" , "mkdir ." ] ) . output ( ) . unwrap ( )
157164 } else {
158165 Command :: new ( "mkdir" ) . arg ( "./" ) . output ( ) . unwrap ( )
159166 } ;
160167
161- assert ! ( status. code( ) == Some ( 1 ) ) ;
168+ assert ! ( status. code( ) . is_some( ) ) ;
169+ assert ! ( status. code( ) != Some ( 0 ) ) ;
162170 assert_eq ! ( stdout, Vec :: new( ) ) ;
163171 assert ! ( !stderr. is_empty( ) ) ;
164172}
165173
166174#[ test]
167- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
175+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
168176fn test_finish_once ( ) {
169177 let mut prog = if cfg ! ( target_os = "windows" ) {
170178 Command :: new ( "cmd" ) . args ( & [ "/C" , "exit 1" ] ) . spawn ( ) . unwrap ( )
171179 } else {
172- Command :: new ( "false" ) . spawn ( ) . unwrap ( )
180+ shell_cmd ( ) . arg ( "-c" ) . arg ( "false" ) . spawn ( ) . unwrap ( )
173181 } ;
174182 assert ! ( prog. wait( ) . unwrap( ) . code( ) == Some ( 1 ) ) ;
175183}
176184
177185#[ test]
178- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
186+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
179187fn test_finish_twice ( ) {
180188 let mut prog = if cfg ! ( target_os = "windows" ) {
181189 Command :: new ( "cmd" ) . args ( & [ "/C" , "exit 1" ] ) . spawn ( ) . unwrap ( )
182190 } else {
183- Command :: new ( "false" ) . spawn ( ) . unwrap ( )
191+ shell_cmd ( ) . arg ( "-c" ) . arg ( "false" ) . spawn ( ) . unwrap ( )
184192 } ;
185193 assert ! ( prog. wait( ) . unwrap( ) . code( ) == Some ( 1 ) ) ;
186194 assert ! ( prog. wait( ) . unwrap( ) . code( ) == Some ( 1 ) ) ;
187195}
188196
189197#[ test]
190- #[ cfg_attr( any( target_os = "vxworks" , target_os = "android" ) , ignore) ]
198+ #[ cfg_attr( any( target_os = "vxworks" ) , ignore) ]
191199fn test_wait_with_output_once ( ) {
192200 let prog = if cfg ! ( target_os = "windows" ) {
193201 Command :: new ( "cmd" ) . args ( & [ "/C" , "echo hello" ] ) . stdout ( Stdio :: piped ( ) ) . spawn ( ) . unwrap ( )
194202 } else {
195- Command :: new ( "echo ") . arg ( "hello" ) . stdout ( Stdio :: piped ( ) ) . spawn ( ) . unwrap ( )
203+ shell_cmd ( ) . arg ( "-c ") . arg ( "echo hello" ) . stdout ( Stdio :: piped ( ) ) . spawn ( ) . unwrap ( )
196204 } ;
197205
198206 let Output { status, stdout, stderr } = prog. wait_with_output ( ) . unwrap ( ) ;
0 commit comments