mirror of
https://github.com/nushell/nushell.git
synced 2025-04-04 14:40:43 +02: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
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("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)
|
||||||
|
@ -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",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -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");
|
||||||
|
Loading…
Reference in New Issue
Block a user