Merge pull request #4337 from RalfJung/io

test direct usage of io::{stdout,stderr,stdin}
This commit is contained in:
Ralf Jung 2025-05-21 06:38:23 +00:00 committed by GitHub
commit fe5119375c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 25 additions and 17 deletions

View file

@ -1,9 +0,0 @@
//@ignore-target: windows # No libc IO on Windows
fn main() -> std::io::Result<()> {
let mut bytes = [0u8; 512];
unsafe {
libc::read(0, bytes.as_mut_ptr() as *mut libc::c_void, 512); //~ ERROR: `read` from stdin not available when isolation is enabled
}
Ok(())
}

View file

@ -0,0 +1,12 @@
//@ignore-target: windows # FIXME: stdin does not work on Windows
//@error-in-other-file: `read` from stdin not available when isolation is enabled
//@normalize-stderr-test: "src/sys/.*\.rs" -> "$$FILE"
//@normalize-stderr-test: "\nLL \| .*" -> ""
//@normalize-stderr-test: "\| +[|_^]+" -> "| ^"
//@normalize-stderr-test: "\n *= note:.*" -> ""
use std::io::{self, Read};
fn main() {
let mut bytes = [0u8; 512];
io::stdin().read(&mut bytes).unwrap();
}

View file

@ -1,13 +1,14 @@
error: unsupported operation: `read` from stdin not available when isolation is enabled
--> tests/fail-dep/libc/fs/isolated_stdin.rs:LL:CC
--> RUSTLIB/std/$FILE:LL:CC
|
LL | libc::read(0, bytes.as_mut_ptr() as *mut libc::c_void, 512);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `read` from stdin not available when isolation is enabled
| ^ `read` from stdin not available when isolation is enabled
|
= help: set `MIRIFLAGS=-Zmiri-disable-isolation` to disable isolation;
= help: or set `MIRIFLAGS=-Zmiri-isolation-error=warn` to make Miri return an error code from isolated operations (if supported for that operation) and continue with a warning
= note: BACKTRACE:
= note: inside `main` at tests/fail-dep/libc/fs/isolated_stdin.rs:LL:CC
note: inside `main`
--> tests/fail/shims/isolated_stdin.rs:LL:CC
|
| ^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View file

@ -1,8 +1,10 @@
use std::io::{self, IsTerminal};
use std::io::{self, IsTerminal, Write};
fn main() {
// We can't really assume that this is truly a terminal, and anyway on Windows Miri will always
// return `false` here, but we can check that the call succeeds.
io::stdout().write_all(b"stdout\n").unwrap();
io::stderr().write_all(b"stderr\n").unwrap();
// We can't assume that this is truly a terminal, but we can check that the call succeeds.
io::stdout().is_terminal();
// Ensure we can format `io::Error` created from OS errors

View file

@ -0,0 +1 @@
stderr

View file

@ -0,0 +1 @@
stdout