From 026e18399ea8ba1819c75ea2afcea4e8cf10b4d2 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Thu, 14 Sep 2023 10:18:29 +1200 Subject: [PATCH] fix 'let' to properly redirect (#10360) # Description Fixes a bug in `let` where the pipeline wasn't being properly redirected. fixes #9767 # User-Facing Changes Shouldn't have any breaking changes, as this should be better for expected use cases. # Tests + Formatting # After Submitting --- crates/nu-cmd-lang/src/core_commands/let_.rs | 9 +-------- crates/nu-command/tests/commands/let_.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/nu-cmd-lang/src/core_commands/let_.rs b/crates/nu-cmd-lang/src/core_commands/let_.rs index 649035c8dd..6b020426a3 100644 --- a/crates/nu-cmd-lang/src/core_commands/let_.rs +++ b/crates/nu-cmd-lang/src/core_commands/let_.rs @@ -61,14 +61,7 @@ impl Command for Let { .expect("internal error: missing right hand side"); let block = engine_state.get_block(block_id); - let pipeline_data = eval_block( - engine_state, - stack, - block, - input, - call.redirect_stdout, - call.redirect_stderr, - )?; + let pipeline_data = eval_block(engine_state, stack, block, input, true, false)?; stack.add_var(var_id, pipeline_data.into_value(call.head)); Ok(PipelineData::empty()) } diff --git a/crates/nu-command/tests/commands/let_.rs b/crates/nu-command/tests/commands/let_.rs index 408dc5f6ff..5fa2fcc505 100644 --- a/crates/nu-command/tests/commands/let_.rs +++ b/crates/nu-command/tests/commands/let_.rs @@ -46,6 +46,20 @@ fn mut_pipeline_allows_in() { assert_eq!(actual.out, "21"); } +#[test] +fn let_pipeline_redirects_internals() { + let actual = nu!(r#"let x = echo 'bar'; $x | str length"#); + + assert_eq!(actual.out, "3"); +} + +#[test] +fn let_pipeline_redirects_externals() { + let actual = nu!(r#"let x = nu --testbin cococo 'bar'; $x | str length"#); + + assert_eq!(actual.out, "3"); +} + #[ignore] #[test] fn let_with_external_failed() {