@@ -943,12 +943,20 @@ mod tests {
943
943
}
944
944
945
945
#[ test]
946
+ #[ cfg( not( target_os="android" ) ) ]
946
947
fn test_process_status( ) {
947
948
assert_eq!( run:: process_status( "false" , [ ] ) , 1 ) ;
948
949
assert_eq!( run:: process_status( "true" , [ ] ) , 0 ) ;
949
950
}
951
+ #[ test]
952
+ #[ cfg( target_os="android" ) ]
953
+ fn test_process_status( ) {
954
+ assert_eq!( run:: process_status( "/system/bin/sh" , [ ~"-c",~" false "]), 1);
955
+ assert_eq!(run::process_status(" /system/bin/sh", [~" -c",~" true "]), 0);
956
+ }
950
957
951
958
#[test]
959
+ #[cfg(not(target_os=" android"))]
952
960
fn test_process_output_output() {
953
961
954
962
let run::ProcessOutput {status, output, error}
@@ -962,8 +970,24 @@ mod tests {
962
970
assert_eq!(error, ~[]);
963
971
}
964
972
}
973
+ #[test]
974
+ #[cfg(target_os=" android")]
975
+ fn test_process_output_output() {
976
+
977
+ let run::ProcessOutput {status, output, error}
978
+ = run::process_output(" /system/bin/sh", [~" -c",~" echo hello"]);
979
+ let output_str = str::from_bytes(output);
980
+
981
+ assert_eq!(status, 0);
982
+ assert_eq!(output_str.trim().to_owned(), ~" hello");
983
+ // FIXME #7224
984
+ if !running_on_valgrind() {
985
+ assert_eq!(error, ~[]);
986
+ }
987
+ }
965
988
966
989
#[test]
990
+ #[cfg(not(target_os=" android"))]
967
991
fn test_process_output_error() {
968
992
969
993
let run::ProcessOutput {status, output, error}
@@ -973,6 +997,17 @@ mod tests {
973
997
assert_eq!(output, ~[]);
974
998
assert!(!error.is_empty());
975
999
}
1000
+ #[test]
1001
+ #[cfg(target_os=" android")]
1002
+ fn test_process_output_error() {
1003
+
1004
+ let run::ProcessOutput {status, output, error}
1005
+ = run::process_output(" /system/bin/mkdir", [~" . "]);
1006
+
1007
+ assert_eq!(status, 255);
1008
+ assert_eq!(output, ~[]);
1009
+ assert!(!error.is_empty());
1010
+ }
976
1011
977
1012
#[test]
978
1013
fn test_pipes() {
@@ -1023,19 +1058,37 @@ mod tests {
1023
1058
}
1024
1059
1025
1060
#[test]
1061
+ #[cfg(not(target_os=" android"))]
1026
1062
fn test_finish_once() {
1027
1063
let mut prog = run::Process::new(" false ", [], run::ProcessOptions::new());
1028
1064
assert_eq!(prog.finish(), 1);
1029
1065
}
1066
+ #[test]
1067
+ #[cfg(target_os=" android")]
1068
+ fn test_finish_once() {
1069
+ let mut prog = run::Process::new(" /system/bin/sh", [~" -c",~" false "],
1070
+ run::ProcessOptions::new());
1071
+ assert_eq!(prog.finish(), 1);
1072
+ }
1030
1073
1031
1074
#[test]
1075
+ #[cfg(not(target_os=" android"))]
1032
1076
fn test_finish_twice() {
1033
1077
let mut prog = run::Process::new(" false ", [], run::ProcessOptions::new());
1034
1078
assert_eq!(prog.finish(), 1);
1035
1079
assert_eq!(prog.finish(), 1);
1036
1080
}
1081
+ #[test]
1082
+ #[cfg(target_os=" android")]
1083
+ fn test_finish_twice() {
1084
+ let mut prog = run::Process::new(" /system/bin/sh", [~" -c",~" false "],
1085
+ run::ProcessOptions::new());
1086
+ assert_eq!(prog.finish(), 1);
1087
+ assert_eq!(prog.finish(), 1);
1088
+ }
1037
1089
1038
1090
#[test]
1091
+ #[cfg(not(target_os=" android"))]
1039
1092
fn test_finish_with_output_once() {
1040
1093
1041
1094
let mut prog = run::Process::new(" echo", [~" hello"], run::ProcessOptions::new());
@@ -1050,8 +1103,26 @@ mod tests {
1050
1103
assert_eq!(error, ~[]);
1051
1104
}
1052
1105
}
1106
+ #[test]
1107
+ #[cfg(target_os=" android")]
1108
+ fn test_finish_with_output_once() {
1109
+
1110
+ let mut prog = run::Process::new(" /system/bin/sh", [~" -c",~" echo hello"],
1111
+ run::ProcessOptions::new());
1112
+ let run::ProcessOutput {status, output, error}
1113
+ = prog.finish_with_output();
1114
+ let output_str = str::from_bytes(output);
1115
+
1116
+ assert_eq!(status, 0);
1117
+ assert_eq!(output_str.trim().to_owned(), ~" hello");
1118
+ // FIXME #7224
1119
+ if !running_on_valgrind() {
1120
+ assert_eq!(error, ~[]);
1121
+ }
1122
+ }
1053
1123
1054
1124
#[test]
1125
+ #[cfg(not(target_os=" android"))]
1055
1126
fn test_finish_with_output_twice() {
1056
1127
1057
1128
let mut prog = run::Process::new(" echo", [~" hello"], run::ProcessOptions::new());
@@ -1077,10 +1148,38 @@ mod tests {
1077
1148
assert_eq!(error, ~[]);
1078
1149
}
1079
1150
}
1151
+ #[test]
1152
+ #[cfg(target_os=" android")]
1153
+ fn test_finish_with_output_twice() {
1154
+
1155
+ let mut prog = run::Process::new(" /system/bin/sh", [~" -c",~" echo hello"],
1156
+ run::ProcessOptions::new());
1157
+ let run::ProcessOutput {status, output, error}
1158
+ = prog.finish_with_output();
1159
+
1160
+ let output_str = str::from_bytes(output);
1161
+
1162
+ assert_eq!(status, 0);
1163
+ assert_eq!(output_str.trim().to_owned(), ~" hello");
1164
+ // FIXME #7224
1165
+ if !running_on_valgrind() {
1166
+ assert_eq!(error, ~[]);
1167
+ }
1168
+
1169
+ let run::ProcessOutput {status, output, error}
1170
+ = prog.finish_with_output();
1171
+
1172
+ assert_eq!(status, 0);
1173
+ assert_eq!(output, ~[]);
1174
+ // FIXME #7224
1175
+ if !running_on_valgrind() {
1176
+ assert_eq!(error, ~[]);
1177
+ }
1178
+ }
1080
1179
1081
1180
#[test]
1082
1181
#[should_fail]
1083
- #[cfg(not(windows))]
1182
+ #[cfg(not(windows),not(target_os=" android ") )]
1084
1183
fn test_finish_with_output_redirected() {
1085
1184
let mut prog = run::Process::new(" echo", [~" hello"], run::ProcessOptions {
1086
1185
env: None,
@@ -1092,14 +1191,36 @@ mod tests {
1092
1191
// this should fail because it is not valid to read the output when it was redirected
1093
1192
prog.finish_with_output();
1094
1193
}
1194
+ #[test]
1195
+ #[should_fail]
1196
+ #[cfg(not(windows),target_os=" android")]
1197
+ fn test_finish_with_output_redirected() {
1198
+ let mut prog = run::Process::new(" /system/bin/sh", [~" -c",~" echo hello"],
1199
+ run::ProcessOptions {
1200
+ env: None,
1201
+ dir: None,
1202
+ in_fd: Some(0),
1203
+ out_fd: Some(1),
1204
+ err_fd: Some(2)
1205
+ });
1206
+ // this should fail because it is not valid to read the output when it was redirected
1207
+ prog.finish_with_output();
1208
+ }
1095
1209
1096
- #[cfg(unix)]
1210
+ #[cfg(unix,not(target_os=" android ") )]
1097
1211
fn run_pwd(dir: Option<&Path>) -> run::Process {
1098
1212
run::Process::new(" pwd", [], run::ProcessOptions {
1099
1213
dir: dir,
1100
1214
.. run::ProcessOptions::new()
1101
1215
})
1102
1216
}
1217
+ #[cfg(unix,target_os=" android")]
1218
+ fn run_pwd(dir: Option<&Path>) -> run::Process {
1219
+ run::Process::new(" /system/bin/sh", [~" -c",~" pwd"], run::ProcessOptions {
1220
+ dir: dir,
1221
+ .. run::ProcessOptions::new()
1222
+ })
1223
+ }
1103
1224
1104
1225
#[cfg(windows)]
1105
1226
fn run_pwd(dir: Option<&Path>) -> run::Process {
@@ -1141,13 +1262,20 @@ mod tests {
1141
1262
assert_eq!(parent_stat.st_ino, child_stat.st_ino);
1142
1263
}
1143
1264
1144
- #[cfg(unix)]
1265
+ #[cfg(unix,not(target_os=" android ") )]
1145
1266
fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
1146
1267
run::Process::new(" env", [], run::ProcessOptions {
1147
1268
env: env,
1148
1269
.. run::ProcessOptions::new()
1149
1270
})
1150
1271
}
1272
+ #[cfg(unix,target_os=" android")]
1273
+ fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
1274
+ run::Process::new(" /system/bin/sh", [~" -c",~" set"], run::ProcessOptions {
1275
+ env: env,
1276
+ .. run::ProcessOptions::new()
1277
+ })
1278
+ }
1151
1279
1152
1280
#[cfg(windows)]
1153
1281
fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
@@ -1158,6 +1286,7 @@ mod tests {
1158
1286
}
1159
1287
1160
1288
#[test]
1289
+ #[cfg(not(target_os=" android"))]
1161
1290
fn test_inherit_env() {
1162
1291
if running_on_valgrind() { return; }
1163
1292
@@ -1170,6 +1299,23 @@ mod tests {
1170
1299
assert!(k.is_empty() || output.contains(fmt!(" %s=%s", k, v)));
1171
1300
}
1172
1301
}
1302
+ #[test]
1303
+ #[cfg(target_os=" android")]
1304
+ fn test_inherit_env() {
1305
+ if running_on_valgrind() { return; }
1306
+
1307
+ let mut prog = run_env(None);
1308
+ let output = str::from_bytes(prog.finish_with_output().output);
1309
+
1310
+ let r = os::env();
1311
+ for r.iter().advance |&(k, v)| {
1312
+ // don't check android RANDOM variables
1313
+ if k != ~" RANDOM " {
1314
+ assert!(output.contains(fmt!(" %s=%s", k, v)) ||
1315
+ output.contains(fmt!(" %s=\' %s\' ", k, v) ) ) ;
1316
+ }
1317
+ }
1318
+ }
1173
1319
1174
1320
#[ test]
1175
1321
fn test_add_to_env( ) {
0 commit comments