mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
Force timeit to not capture stdout (#12465)
# Description Fixes: #11996 After this change `let t = timeit ^ls` will list current directory to stdout. ``` ❯ let t = timeit ^ls CODE_OF_CONDUCT.md Cargo.lock Cross.toml README.md aaa benches devdocs here11 scripts target toolkit.nu wix CONTRIBUTING.md Cargo.toml LICENSE a.txt assets crates docker rust-toolchain.toml src tests typos.toml ``` If user don't want such behavior, he can redirect the stdout to `std null-stream` easily ``` > use std > let t = timeit { ^ls o> (std null-device) } ``` # User-Facing Changes NaN # Tests + Formatting Done # After Submitting Nan --------- Co-authored-by: Ian Manske <ian.manske@pm.me>
This commit is contained in:
parent
81c61f3243
commit
18ddf95d44
@ -44,6 +44,8 @@ impl Command for TimeIt {
|
||||
// Get the start time after all other computation has been done.
|
||||
let start_time = Instant::now();
|
||||
|
||||
// reset outdest, so the command can write to stdout and stderr.
|
||||
let stack = &mut stack.push_redirection(None, None);
|
||||
if let Some(command_to_run) = command_to_run {
|
||||
if let Some(block_id) = command_to_run.as_block() {
|
||||
let eval_block = get_eval_block(engine_state);
|
||||
|
1
crates/nu-command/tests/commands/debug/mod.rs
Normal file
1
crates/nu-command/tests/commands/debug/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
mod timeit;
|
14
crates/nu-command/tests/commands/debug/timeit.rs
Normal file
14
crates/nu-command/tests/commands/debug/timeit.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[test]
|
||||
fn timeit_show_stdout() {
|
||||
let actual = nu!("let t = timeit nu --testbin cococo abcdefg");
|
||||
assert_eq!(actual.out, "abcdefg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timeit_show_stderr() {
|
||||
let actual = nu!(" with-env {FOO: bar, FOO2: baz} { let t = timeit { nu --testbin echo_env_mixed out-err FOO FOO2 } }");
|
||||
assert!(actual.out.contains("bar"));
|
||||
assert!(actual.err.contains("baz"));
|
||||
}
|
@ -113,6 +113,7 @@ mod ucp;
|
||||
#[cfg(unix)]
|
||||
mod ulimit;
|
||||
|
||||
mod debug;
|
||||
mod umkdir;
|
||||
mod uname;
|
||||
mod uniq;
|
||||
|
@ -70,7 +70,7 @@ pub fn echo_env_mixed() {
|
||||
}
|
||||
|
||||
/// Cross platform echo using println!()
|
||||
/// Example: nu --testbin echo a b c
|
||||
/// Example: nu --testbin cococo a b c
|
||||
/// a b c
|
||||
pub fn cococo() {
|
||||
let args: Vec<String> = args();
|
||||
|
Loading…
Reference in New Issue
Block a user