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 <sholderbach@users.noreply.github.com>
This commit is contained in:
Wind 2024-11-14 17:05:33 +08:00 committed by GitHub
parent e6f55da080
commit a3c145432e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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())
}