]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/command/command-pre-exec.rs
3 #![allow(stable_features)]
4 // ignore-windows - this is a unix-specific test
5 // ignore-emscripten no processes
6 // ignore-sgx no processes
7 #![feature(process_exec, rustc_private)]
13 use std
::os
::unix
::process
::CommandExt
;
14 use std
::process
::Command
;
15 use std
::sync
::atomic
::{AtomicUsize, Ordering}
;
19 if let Some(arg
) = env
::args().nth(1) {
21 "test1" => println
!("hello2"),
22 "test2" => assert_eq
!(env
::var("FOO").unwrap(), "BAR"),
23 "test3" => assert_eq
!(env
::current_dir().unwrap().to_str().unwrap(), "/"),
25 _
=> panic
!("unknown argument: {}", arg
),
30 let me
= env
::current_exe().unwrap();
42 assert
!(output
.status
.success());
43 assert
!(output
.stderr
.is_empty());
44 assert_eq
!(output
.stdout
, b
"hello\nhello2\n");
50 env
::set_current_dir("/").unwrap();
56 assert
!(output
.status
.success());
57 assert
!(output
.stderr
.is_empty());
58 assert
!(output
.stdout
.is_empty());
63 .pre_exec(|| Err(Error
::from_raw_os_error(102)))
67 assert_eq
!(output
.raw_os_error(), Some(102));
69 let pid
= unsafe { libc::getpid() }
;
75 let child
= libc
::getpid();
77 assert
!(pid
!= child
);
83 assert
!(output
.status
.success());
84 assert
!(output
.stderr
.is_empty());
85 assert
!(output
.stdout
.is_empty());
87 let mem
= Arc
::new(AtomicUsize
::new(0));
88 let mem2
= mem
.clone();
93 assert_eq
!(mem2
.fetch_add(1, Ordering
::SeqCst
), 0);
99 assert
!(output
.status
.success());
100 assert
!(output
.stderr
.is_empty());
101 assert
!(output
.stdout
.is_empty());
102 assert_eq
!(mem
.load(Ordering
::SeqCst
), 0);