diff --git a/crates/nu-command/src/debug/timeit.rs b/crates/nu-command/src/debug/timeit.rs index 0dcf85725f..2747db02af 100644 --- a/crates/nu-command/src/debug/timeit.rs +++ b/crates/nu-command/src/debug/timeit.rs @@ -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); diff --git a/crates/nu-command/tests/commands/debug/mod.rs b/crates/nu-command/tests/commands/debug/mod.rs new file mode 100644 index 0000000000..4d5674a0d9 --- /dev/null +++ b/crates/nu-command/tests/commands/debug/mod.rs @@ -0,0 +1 @@ +mod timeit; diff --git a/crates/nu-command/tests/commands/debug/timeit.rs b/crates/nu-command/tests/commands/debug/timeit.rs new file mode 100644 index 0000000000..a59f67d26a --- /dev/null +++ b/crates/nu-command/tests/commands/debug/timeit.rs @@ -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")); +} diff --git a/crates/nu-command/tests/commands/mod.rs b/crates/nu-command/tests/commands/mod.rs index ddb84a72c0..af1f2079d2 100644 --- a/crates/nu-command/tests/commands/mod.rs +++ b/crates/nu-command/tests/commands/mod.rs @@ -113,6 +113,7 @@ mod ucp; #[cfg(unix)] mod ulimit; +mod debug; mod umkdir; mod uname; mod uniq; diff --git a/src/test_bins.rs b/src/test_bins.rs index c491bcbdbc..97fe9cc357 100644 --- a/src/test_bins.rs +++ b/src/test_bins.rs @@ -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 = args();