Make let-env work like let (#4389)

* Make let-env work like let

* Fix tests
This commit is contained in:
JT 2022-02-09 13:41:41 -05:00 committed by GitHub
parent 5d18e07b7d
commit fc88a8538b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View file

@ -20,7 +20,7 @@ impl Command for LetEnv {
.required("var_name", SyntaxShape::String, "variable name")
.required(
"initial_value",
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Any)),
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
"equals sign followed by value",
)
.category(Category::Env)

View file

@ -194,7 +194,7 @@ fn let_sees_in_variable2() -> TestResult {
#[test]
fn def_env() -> TestResult {
run_test(
r#"def-env bob [] { let-env BAR = BAZ }; bob; $env.BAR"#,
r#"def-env bob [] { let-env BAR = "BAZ" }; bob; $env.BAR"#,
"BAZ",
)
}
@ -202,7 +202,7 @@ fn def_env() -> TestResult {
#[test]
fn not_def_env() -> TestResult {
fail_test(
r#"def bob [] { let-env BAR = BAZ }; bob; $env.BAR"#,
r#"def bob [] { let-env BAR = "BAZ" }; bob; $env.BAR"#,
"did you mean",
)
}
@ -226,7 +226,7 @@ fn def_env_then_hide() -> TestResult {
#[test]
fn export_def_env() -> TestResult {
run_test(
r#"module foo { export def-env bob [] { let-env BAR = BAZ } }; use foo bob; bob; $env.BAR"#,
r#"module foo { export def-env bob [] { let-env BAR = "BAZ" } }; use foo bob; bob; $env.BAR"#,
"BAZ",
)
}

View file

@ -189,3 +189,11 @@ fn commands_have_usage() -> TestResult {
fn equals_separates_long_flag() -> TestResult {
run_test(r#"seq 1 4 --separator='+'"#, "1+2+3+4")
}
#[test]
fn let_env_expressions() -> TestResult {
run_test(
r#"let-env PATH = if (env | any? name == VENV_OLD_PATH) { $env.VENV_OLD_PATH } else { $env.PATH }; echo done"#,
"done",
)
}

View file

@ -464,7 +464,7 @@ fn proper_shadow_let_env_aliases() {
let actual = nu!(
cwd: ".",
r#"
let-env DEBUG = true; echo $env.DEBUG | table; do { let-env DEBUG = false; echo $env.DEBUG } | table; echo $env.DEBUG
let-env DEBUG = "true"; echo $env.DEBUG | table; do { let-env DEBUG = "false"; echo $env.DEBUG } | table; echo $env.DEBUG
"#
);
assert_eq!(actual.out, "truefalsetrue");
@ -513,7 +513,7 @@ fn proper_shadow_load_env_aliases() {
let actual = nu!(
cwd: ".",
r#"
let-env DEBUG = true; echo $env.DEBUG | table; do { echo {DEBUG: "false"} | load-env; echo $env.DEBUG } | table; echo $env.DEBUG
let-env DEBUG = "true"; echo $env.DEBUG | table; do { echo {DEBUG: "false"} | load-env; echo $env.DEBUG } | table; echo $env.DEBUG
"#
);
assert_eq!(actual.out, "truefalsetrue");