add -e flag to print, to print the value to stderr (#5935)

* Refactor: make stdout write all and flush as generic function

* support print to stderr
This commit is contained in:
WindSoilder
2022-07-02 22:54:49 +08:00
committed by GitHub
parent be7f35246e
commit 84caf8859f
8 changed files with 64 additions and 16 deletions

View File

@ -44,6 +44,7 @@ mod open;
mod parse;
mod path;
mod prepend;
mod print;
#[cfg(feature = "database")]
mod query;
mod random;

View File

@ -0,0 +1,23 @@
use nu_test_support::{nu, pipeline};
#[test]
fn print_to_stdout() {
let actual = nu!(
cwd: ".", pipeline(
"print 'hello world'"
)
);
assert!(actual.out.contains("hello world"));
assert!(actual.err.is_empty());
}
#[test]
fn print_to_stderr() {
let actual = nu!(
cwd: ".", pipeline(
"print -e 'hello world'"
)
);
assert!(actual.out.is_empty());
assert!(actual.err.contains("hello world"));
}