nushell/crates/nu-command/tests/commands/let_.rs
mike fb72da0e82
unify the *-BuiltinVar parser errors (#8944)
# Description

this pr condenses `MutBuiltinVar`, `LetBuiltinVar` and `ConstBuiltinVar`
into one error:
```nu
Error: nu::parser::name_is_builtin_var

  × `in` used as variable name.
   ╭─[entry #69:1:1]
 1 │ let in = 420
   ·     ─┬
   ·      ╰── already a builtin variable
   ╰────
  help: 'in' is the name of a builtin Nushell variable and cannot be used
        as a variable name
```

it also fixes this case which was previously not handled
```nu
let $nu = 420 # this variable would have been 'lost'
```
2023-04-20 19:44:31 +02:00

38 lines
676 B
Rust

use nu_test_support::{nu, pipeline};
#[test]
fn let_name_builtin_var() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let in = 3
"#
));
assert!(actual
.err
.contains("'in' is the name of a builtin Nushell variable"));
}
#[test]
fn let_doesnt_mutate() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let i = 3; $i = 4
"#
));
assert!(actual.err.contains("immutable"));
}
#[test]
fn let_with_external_failed() {
let actual = nu!(
cwd: ".",
pipeline(r#"let x = nu --testbin outcome_err "aa"; echo fail"#)
);
assert!(!actual.out.contains("fail"));
}