mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
Rollup merge of #91151 - name1e5s:chore/process_test, r=m-ou-se
Fix test in std::process on android closes #10380
This commit is contained in:
commit
a81f3610ea
@ -4,15 +4,23 @@ use super::{Command, Output, Stdio};
|
||||
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();
|
||||
@ -29,12 +37,12 @@ fn smoke_failure() {
|
||||
}
|
||||
|
||||
#[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();
|
||||
@ -44,12 +52,11 @@ fn exit_reported_right() {
|
||||
|
||||
#[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) => {}
|
||||
@ -69,31 +76,31 @@ pub fn run_output(mut cmd: Command) -> String {
|
||||
}
|
||||
|
||||
#[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())
|
||||
@ -109,19 +116,19 @@ fn stdin_works() {
|
||||
}
|
||||
|
||||
#[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());
|
||||
}
|
||||
@ -135,12 +142,12 @@ fn test_process_output_fail_to_start() {
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
||||
@ -150,7 +157,7 @@ fn test_process_output_output() {
|
||||
}
|
||||
|
||||
#[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()
|
||||
@ -158,41 +165,42 @@ fn test_process_output_error() {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user