From a3c145432e9bdf4b4c411da78df14ac492086dca Mon Sep 17 00:00:00 2001 From: Wind Date: Thu, 14 Nov 2024 17:05:33 +0800 Subject: [PATCH] Tests: add a test to make sure that function can't use mutable variable (#14314) @sholderbach suggested that we need to have a test for a function can't use mutable variable. https://github.com/nushell/nushell/pull/14311#issuecomment-2470035194 So this pr is going to add a case for it. --------- Co-authored-by: Stefan Holderbach --- crates/nu-command/tests/commands/mut_.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/nu-command/tests/commands/mut_.rs b/crates/nu-command/tests/commands/mut_.rs index e66348f8f2..52aa9fcff1 100644 --- a/crates/nu-command/tests/commands/mut_.rs +++ b/crates/nu-command/tests/commands/mut_.rs @@ -141,3 +141,10 @@ fn mut_raw_string() { let actual = nu!(r#"mut x = r#'abc'#; $x"#); assert_eq!(actual.out, "abc"); } + +#[test] +fn def_should_not_mutate_mut() { + let actual = nu!("mut a = 3; def foo [] { $a = 4}"); + assert!(actual.err.contains("capture of mutable variable")); + assert!(!actual.status.success()) +}