Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move two tests from tests/ui/std to library/std/tests #112390

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions tests/ui/std/issue-15149.rs → library/std/tests/issue-15149.rs
MoskalykA marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// run-pass
// ignore-wasm (needs file descriptors and env variables)
#[cfg(any(target_family = "unix", target_family = "windows"))]
MoskalykA marked this conversation as resolved.
Show resolved Hide resolved

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) {
Expand Down Expand Up @@ -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() {
MoskalykA marked this conversation as resolved.
Show resolved Hide resolved
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();
Expand Down