about summary refs log tree commit diff
path: root/library/std/tests
diff options
context:
space:
mode:
authorJiahao XU <Jiahao_XU@outlook.com>2024-06-30 18:23:07 +1000
committerJiahao XU <Jiahao_XU@outlook.com>2024-07-23 23:13:56 +1000
commitc9c8a14884c19e51a0eee54ccd98efa7f0f2bddd (patch)
tree1b94b0d4990f0771508383ea979d012270473e53 /library/std/tests
parent52f3c71c8dc4aaed71e3035995fcbdd6d78c98c6 (diff)
downloadrust-c9c8a14884c19e51a0eee54ccd98efa7f0f2bddd.tar.gz
rust-c9c8a14884c19e51a0eee54ccd98efa7f0f2bddd.zip
Initial implementation of anonymous_pipe
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Diffstat (limited to 'library/std/tests')
-rw-r--r--library/std/tests/pipe_subprocess.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/library/std/tests/pipe_subprocess.rs b/library/std/tests/pipe_subprocess.rs
new file mode 100644
index 00000000000..c2278098b9b
--- /dev/null
+++ b/library/std/tests/pipe_subprocess.rs
@@ -0,0 +1,39 @@
+#![feature(anonymous_pipe)]
+
+fn main() {
+    #[cfg(all(not(miri), any(unix, windows)))]
+    {
+        use std::{env, io::Read, pipe::pipe, process};
+
+        if env::var("I_AM_THE_CHILD").is_ok() {
+            child();
+        } else {
+            parent();
+        }
+
+        fn parent() {
+            let me = env::current_exe().unwrap();
+
+            let (rx, tx) = pipe().unwrap();
+            assert!(
+                process::Command::new(me)
+                    .env("I_AM_THE_CHILD", "1")
+                    .stdout(tx)
+                    .status()
+                    .unwrap()
+                    .success()
+            );
+
+            let mut s = String::new();
+            (&rx).read_to_string(&mut s).unwrap();
+            drop(rx);
+            assert_eq!(s, "Heloo,\n");
+
+            println!("Test pipe_subprocess.rs success");
+        }
+
+        fn child() {
+            println!("Heloo,");
+        }
+    }
+}