diff options
| author | Zack Weinberg <zackw@panix.com> | 2017-01-21 13:38:11 -0500 |
|---|---|---|
| committer | Zack Weinberg <zackw@panix.com> | 2017-05-10 09:29:16 -0400 |
| commit | 76127275a09d970169952bcf616f966faa9ed6db (patch) | |
| tree | def3a13636f3b6fa69cc4cf4fe7782da05994082 /src/test/run-pass | |
| parent | 2b97174ada7fb1854269558ed2cf3b089e58beee (diff) | |
| download | rust-76127275a09d970169952bcf616f966faa9ed6db.tar.gz rust-76127275a09d970169952bcf616f966faa9ed6db.zip | |
Add `eprint!` and `eprintln!` macros to the prelude.
These are exactly the same as `print!` and `println!` except that they write to stderr instead of stdout. Issue #39228.
Diffstat (limited to 'src/test/run-pass')
| -rw-r--r-- | src/test/run-pass/print-stdout-eprint-stderr.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/run-pass/print-stdout-eprint-stderr.rs b/src/test/run-pass/print-stdout-eprint-stderr.rs new file mode 100644 index 00000000000..8ca6e1c6356 --- /dev/null +++ b/src/test/run-pass/print-stdout-eprint-stderr.rs @@ -0,0 +1,40 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(eprint)] + +use std::{env, process}; + +fn child() { + print!("[stdout 0]"); + print!("[stdout {}]", 1); + println!("[stdout {}]", 2); + println!(); + eprint!("[stderr 0]"); + eprint!("[stderr {}]", 1); + eprintln!("[stderr {}]", 2); + eprintln!(); +} + +fn parent() { + let this = env::args().next().unwrap(); + let output = process::Command::new(this).arg("-").output().unwrap(); + assert!(output.status.success()); + + let stdout = String::from_utf8(output.stdout).unwrap(); + let stderr = String::from_utf8(output.stderr).unwrap(); + + assert_eq!(stdout, "[stdout 0][stdout 1][stdout 2]\n\n"); + assert_eq!(stderr, "[stderr 0][stderr 1][stderr 2]\n\n"); +} + +fn main() { + if env::args().count() == 2 { child() } else { parent() } +} |
