about summary refs log tree commit diff
path: root/src/test/ui/process
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 01:33:01 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 18:56:16 +0300
commit9be35f82c1abf2ecbab489bca9eca138ea648312 (patch)
tree69888506e34af447d9748c0d542de3ba1dd76210 /src/test/ui/process
parentca9faa52f5ada0054b1fa27d97aedf448afb059b (diff)
downloadrust-9be35f82c1abf2ecbab489bca9eca138ea648312.tar.gz
rust-9be35f82c1abf2ecbab489bca9eca138ea648312.zip
tests: Move run-pass tests without naming conflicts to ui
Diffstat (limited to 'src/test/ui/process')
-rw-r--r--src/test/ui/process/process-envs.rs53
-rw-r--r--src/test/ui/process/process-exit.rs27
-rw-r--r--src/test/ui/process/process-remove-from-env.rs47
-rw-r--r--src/test/ui/process/process-sigpipe.rs36
-rw-r--r--src/test/ui/process/process-spawn-nonexistent.rs15
-rw-r--r--src/test/ui/process/process-spawn-with-unicode-params.rs77
-rw-r--r--src/test/ui/process/process-status-inherits-stdin.rs36
7 files changed, 291 insertions, 0 deletions
diff --git a/src/test/ui/process/process-envs.rs b/src/test/ui/process/process-envs.rs
new file mode 100644
index 00000000000..a7779c55f1f
--- /dev/null
+++ b/src/test/ui/process/process-envs.rs
@@ -0,0 +1,53 @@
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten no processes
+// ignore-sgx no processes
+
+use std::process::Command;
+use std::env;
+use std::collections::HashMap;
+
+#[cfg(all(unix, not(target_os="android")))]
+pub fn env_cmd() -> Command {
+    Command::new("env")
+}
+#[cfg(target_os="android")]
+pub fn env_cmd() -> Command {
+    let mut cmd = Command::new("/system/bin/sh");
+    cmd.arg("-c").arg("set");
+    cmd
+}
+
+#[cfg(windows)]
+pub fn env_cmd() -> Command {
+    let mut cmd = Command::new("cmd");
+    cmd.arg("/c").arg("set");
+    cmd
+}
+
+fn main() {
+    // save original environment
+    let old_env = env::var_os("RUN_TEST_NEW_ENV");
+
+    env::set_var("RUN_TEST_NEW_ENV", "123");
+
+    // create filtered environment vector
+    let filtered_env : HashMap<String, String> =
+        env::vars().filter(|&(ref k, _)| k == "PATH").collect();
+
+    let mut cmd = env_cmd();
+    cmd.env_clear();
+    cmd.envs(&filtered_env);
+
+    // restore original environment
+    match old_env {
+        None => env::remove_var("RUN_TEST_NEW_ENV"),
+        Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
+    }
+
+    let result = cmd.output().unwrap();
+    let output = String::from_utf8_lossy(&result.stdout);
+
+    assert!(!output.contains("RUN_TEST_NEW_ENV"),
+            "found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
+}
diff --git a/src/test/ui/process/process-exit.rs b/src/test/ui/process/process-exit.rs
new file mode 100644
index 00000000000..da3b4ca85c2
--- /dev/null
+++ b/src/test/ui/process/process-exit.rs
@@ -0,0 +1,27 @@
+// run-pass
+#![allow(unused_imports)]
+// ignore-cloudabi no processes
+// ignore-emscripten no processes
+// ignore-sgx no processes
+
+use std::env;
+use std::process::{self, Command, Stdio};
+
+fn main() {
+    let args: Vec<String> = env::args().collect();
+    if args.len() > 1 && args[1] == "child" {
+        child();
+    } else {
+        parent();
+    }
+}
+
+fn parent() {
+    let args: Vec<String> = env::args().collect();
+    let status = Command::new(&args[0]).arg("child").status().unwrap();
+    assert_eq!(status.code(), Some(2));
+}
+
+fn child() -> i32 {
+    process::exit(2);
+}
diff --git a/src/test/ui/process/process-remove-from-env.rs b/src/test/ui/process/process-remove-from-env.rs
new file mode 100644
index 00000000000..32cbb6ac85a
--- /dev/null
+++ b/src/test/ui/process/process-remove-from-env.rs
@@ -0,0 +1,47 @@
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten no processes
+// ignore-sgx no processes
+
+use std::process::Command;
+use std::env;
+
+#[cfg(all(unix, not(target_os="android")))]
+pub fn env_cmd() -> Command {
+    Command::new("env")
+}
+#[cfg(target_os="android")]
+pub fn env_cmd() -> Command {
+    let mut cmd = Command::new("/system/bin/sh");
+    cmd.arg("-c").arg("set");
+    cmd
+}
+
+#[cfg(windows)]
+pub fn env_cmd() -> Command {
+    let mut cmd = Command::new("cmd");
+    cmd.arg("/c").arg("set");
+    cmd
+}
+
+fn main() {
+    // save original environment
+    let old_env = env::var_os("RUN_TEST_NEW_ENV");
+
+    env::set_var("RUN_TEST_NEW_ENV", "123");
+
+    let mut cmd = env_cmd();
+    cmd.env_remove("RUN_TEST_NEW_ENV");
+
+    // restore original environment
+    match old_env {
+        None => env::remove_var("RUN_TEST_NEW_ENV"),
+        Some(val) => env::set_var("RUN_TEST_NEW_ENV", &val)
+    }
+
+    let result = cmd.output().unwrap();
+    let output = String::from_utf8_lossy(&result.stdout);
+
+    assert!(!output.contains("RUN_TEST_NEW_ENV"),
+            "found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
+}
diff --git a/src/test/ui/process/process-sigpipe.rs b/src/test/ui/process/process-sigpipe.rs
new file mode 100644
index 00000000000..bf589096006
--- /dev/null
+++ b/src/test/ui/process/process-sigpipe.rs
@@ -0,0 +1,36 @@
+// run-pass
+#![allow(unused_imports)]
+#![allow(deprecated)]
+
+// ignore-android since the dynamic linker sets a SIGPIPE handler (to do
+// a crash report) so inheritance is moot on the entire platform
+
+// libstd ignores SIGPIPE, and other libraries may set signal masks.
+// Make sure that these behaviors don't get inherited to children
+// spawned via std::process, since they're needed for traditional UNIX
+// filter behavior. This test checks that `yes | head` terminates
+// (instead of running forever), and that it does not print an error
+// message about a broken pipe.
+
+// ignore-cloudabi no subprocesses support
+// ignore-emscripten no threads support
+
+use std::process;
+use std::thread;
+
+#[cfg(unix)]
+fn main() {
+    // Just in case `yes` doesn't check for EPIPE...
+    thread::spawn(|| {
+        thread::sleep_ms(5000);
+        process::exit(1);
+    });
+    let output = process::Command::new("sh").arg("-c").arg("yes | head").output().unwrap();
+    assert!(output.status.success());
+    assert!(output.stderr.len() == 0);
+}
+
+#[cfg(not(unix))]
+fn main() {
+    // Not worried about signal masks on other platforms
+}
diff --git a/src/test/ui/process/process-spawn-nonexistent.rs b/src/test/ui/process/process-spawn-nonexistent.rs
new file mode 100644
index 00000000000..182cf1748fe
--- /dev/null
+++ b/src/test/ui/process/process-spawn-nonexistent.rs
@@ -0,0 +1,15 @@
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten no processes
+// ignore-sgx no processes
+
+use std::io::ErrorKind;
+use std::process::Command;
+
+fn main() {
+    assert_eq!(Command::new("nonexistent")
+                   .spawn()
+                   .unwrap_err()
+                   .kind(),
+               ErrorKind::NotFound);
+}
diff --git a/src/test/ui/process/process-spawn-with-unicode-params.rs b/src/test/ui/process/process-spawn-with-unicode-params.rs
new file mode 100644
index 00000000000..edd3cb26ec3
--- /dev/null
+++ b/src/test/ui/process/process-spawn-with-unicode-params.rs
@@ -0,0 +1,77 @@
+// run-pass
+// no-prefer-dynamic
+
+// The test copies itself into a subdirectory with a non-ASCII name and then
+// runs it as a child process within the subdirectory.  The parent process
+// also adds an environment variable and an argument, both containing
+// non-ASCII characters.  The child process ensures all the strings are
+// intact.
+
+// ignore-cloudabi no processes
+// ignore-emscripten no processes
+// ignore-sgx no processes
+
+use std::io::prelude::*;
+use std::io;
+use std::fs;
+use std::process::Command;
+use std::env;
+use std::path::Path;
+
+fn main() {
+    let my_args = env::args().collect::<Vec<_>>();
+    let my_cwd  = env::current_dir().unwrap();
+    let my_env  = env::vars().collect::<Vec<_>>();
+    let my_path = env::current_exe().unwrap();
+    let my_dir  = my_path.parent().unwrap();
+    let my_ext  = my_path.extension().and_then(|s| s.to_str()).unwrap_or("");
+
+    // some non-ASCII characters
+    let blah       = "\u{3c0}\u{42f}\u{97f3}\u{e6}\u{221e}";
+
+    let child_name = "child";
+    let child_dir  = format!("process-spawn-with-unicode-params-{}", blah);
+
+    // parameters sent to child / expected to be received from parent
+    let arg = blah;
+    let cwd = my_dir.join(&child_dir);
+    let env = ("RUST_TEST_PROC_SPAWN_UNICODE".to_string(), blah.to_string());
+
+    // am I the parent or the child?
+    if my_args.len() == 1 {             // parent
+
+        let child_filestem = Path::new(child_name);
+        let child_filename = child_filestem.with_extension(my_ext);
+        let child_path     = cwd.join(&child_filename);
+
+        // make a separate directory for the child
+        let _ = fs::create_dir(&cwd);
+        fs::copy(&my_path, &child_path).unwrap();
+
+        // run child
+        let p = Command::new(&child_path)
+                        .arg(arg)
+                        .current_dir(&cwd)
+                        .env(&env.0, &env.1)
+                        .spawn().unwrap().wait_with_output().unwrap();
+
+        // display the output
+        io::stdout().write_all(&p.stdout).unwrap();
+        io::stderr().write_all(&p.stderr).unwrap();
+
+        // make sure the child succeeded
+        assert!(p.status.success());
+
+    } else {                            // child
+
+        // check working directory (don't try to compare with `cwd` here!)
+        assert!(my_cwd.ends_with(&child_dir));
+
+        // check arguments
+        assert_eq!(&*my_args[1], arg);
+
+        // check environment variable
+        assert!(my_env.contains(&env));
+
+    };
+}
diff --git a/src/test/ui/process/process-status-inherits-stdin.rs b/src/test/ui/process/process-status-inherits-stdin.rs
new file mode 100644
index 00000000000..f9b2da7e401
--- /dev/null
+++ b/src/test/ui/process/process-status-inherits-stdin.rs
@@ -0,0 +1,36 @@
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten no processes
+// ignore-sgx no processes
+
+use std::env;
+use std::io;
+use std::io::Write;
+use std::process::{Command, Stdio};
+
+fn main() {
+    let mut args = env::args();
+    let me = args.next().unwrap();
+    let arg = args.next();
+    match arg.as_ref().map(|s| &s[..]) {
+        None => {
+            let mut s = Command::new(&me)
+                                .arg("a1")
+                                .stdin(Stdio::piped())
+                                .spawn()
+                                .unwrap();
+            s.stdin.take().unwrap().write_all(b"foo\n").unwrap();
+            let s = s.wait().unwrap();
+            assert!(s.success());
+        }
+        Some("a1") => {
+            let s = Command::new(&me).arg("a2").status().unwrap();
+            assert!(s.success());
+        }
+        Some(..) => {
+            let mut s = String::new();
+            io::stdin().read_line(&mut s).unwrap();
+            assert_eq!(s, "foo\n");
+        }
+    }
+}