Skip to content

Commit

Permalink
Auto merge of #2144 - matthiaskrgr:stderrfix, r=RalfJung
Browse files Browse the repository at this point in the history
mute_stdout_stderr: mute stderr instead of stdin

should fix #2143

note: this is entirely untested, I was getting tons of errors on `cargo test` because of some missing setup.
I hope that CI can tell me if this works or not 🙈

r? `@oli-obk`
  • Loading branch information
bors committed May 22, 2022
2 parents e3227cf + 89da571 commit 62ea0c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/shims/posix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ trait FileDescriptor: std::fmt::Debug {
communicate_allowed: bool,
bytes: &mut [u8],
) -> InterpResult<'tcx, io::Result<usize>>;

fn write<'tcx>(
&self,
communicate_allowed: bool,
bytes: &[u8],
) -> InterpResult<'tcx, io::Result<usize>>;

fn seek<'tcx>(
&mut self,
communicate_allowed: bool,
offset: SeekFrom,
) -> InterpResult<'tcx, io::Result<u64>>;

fn close<'tcx>(
self: Box<Self>,
_communicate_allowed: bool,
Expand Down Expand Up @@ -304,14 +307,14 @@ pub struct FileHandler {
impl<'tcx> FileHandler {
pub(crate) fn new(mute_stdout_stderr: bool) -> FileHandler {
let mut handles: BTreeMap<_, Box<dyn FileDescriptor>> = BTreeMap::new();
handles.insert(0i32, Box::new(io::stdin()));
if mute_stdout_stderr {
handles.insert(0i32, Box::new(DummyOutput));
handles.insert(1i32, Box::new(DummyOutput));
handles.insert(2i32, Box::new(DummyOutput));
} else {
handles.insert(0i32, Box::new(io::stdin()));
handles.insert(1i32, Box::new(io::stdout()));
handles.insert(2i32, Box::new(io::stderr()));
}
handles.insert(2i32, Box::new(io::stderr()));
FileHandler { handles }
}

Expand Down
3 changes: 2 additions & 1 deletion tests/run-pass/hide_stdout.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// compile-flags: -Zmiri-mute-stdout-stderr

fn main() {
println!("cake");
println!("print to stdout");
eprintln!("print to stderr");
}

0 comments on commit 62ea0c8

Please sign in to comment.