about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-28 05:00:22 +0000
committerbors <bors@rust-lang.org>2023-07-28 05:00:22 +0000
commite40e22be550fdcf5f11ba95cc84f3f337b0695f4 (patch)
tree93b7509b28f3bad452e3e40413c9a111579ee2d7
parent0ca28c3da75b165cc3e4870a1f397a23d2a58857 (diff)
parent48e7f3e313c19d8df1a05f0ccc17ac02e41dda6a (diff)
downloadrust-e40e22be550fdcf5f11ba95cc84f3f337b0695f4.tar.gz
rust-e40e22be550fdcf5f11ba95cc84f3f337b0695f4.zip
Auto merge of #112390 - MoskalykA:move-two-tests-from-library-to-tests, r=workingjubilee
Move two tests from `tests/ui/std` to `library/std/tests`

Hi, there,
This pull request comes from this issue (#99417), sorry I made some mistakes creating the pull request, it's my first one.
-rw-r--r--library/std/tests/process_spawning.rs (renamed from tests/ui/std/issue-15149.rs)31
-rw-r--r--library/std/tests/switch-stdout.rs (renamed from tests/ui/std/switch-stdout.rs)23
2 files changed, 17 insertions, 37 deletions
diff --git a/tests/ui/std/issue-15149.rs b/library/std/tests/process_spawning.rs
index 064472f5785..52e5b55fb9d 100644
--- a/tests/ui/std/issue-15149.rs
+++ b/library/std/tests/process_spawning.rs
@@ -1,38 +1,17 @@
-// run-pass
-
-#![allow(unused_variables)]
-// no-prefer-dynamic
-// ignore-cross-compile
-
 use std::env;
-use std::ffi::OsStr;
 use std::fs;
-use std::path::PathBuf;
 use std::process;
 use std::str;
 
-fn main() {
-    // If we're the child, make sure we were invoked correctly
-    let args: Vec<String> = env::args().collect();
-    if args.len() > 1 && args[1] == "child" {
-        // FIXME: This should check the whole `args[0]` instead of just
-        // checking that it ends_with the executable name. This
-        // is needed because of Windows, which has a different behavior.
-        // See #15149 for more info.
-        let my_path = env::current_exe().unwrap();
-        return assert_eq!(my_path.file_stem(), Some(OsStr::new("mytest")));
-    }
-
-    test();
-}
+mod common;
 
-fn test() {
+#[test]
+fn issue_15149() {
     // If we're the parent, copy our own binary to a new directory.
     let my_path = env::current_exe().unwrap();
-    let my_dir = my_path.parent().unwrap();
 
-    let child_dir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
-    let child_dir = child_dir.join("issue-15140-child");
+    let temp = common::tmpdir();
+    let child_dir = temp.join("issue-15140-child");
     fs::create_dir_all(&child_dir).unwrap();
 
     let child_path = child_dir.join(&format!("mytest{}", env::consts::EXE_SUFFIX));
diff --git a/tests/ui/std/switch-stdout.rs b/library/std/tests/switch-stdout.rs
index 2d936d96b05..28ce6dfccd3 100644
--- a/tests/ui/std/switch-stdout.rs
+++ b/library/std/tests/switch-stdout.rs
@@ -1,10 +1,9 @@
-// run-pass
-// ignore-wasm (needs file descriptors and env variables)
+#[cfg(any(target_family = "unix", target_family = "windows"))]
 
-use std::env;
 use std::fs::File;
 use std::io::{Read, Write};
-use std::path::PathBuf;
+
+mod common;
 
 #[cfg(unix)]
 fn switch_stdout_to(file: File) {
@@ -35,16 +34,18 @@ fn switch_stdout_to(file: File) {
     }
 }
 
-fn main() {
-    let path = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
-    let path = path.join("switch-stdout-output");
+#[test]
+fn switch_stdout() {
+    let temp = common::tmpdir();
+    let path = temp.join("switch-stdout-output");
     let f = File::create(&path).unwrap();
 
-    println!("foo");
-    std::io::stdout().flush().unwrap();
+    let mut stdout = std::io::stdout();
+    stdout.write(b"foo\n").unwrap();
+    stdout.flush().unwrap();
     switch_stdout_to(f);
-    println!("bar");
-    std::io::stdout().flush().unwrap();
+    stdout.write(b"bar\n").unwrap();
+    stdout.flush().unwrap();
 
     let mut contents = String::new();
     File::open(&path).unwrap().read_to_string(&mut contents).unwrap();