use crate::io::ErrorKind;
use crate::str;
-// FIXME(#10380) these tests should not all be ignored on android.
+#[cfg(target_os = "android")]
+fn shell_cmd() -> Command {
+ Command::new("/system/bin/sh")
+}
+
+#[cfg(not(target_os = "android"))]
+fn shell_cmd() -> Command {
+ Command::new("/bin/sh")
+}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn smoke() {
let p = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "exit 0"]).spawn()
} else {
- Command::new("true").spawn()
+ shell_cmd().arg("-c").arg("true").spawn()
};
assert!(p.is_ok());
let mut p = p.unwrap();
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn exit_reported_right() {
let p = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "exit 1"]).spawn()
} else {
- Command::new("false").spawn()
+ shell_cmd().arg("-c").arg("false").spawn()
};
assert!(p.is_ok());
let mut p = p.unwrap();
#[test]
#[cfg(unix)]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn signal_reported_right() {
use crate::os::unix::process::ExitStatusExt;
- let mut p =
- Command::new("/bin/sh").arg("-c").arg("read a").stdin(Stdio::piped()).spawn().unwrap();
+ let mut p = shell_cmd().arg("-c").arg("read a").stdin(Stdio::piped()).spawn().unwrap();
p.kill().unwrap();
match p.wait().unwrap().signal() {
Some(9) => {}
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn stdout_works() {
if cfg!(target_os = "windows") {
let mut cmd = Command::new("cmd");
cmd.args(&["/C", "echo foobar"]).stdout(Stdio::piped());
assert_eq!(run_output(cmd), "foobar\r\n");
} else {
- let mut cmd = Command::new("echo");
- cmd.arg("foobar").stdout(Stdio::piped());
+ let mut cmd = shell_cmd();
+ cmd.arg("-c").arg("echo foobar").stdout(Stdio::piped());
assert_eq!(run_output(cmd), "foobar\n");
}
}
#[test]
-#[cfg_attr(any(windows, target_os = "android", target_os = "vxworks"), ignore)]
+#[cfg_attr(any(windows, target_os = "vxworks"), ignore)]
fn set_current_dir_works() {
- let mut cmd = Command::new("/bin/sh");
+ let mut cmd = shell_cmd();
cmd.arg("-c").arg("pwd").current_dir("/").stdout(Stdio::piped());
assert_eq!(run_output(cmd), "/\n");
}
#[test]
-#[cfg_attr(any(windows, target_os = "android", target_os = "vxworks"), ignore)]
+#[cfg_attr(any(windows, target_os = "vxworks"), ignore)]
fn stdin_works() {
- let mut p = Command::new("/bin/sh")
+ let mut p = shell_cmd()
.arg("-c")
.arg("read line; echo $line")
.stdin(Stdio::piped())
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn test_process_status() {
let mut status = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "exit 1"]).status().unwrap()
} else {
- Command::new("false").status().unwrap()
+ shell_cmd().arg("-c").arg("false").status().unwrap()
};
assert!(status.code() == Some(1));
status = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "exit 0"]).status().unwrap()
} else {
- Command::new("true").status().unwrap()
+ shell_cmd().arg("-c").arg("true").status().unwrap()
};
assert!(status.success());
}
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn test_process_output_output() {
let Output { status, stdout, stderr } = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "echo hello"]).output().unwrap()
} else {
- Command::new("echo").arg("hello").output().unwrap()
+ shell_cmd().arg("-c").arg("echo hello").output().unwrap()
};
let output_str = str::from_utf8(&stdout).unwrap();
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn test_process_output_error() {
let Output { status, stdout, stderr } = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "mkdir ."]).output().unwrap()
Command::new("mkdir").arg("./").output().unwrap()
};
- assert!(status.code() == Some(1));
+ assert!(status.code().is_some());
+ assert!(status.code() != Some(0));
assert_eq!(stdout, Vec::new());
assert!(!stderr.is_empty());
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn test_finish_once() {
let mut prog = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "exit 1"]).spawn().unwrap()
} else {
- Command::new("false").spawn().unwrap()
+ shell_cmd().arg("-c").arg("false").spawn().unwrap()
};
assert!(prog.wait().unwrap().code() == Some(1));
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn test_finish_twice() {
let mut prog = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "exit 1"]).spawn().unwrap()
} else {
- Command::new("false").spawn().unwrap()
+ shell_cmd().arg("-c").arg("false").spawn().unwrap()
};
assert!(prog.wait().unwrap().code() == Some(1));
assert!(prog.wait().unwrap().code() == Some(1));
}
#[test]
-#[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)]
+#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn test_wait_with_output_once() {
let prog = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "echo hello"]).stdout(Stdio::piped()).spawn().unwrap()
} else {
- Command::new("echo").arg("hello").stdout(Stdio::piped()).spawn().unwrap()
+ shell_cmd().arg("-c").arg("echo hello").stdout(Stdio::piped()).spawn().unwrap()
};
let Output { status, stdout, stderr } = prog.wait_with_output().unwrap();