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("var_name", SyntaxShape::String, "variable name")
.required( .required(
"initial_value", "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", "equals sign followed by value",
) )
.category(Category::Env) .category(Category::Env)

View File

@ -194,7 +194,7 @@ fn let_sees_in_variable2() -> TestResult {
#[test] #[test]
fn def_env() -> TestResult { fn def_env() -> TestResult {
run_test( 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", "BAZ",
) )
} }
@ -202,7 +202,7 @@ fn def_env() -> TestResult {
#[test] #[test]
fn not_def_env() -> TestResult { fn not_def_env() -> TestResult {
fail_test( 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", "did you mean",
) )
} }
@ -226,7 +226,7 @@ fn def_env_then_hide() -> TestResult {
#[test] #[test]
fn export_def_env() -> TestResult { fn export_def_env() -> TestResult {
run_test( 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", "BAZ",
) )
} }

View File

@ -189,3 +189,11 @@ fn commands_have_usage() -> TestResult {
fn equals_separates_long_flag() -> TestResult { fn equals_separates_long_flag() -> TestResult {
run_test(r#"seq 1 4 --separator='+'"#, "1+2+3+4") 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!( let actual = nu!(
cwd: ".", cwd: ".",
r#" 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"); assert_eq!(actual.out, "truefalsetrue");
@ -513,7 +513,7 @@ fn proper_shadow_load_env_aliases() {
let actual = nu!( let actual = nu!(
cwd: ".", cwd: ".",
r#" 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"); assert_eq!(actual.out, "truefalsetrue");