about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-05-11 00:21:24 -0400
committerGitHub <noreply@github.com>2017-05-11 00:21:24 -0400
commita00e18205342e82db3216dc1ea942392aafe30eb (patch)
treef346c620627bce19ec09a95eefb4df7ec861f683 /src/test
parentbb8d51c2ebe8d89c9cdcf06a9383d6e974efc5b6 (diff)
parent72588a2b2a1af655b81fcd3c1c467707d9c237c2 (diff)
Rollup merge of #41192 - zackw:eprintln, r=alexcrichton
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.  Issues #39228 and #40528; previous PR #39229; accepted RFC rust-lang/rfcs#1869; proposed revision to The Book rust-lang/book#615.

I have _not_ revised this any since the original submission; I will do that later this week.  I wanted to get this PR in place since it's been quite a while since the RFC was merged.

Known outstanding review comments:

* [x] @steveklabnik requested a new chapter for the unstable version of The Book -- please see if the proposed revisions to the second edition cover it.
* [x] @nodakai asked if it were possible to merge the internal methods `_print` and `_eprint` - not completely, since they both refer to different internal globals which we don't want to expose, but I will see if some duplication can be factored out.

Please let me know if I missed anything.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/print-stdout-eprint-stderr.rs40
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..0a0f30aba72
--- /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.
+
+// ignore-emscripten spawning processes is not supported
+
+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() }
+}