Skip to content

Commit 439b13f

Browse files
committed
auto merge of #7449 : yichoi/rust/std_test, r=cmr
adjust run.rs test for android to pass check std
2 parents c86df3a + 9b95b6d commit 439b13f

File tree

1 file changed

+149
-3
lines changed

1 file changed

+149
-3
lines changed

src/libstd/run.rs

Lines changed: 149 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,20 @@ mod tests {
943943
}
944944

945945
#[test]
946+
#[cfg(not(target_os="android"))]
946947
fn test_process_status() {
947948
assert_eq!(run::process_status("false", []), 1);
948949
assert_eq!(run::process_status("true", []), 0);
949950
}
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+
}
950957
951958
#[test]
959+
#[cfg(not(target_os="android"))]
952960
fn test_process_output_output() {
953961
954962
let run::ProcessOutput {status, output, error}
@@ -962,8 +970,24 @@ mod tests {
962970
assert_eq!(error, ~[]);
963971
}
964972
}
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+
}
965988
966989
#[test]
990+
#[cfg(not(target_os="android"))]
967991
fn test_process_output_error() {
968992
969993
let run::ProcessOutput {status, output, error}
@@ -973,6 +997,17 @@ mod tests {
973997
assert_eq!(output, ~[]);
974998
assert!(!error.is_empty());
975999
}
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+
}
9761011
9771012
#[test]
9781013
fn test_pipes() {
@@ -1023,19 +1058,37 @@ mod tests {
10231058
}
10241059
10251060
#[test]
1061+
#[cfg(not(target_os="android"))]
10261062
fn test_finish_once() {
10271063
let mut prog = run::Process::new("false", [], run::ProcessOptions::new());
10281064
assert_eq!(prog.finish(), 1);
10291065
}
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+
}
10301073
10311074
#[test]
1075+
#[cfg(not(target_os="android"))]
10321076
fn test_finish_twice() {
10331077
let mut prog = run::Process::new("false", [], run::ProcessOptions::new());
10341078
assert_eq!(prog.finish(), 1);
10351079
assert_eq!(prog.finish(), 1);
10361080
}
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+
}
10371089
10381090
#[test]
1091+
#[cfg(not(target_os="android"))]
10391092
fn test_finish_with_output_once() {
10401093
10411094
let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new());
@@ -1050,8 +1103,26 @@ mod tests {
10501103
assert_eq!(error, ~[]);
10511104
}
10521105
}
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+
}
10531123
10541124
#[test]
1125+
#[cfg(not(target_os="android"))]
10551126
fn test_finish_with_output_twice() {
10561127
10571128
let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new());
@@ -1077,10 +1148,38 @@ mod tests {
10771148
assert_eq!(error, ~[]);
10781149
}
10791150
}
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+
}
10801179
10811180
#[test]
10821181
#[should_fail]
1083-
#[cfg(not(windows))]
1182+
#[cfg(not(windows),not(target_os="android"))]
10841183
fn test_finish_with_output_redirected() {
10851184
let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions {
10861185
env: None,
@@ -1092,14 +1191,36 @@ mod tests {
10921191
// this should fail because it is not valid to read the output when it was redirected
10931192
prog.finish_with_output();
10941193
}
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+
}
10951209
1096-
#[cfg(unix)]
1210+
#[cfg(unix,not(target_os="android"))]
10971211
fn run_pwd(dir: Option<&Path>) -> run::Process {
10981212
run::Process::new("pwd", [], run::ProcessOptions {
10991213
dir: dir,
11001214
.. run::ProcessOptions::new()
11011215
})
11021216
}
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+
}
11031224
11041225
#[cfg(windows)]
11051226
fn run_pwd(dir: Option<&Path>) -> run::Process {
@@ -1141,13 +1262,20 @@ mod tests {
11411262
assert_eq!(parent_stat.st_ino, child_stat.st_ino);
11421263
}
11431264
1144-
#[cfg(unix)]
1265+
#[cfg(unix,not(target_os="android"))]
11451266
fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
11461267
run::Process::new("env", [], run::ProcessOptions {
11471268
env: env,
11481269
.. run::ProcessOptions::new()
11491270
})
11501271
}
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+
}
11511279
11521280
#[cfg(windows)]
11531281
fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
@@ -1158,6 +1286,7 @@ mod tests {
11581286
}
11591287
11601288
#[test]
1289+
#[cfg(not(target_os="android"))]
11611290
fn test_inherit_env() {
11621291
if running_on_valgrind() { return; }
11631292
@@ -1170,6 +1299,23 @@ mod tests {
11701299
assert!(k.is_empty() || output.contains(fmt!("%s=%s", k, v)));
11711300
}
11721301
}
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+
}
11731319

11741320
#[test]
11751321
fn test_add_to_env() {

0 commit comments

Comments
 (0)