about summary refs log tree commit diff
path: root/src/test/run-pass/process
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-09-27 23:46:21 +0000
committerbors <bors@rust-lang.org>2018-09-27 23:46:21 +0000
commit7d52cbce6db83e4fc2d8706b4e4b9c7da76cbcf8 (patch)
treebfe627dfa7d7ea762d9a4fb1ea238539eb798934 /src/test/run-pass/process
parent8876906867b2db3c7177d69dd020c40d89177f86 (diff)
parent649b20eca9a5d2860eb46f6b9e1d99753d4515b7 (diff)
downloadrust-7d52cbce6db83e4fc2d8706b4e4b9c7da76cbcf8.tar.gz
rust-7d52cbce6db83e4fc2d8706b4e4b9c7da76cbcf8.zip
Auto merge of #54530 - pnkfelix:issue-54047-migrate-ui-run-pass-back-to-run-pass, r=alexcrichton
Migrate `src/test/ui/run-pass/*` back to `src/test/run-pass/`.

Moves all the tests from `src/test/ui/run-pass/**` back to `src/test/run-pass/`.

This should have no impact on our overall testing completeness due to PR #54223

Fix #54047
Diffstat (limited to 'src/test/run-pass/process')
-rw-r--r--src/test/run-pass/process/process-envs.rs62
-rw-r--r--src/test/run-pass/process/process-exit.rs36
-rw-r--r--src/test/run-pass/process/process-remove-from-env.rs56
-rw-r--r--src/test/run-pass/process/process-sigpipe.rs46
-rw-r--r--src/test/run-pass/process/process-spawn-nonexistent.rs24
-rw-r--r--src/test/run-pass/process/process-spawn-with-unicode-params.rs86
-rw-r--r--src/test/run-pass/process/process-status-inherits-stdin.rs45
7 files changed, 355 insertions, 0 deletions
diff --git a/src/test/run-pass/process/process-envs.rs b/src/test/run-pass/process/process-envs.rs
new file mode 100644
index 00000000000..4fb21d4dc66
--- /dev/null
+++ b/src/test/run-pass/process/process-envs.rs
@@ -0,0 +1,62 @@
+// Copyright 2014, 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten 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/run-pass/process/process-exit.rs b/src/test/run-pass/process/process-exit.rs
new file mode 100644
index 00000000000..6314dc2cd64
--- /dev/null
+++ b/src/test/run-pass/process/process-exit.rs
@@ -0,0 +1,36 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(unused_imports)]
+// ignore-cloudabi no processes
+// ignore-emscripten 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/run-pass/process/process-remove-from-env.rs b/src/test/run-pass/process/process-remove-from-env.rs
new file mode 100644
index 00000000000..d9c35f3e993
--- /dev/null
+++ b/src/test/run-pass/process/process-remove-from-env.rs
@@ -0,0 +1,56 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten 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/run-pass/process/process-sigpipe.rs b/src/test/run-pass/process/process-sigpipe.rs
new file mode 100644
index 00000000000..715da1514f3
--- /dev/null
+++ b/src/test/run-pass/process/process-sigpipe.rs
@@ -0,0 +1,46 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// 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/run-pass/process/process-spawn-nonexistent.rs b/src/test/run-pass/process/process-spawn-nonexistent.rs
new file mode 100644
index 00000000000..926e93104f3
--- /dev/null
+++ b/src/test/run-pass/process/process-spawn-nonexistent.rs
@@ -0,0 +1,24 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten 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/run-pass/process/process-spawn-with-unicode-params.rs b/src/test/run-pass/process/process-spawn-with-unicode-params.rs
new file mode 100644
index 00000000000..70ed7982508
--- /dev/null
+++ b/src/test/run-pass/process/process-spawn-with-unicode-params.rs
@@ -0,0 +1,86 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// 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
+
+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/run-pass/process/process-status-inherits-stdin.rs b/src/test/run-pass/process/process-status-inherits-stdin.rs
new file mode 100644
index 00000000000..1b09d5e52bc
--- /dev/null
+++ b/src/test/run-pass/process/process-status-inherits-stdin.rs
@@ -0,0 +1,45 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+// ignore-cloudabi no processes
+// ignore-emscripten 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");
+        }
+    }
+}