Use the correct stderr when testing libstd

This commit is contained in:
Jethro Beekman
2019-02-14 18:06:01 +05:30
parent 350674b718
commit c0e8cf9410
4 changed files with 41 additions and 19 deletions

View File

@@ -1,3 +1,5 @@
#![cfg_attr(test, allow(unused))]
use crate::io::prelude::*;
use crate::cell::RefCell;
@@ -16,6 +18,13 @@ thread_local! {
}
}
/// Stderr used by eprint! and eprintln! macros, and panics
thread_local! {
static LOCAL_STDERR: RefCell<Option<Box<dyn Write + Send>>> = {
RefCell::new(None)
}
}
/// A handle to a raw instance of the standard input stream of this process.
///
/// This handle is not synchronized or buffered in any fashion. Constructed via
@@ -668,7 +677,6 @@ impl fmt::Debug for StderrLock<'_> {
issue = "0")]
#[doc(hidden)]
pub fn set_panic(sink: Option<Box<dyn Write + Send>>) -> Option<Box<dyn Write + Send>> {
use crate::panicking::LOCAL_STDERR;
use crate::mem;
LOCAL_STDERR.with(move |slot| {
mem::replace(&mut *slot.borrow_mut(), sink)
@@ -740,6 +748,7 @@ where
reason = "implementation detail which may disappear or be replaced at any time",
issue = "0")]
#[doc(hidden)]
#[cfg(not(test))]
pub fn _print(args: fmt::Arguments) {
print_to(args, &LOCAL_STDOUT, stdout, "stdout");
}
@@ -748,11 +757,14 @@ pub fn _print(args: fmt::Arguments) {
reason = "implementation detail which may disappear or be replaced at any time",
issue = "0")]
#[doc(hidden)]
#[cfg(not(test))]
pub fn _eprint(args: fmt::Arguments) {
use crate::panicking::LOCAL_STDERR;
print_to(args, &LOCAL_STDERR, stderr, "stderr");
}
#[cfg(test)]
pub use realstd::io::{_eprint, _print};
#[cfg(test)]
mod tests {
use crate::panic::{UnwindSafe, RefUnwindSafe};