about summary refs log tree commit diff
path: root/tests/ui/process
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/process')
-rw-r--r--tests/ui/process/env-args-reverse-iterator.rs38
-rw-r--r--tests/ui/process/env-funky-keys.rs43
-rw-r--r--tests/ui/process/env-null-vars.rs16
-rw-r--r--tests/ui/process/env-vars.rs19
-rw-r--r--tests/ui/process/exec-env.rs10
-rw-r--r--tests/ui/process/inherit-env.rs25
-rw-r--r--tests/ui/process/no-stdio.rs8
-rw-r--r--tests/ui/process/println-with-broken-pipe.rs4
8 files changed, 157 insertions, 6 deletions
diff --git a/tests/ui/process/env-args-reverse-iterator.rs b/tests/ui/process/env-args-reverse-iterator.rs
new file mode 100644
index 00000000000..830e9535466
--- /dev/null
+++ b/tests/ui/process/env-args-reverse-iterator.rs
@@ -0,0 +1,38 @@
+//@ run-pass
+//@ ignore-wasm32 no processes
+//@ ignore-sgx no processes
+
+use std::env::args;
+use std::process::Command;
+
+fn assert_reverse_iterator_for_program_arguments(program_name: &str) {
+    let args: Vec<_> = args().rev().collect();
+
+    assert!(args.len() == 4);
+    assert_eq!(args[0], "c");
+    assert_eq!(args[1], "b");
+    assert_eq!(args[2], "a");
+    assert_eq!(args[3], program_name);
+
+    println!("passed");
+}
+
+fn main() {
+    let mut args = args();
+    let me = args.next().unwrap();
+
+    if let Some(_) = args.next() {
+        assert_reverse_iterator_for_program_arguments(&me);
+        return
+    }
+
+    let output = Command::new(&me)
+        .arg("a")
+        .arg("b")
+        .arg("c")
+        .output()
+        .unwrap();
+    assert!(output.status.success());
+    assert!(output.stderr.is_empty());
+    assert_eq!(output.stdout, b"passed\n");
+}
diff --git a/tests/ui/process/env-funky-keys.rs b/tests/ui/process/env-funky-keys.rs
new file mode 100644
index 00000000000..314ccaea015
--- /dev/null
+++ b/tests/ui/process/env-funky-keys.rs
@@ -0,0 +1,43 @@
+//@ run-pass
+// Ignore this test on Android, because it segfaults there.
+
+//@ ignore-android
+//@ ignore-windows
+//@ ignore-wasm32 no execve
+//@ ignore-sgx no execve
+//@ ignore-vxworks no execve
+//@ ignore-fuchsia no 'execve'
+//@ no-prefer-dynamic
+
+#![feature(rustc_private)]
+
+extern crate libc;
+
+use libc::c_char;
+use libc::execve;
+use std::env;
+use std::ffi::CString;
+use std::os::unix::prelude::*;
+use std::ptr;
+
+fn main() {
+    if env::args_os().count() == 2 {
+        for (key, value) in env::vars_os() {
+            panic!("found env value {:?} {:?}", key, value);
+        }
+        return;
+    }
+
+    let current_exe = CString::new(env::current_exe()
+                                       .unwrap()
+                                       .as_os_str()
+                                       .as_bytes()).unwrap();
+    let new_env_var = CString::new("FOOBAR").unwrap();
+    let filename: *const c_char = current_exe.as_ptr();
+    let argv: &[*const c_char] = &[filename, filename, ptr::null()];
+    let envp: &[*const c_char] = &[new_env_var.as_ptr(), ptr::null()];
+    unsafe {
+        execve(filename, &argv[0], &envp[0]);
+    }
+    panic!("execve failed");
+}
diff --git a/tests/ui/process/env-null-vars.rs b/tests/ui/process/env-null-vars.rs
new file mode 100644
index 00000000000..24d783553d1
--- /dev/null
+++ b/tests/ui/process/env-null-vars.rs
@@ -0,0 +1,16 @@
+// Ensure that env::vars() does not panic if environ is null.
+// Regression test for rust-lang/rust#53200
+//@ run-pass
+
+#![feature(rustc_private)]
+
+// FIXME: more platforms?
+#[cfg(target_os = "linux")]
+fn main() {
+    extern crate libc;
+    unsafe { libc::clearenv(); }
+    assert_eq!(std::env::vars().count(), 0);
+}
+
+#[cfg(not(target_os = "linux"))]
+fn main() {}
diff --git a/tests/ui/process/env-vars.rs b/tests/ui/process/env-vars.rs
new file mode 100644
index 00000000000..73068b5dfb8
--- /dev/null
+++ b/tests/ui/process/env-vars.rs
@@ -0,0 +1,19 @@
+//@ run-pass
+
+use std::env::*;
+
+fn main() {
+    for (k, v) in vars_os() {
+        // On Windows, the environment variable NUMBER_OF_PROCESSORS has special meaning.
+        // Unfortunately, you can get different answers, depending on whether you are
+        // enumerating all environment variables or querying a specific variable.
+        // This was causing this test to fail on machines with more than 64 processors.
+        if cfg!(target_os = "windows") && k == "NUMBER_OF_PROCESSORS" {
+            continue;
+        }
+
+        let v2 = var_os(&k);
+        assert!(v2.as_ref().map(|s| &**s) == Some(&*v),
+                "bad vars->var transition: {:?} {:?} {:?}", k, v, v2);
+    }
+}
diff --git a/tests/ui/process/exec-env.rs b/tests/ui/process/exec-env.rs
new file mode 100644
index 00000000000..9054b378f56
--- /dev/null
+++ b/tests/ui/process/exec-env.rs
@@ -0,0 +1,10 @@
+//@ run-pass
+//@ exec-env:TEST_EXEC_ENV=22
+//@ ignore-wasm32 wasm runtimes aren't configured to inherit env vars yet
+//@ ignore-sgx unsupported
+
+use std::env;
+
+pub fn main() {
+    assert_eq!(env::var("TEST_EXEC_ENV"), Ok("22".to_string()));
+}
diff --git a/tests/ui/process/inherit-env.rs b/tests/ui/process/inherit-env.rs
new file mode 100644
index 00000000000..0eb61fcdd53
--- /dev/null
+++ b/tests/ui/process/inherit-env.rs
@@ -0,0 +1,25 @@
+//@ run-pass
+//@ ignore-wasm32 no subprocess support
+//@ ignore-sgx no processes
+
+use std::env;
+use std::process::Command;
+
+fn main() {
+    if env::args().nth(1).map(|s| s == "print").unwrap_or(false) {
+        for (k, v) in env::vars() {
+            println!("{}={}", k, v);
+        }
+        return
+    }
+
+    let me = env::current_exe().unwrap();
+    let result = Command::new(me).arg("print").output().unwrap();
+    let output = String::from_utf8(result.stdout).unwrap();
+
+    for (k, v) in env::vars() {
+        assert!(output.contains(&format!("{}={}", k, v)),
+                "output doesn't contain `{}={}`\n{}",
+                k, v, output);
+    }
+}
diff --git a/tests/ui/process/no-stdio.rs b/tests/ui/process/no-stdio.rs
index 05b1e52b799..8eebf6dbc7d 100644
--- a/tests/ui/process/no-stdio.rs
+++ b/tests/ui/process/no-stdio.rs
@@ -5,11 +5,13 @@
 
 #![feature(rustc_private)]
 
+#[cfg(unix)]
 extern crate libc;
 
-use std::process::{Command, Stdio};
 use std::env;
+use std::ffi::c_int;
 use std::io::{self, Read, Write};
+use std::process::{Command, Stdio};
 
 #[cfg(unix)]
 unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
@@ -36,14 +38,14 @@ unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
 }
 
 #[cfg(unix)]
-fn assert_fd_is_valid(fd: libc::c_int) {
+fn assert_fd_is_valid(fd: c_int) {
     if unsafe { libc::fcntl(fd, libc::F_GETFD) == -1 } {
         panic!("file descriptor {} is not valid: {}", fd, io::Error::last_os_error());
     }
 }
 
 #[cfg(windows)]
-fn assert_fd_is_valid(_fd: libc::c_int) {}
+fn assert_fd_is_valid(_fd: c_int) {}
 
 #[cfg(windows)]
 unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
diff --git a/tests/ui/process/println-with-broken-pipe.rs b/tests/ui/process/println-with-broken-pipe.rs
index 1df8c765cbd..798db3c0f8c 100644
--- a/tests/ui/process/println-with-broken-pipe.rs
+++ b/tests/ui/process/println-with-broken-pipe.rs
@@ -6,16 +6,14 @@
 //@ ignore-horizon
 //@ ignore-android
 //@ normalize-stderr-test ".rs:\d+:\d+" -> ".rs:LL:CC"
+//@ compile-flags: -Zon-broken-pipe=error
 
 // Test what the error message looks like when `println!()` panics because of
 // `std::io::ErrorKind::BrokenPipe`
 
-#![feature(unix_sigpipe)]
-
 use std::env;
 use std::process::{Command, Stdio};
 
-#[unix_sigpipe = "sig_ign"]
 fn main() {
     let mut args = env::args();
     let me = args.next().unwrap();