From 1796d6ccd4bc150281f8b3c0353c44170910f894 Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Tue, 23 Jul 2024 00:13:07 -0700 Subject: [PATCH] make existing tests pass --- crates/nu-command/tests/commands/complete.rs | 4 ++-- crates/nu-command/tests/commands/rm.rs | 2 +- crates/nu-command/tests/commands/table.rs | 2 +- crates/nu-parser/src/parser.rs | 19 ++++++++----------- crates/nu-parser/tests/test_parser.rs | 15 +++++++-------- tests/plugins/env.rs | 6 +++--- tests/repl/test_config.rs | 2 +- 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/crates/nu-command/tests/commands/complete.rs b/crates/nu-command/tests/commands/complete.rs index 329e95ad71..5426d4e8bb 100644 --- a/crates/nu-command/tests/commands/complete.rs +++ b/crates/nu-command/tests/commands/complete.rs @@ -95,13 +95,13 @@ fn capture_error_with_both_stdout_stderr_messages_not_hang_nushell() { #[test] fn combined_pipe_redirection() { - let actual = nu!("$env.FOO = hello; $env.BAR = world; nu --testbin echo_env_mixed out-err FOO BAR o+e>| complete | get stdout"); + let actual = nu!("$env.FOO = 'hello'; $env.BAR = 'world'; nu --testbin echo_env_mixed out-err FOO BAR o+e>| complete | get stdout"); assert_eq!(actual.out, "helloworld"); } #[test] fn err_pipe_redirection() { let actual = - nu!("$env.FOO = hello; nu --testbin echo_env_stderr FOO e>| complete | get stdout"); + nu!("$env.FOO = 'hello'; nu --testbin echo_env_stderr FOO e>| complete | get stdout"); assert_eq!(actual.out, "hello"); } diff --git a/crates/nu-command/tests/commands/rm.rs b/crates/nu-command/tests/commands/rm.rs index e6cbf88cda..6baefd5420 100644 --- a/crates/nu-command/tests/commands/rm.rs +++ b/crates/nu-command/tests/commands/rm.rs @@ -144,7 +144,7 @@ fn errors_if_attempting_to_delete_home() { Playground::setup("rm_test_8", |dirs, _| { let actual = nu!( cwd: dirs.root(), - "$env.HOME = myhome ; rm -rf ~" + "$env.HOME = 'myhome' ; rm -rf ~" ); assert!(actual.err.contains("please use -I or -i")); diff --git a/crates/nu-command/tests/commands/table.rs b/crates/nu-command/tests/commands/table.rs index a4869f6bfa..363304ce71 100644 --- a/crates/nu-command/tests/commands/table.rs +++ b/crates/nu-command/tests/commands/table.rs @@ -2567,7 +2567,7 @@ fn theme_cmd(theme: &str, footer: bool, then: &str) -> String { with_footer = "$env.config.footer_mode = \"always\"".to_string(); } - format!("$env.config.table.mode = {theme}; $env.config.table.header_on_separator = true; {with_footer}; {then}") + format!("$env.config.table.mode = \"{theme}\"; $env.config.table.header_on_separator = true; {with_footer}; {then}") } #[test] diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index f588290e74..6014e9b434 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -4855,11 +4855,11 @@ pub fn parse_assignment_expression( } // Parse the lhs and operator as usual for a math expression - let lhs = parse_expression(working_set, lhs_spans); - let operator = parse_assignment_operator(working_set, op_span); + let mut lhs = parse_expression(working_set, lhs_spans); + let mut operator = parse_assignment_operator(working_set, op_span); // Re-parse the right-hand side as a subexpression - let rhs_span = Span::concat(&rhs_spans); + let rhs_span = Span::concat(rhs_spans); let (rhs_tokens, rhs_error) = lex( working_set.get_span_contents(rhs_span), @@ -4874,26 +4874,23 @@ pub fn parse_assignment_expression( let rhs_block = parse_block(working_set, &rhs_tokens, rhs_span, false, true); let rhs_ty = rhs_block.output_type(); let rhs_block_id = working_set.add_block(Arc::new(rhs_block)); - let rhs = Expression::new( + let mut rhs = Expression::new( working_set, Expr::Subexpression(rhs_block_id), rhs_span, rhs_ty, ); - if !type_compatible(&lhs.ty, &rhs.ty) { - working_set.parse_errors.push(ParseError::TypeMismatch( - lhs.ty.clone(), - rhs.ty.clone(), - rhs_span, - )); + let (result_ty, err) = math_result_type(working_set, &mut lhs, &mut operator, &mut rhs); + if let Some(err) = err { + working_set.parse_errors.push(err); } Expression::new( working_set, Expr::BinaryOp(Box::new(lhs), Box::new(operator), Box::new(rhs)), expr_span, - Type::Nothing, + result_ty, ) } diff --git a/crates/nu-parser/tests/test_parser.rs b/crates/nu-parser/tests/test_parser.rs index 7762863ba1..a992ff2281 100644 --- a/crates/nu-parser/tests/test_parser.rs +++ b/crates/nu-parser/tests/test_parser.rs @@ -1142,18 +1142,17 @@ fn test_nothing_comparison_eq() { #[rstest] #[case(b"let a = 1 err> /dev/null")] #[case(b"let a = 1 out> /dev/null")] -#[case(b"mut a = 1 err> /dev/null")] -#[case(b"mut a = 1 out> /dev/null")] #[case(b"let a = 1 out+err> /dev/null")] -#[case(b"mut a = 1 out+err> /dev/null")] -fn test_redirection_with_letmut(#[case] phase: &[u8]) { +fn test_redirection_with_let(#[case] phase: &[u8]) { let engine_state = EngineState::new(); let mut working_set = StateWorkingSet::new(&engine_state); + working_set.add_decl(Box::new(Let)); let _block = parse(&mut working_set, None, phase, true); - assert!(matches!( - working_set.parse_errors.first(), - Some(ParseError::RedirectingBuiltinCommand(_, _, _)) - )); + assert!( + working_set.parse_errors.is_empty(), + "parse errors: {:?}", + working_set.parse_errors + ); } #[rstest] diff --git a/tests/plugins/env.rs b/tests/plugins/env.rs index c5a2ccc7af..8b307999b3 100644 --- a/tests/plugins/env.rs +++ b/tests/plugins/env.rs @@ -6,9 +6,9 @@ fn get_env_by_name() { cwd: ".", plugin: ("nu_plugin_example"), r#" - $env.FOO = bar + $env.FOO = 'bar' example env FOO | print - $env.FOO = baz + $env.FOO = 'baz' example env FOO | print "# ); @@ -21,7 +21,7 @@ fn get_envs() { let result = nu_with_plugins!( cwd: ".", plugin: ("nu_plugin_example"), - "$env.BAZ = foo; example env | get BAZ" + "$env.BAZ = 'foo'; example env | get BAZ" ); assert!(result.status.success()); assert_eq!("foo", result.out); diff --git a/tests/repl/test_config.rs b/tests/repl/test_config.rs index 005ae63171..6c0ba6180f 100644 --- a/tests/repl/test_config.rs +++ b/tests/repl/test_config.rs @@ -20,7 +20,7 @@ fn mutate_nu_config_nested_ls() -> TestResult { fn mutate_nu_config_nested_table() -> TestResult { run_test_std( r#" - $env.config.table.trim.methodology = wrapping + $env.config.table.trim.methodology = 'wrapping' $env.config.table.trim.wrapping_try_keep_words = false $env.config.table.trim.wrapping_try_keep_words "#,