mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Make let-env
work like let
(#4389)
* Make let-env work like let * Fix tests
This commit is contained in:
parent
5d18e07b7d
commit
fc88a8538b
4 changed files with 14 additions and 6 deletions
2
crates/nu-command/src/env/let_env.rs
vendored
2
crates/nu-command/src/env/let_env.rs
vendored
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue