mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 00:54:56 +02:00
Hiding of environment variables (#362)
* Remember environment variables from previous scope * Re-introduce env var hiding Right now, hiding decls is broken * Re-introduce hidden field of import patterns All tests pass now. * Remove/Address tests TODOs * Fix test typo; Report hiding error * Add a few more tests * Fix wrong expected test result
This commit is contained in:
@ -126,7 +126,7 @@ fn main() -> Result<()> {
|
||||
let mut stack = nu_protocol::engine::Stack::new();
|
||||
|
||||
for (k, v) in std::env::vars() {
|
||||
stack.env_vars.insert(k, v);
|
||||
stack.add_env_var(k, v);
|
||||
}
|
||||
|
||||
// Set up our initial config to start from
|
||||
@ -170,7 +170,7 @@ fn main() -> Result<()> {
|
||||
let mut stack = nu_protocol::engine::Stack::new();
|
||||
|
||||
for (k, v) in std::env::vars() {
|
||||
stack.env_vars.insert(k, v);
|
||||
stack.add_env_var(k, v);
|
||||
}
|
||||
|
||||
// Set up our initial config to start from
|
||||
|
102
src/tests.rs
102
src/tests.rs
@ -474,6 +474,22 @@ fn module_env_imports_5() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_def_and_env_imports_1() -> TestResult {
|
||||
run_test(
|
||||
r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; $nu.env.foo"#,
|
||||
"foo",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_def_and_env_imports_2() -> TestResult {
|
||||
run_test(
|
||||
r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; foo"#,
|
||||
"bar",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_def_import_uses_internal_command() -> TestResult {
|
||||
run_test(
|
||||
@ -496,7 +512,7 @@ fn hides_def() -> TestResult {
|
||||
fail_test(r#"def foo [] { "foo" }; hide foo; foo"#, not_found_msg())
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env() -> TestResult {
|
||||
fail_test(
|
||||
r#"let-env foo = "foo"; hide foo; $nu.env.foo"#,
|
||||
@ -514,7 +530,7 @@ fn hides_def_then_redefines() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_then_redefines() -> TestResult {
|
||||
run_test(
|
||||
r#"let-env foo = "foo"; hide foo; let-env foo = "bar"; $nu.env.foo"#,
|
||||
@ -554,7 +570,7 @@ fn hides_def_in_scope_4() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_in_scope_1() -> TestResult {
|
||||
fail_test(
|
||||
r#"let-env foo = "foo"; do { hide foo; $nu.env.foo }"#,
|
||||
@ -562,16 +578,15 @@ fn hides_env_in_scope_1() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_in_scope_2() -> TestResult {
|
||||
// TODO: Revisit this -- 'hide foo' should restore the env, not hide it completely
|
||||
run_test(
|
||||
r#"let-env foo = "foo"; do { let-env foo = "bar"; hide foo; $nu.env.foo }"#,
|
||||
"foo",
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_in_scope_3() -> TestResult {
|
||||
fail_test(
|
||||
r#"let-env foo = "foo"; do { hide foo; let-env foo = "bar"; hide foo; $nu.env.foo }"#,
|
||||
@ -579,9 +594,8 @@ fn hides_env_in_scope_3() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_in_scope_4() -> TestResult {
|
||||
// TODO: Revisit this -- 'hide foo' should restore the env, not hide it completely
|
||||
fail_test(
|
||||
r#"let-env foo = "foo"; do { let-env foo = "bar"; hide foo; hide foo; $nu.env.foo }"#,
|
||||
"did you mean",
|
||||
@ -590,31 +604,38 @@ fn hides_env_in_scope_4() -> TestResult {
|
||||
|
||||
#[test]
|
||||
fn hide_def_twice_not_allowed() -> TestResult {
|
||||
fail_test(r#"def foo [] { "foo" }; hide foo; hide foo"#, "not found")
|
||||
fail_test(
|
||||
r#"def foo [] { "foo" }; hide foo; hide foo"#,
|
||||
"did not find",
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hide_env_twice_not_allowed() -> TestResult {
|
||||
fail_test(r#"let-env foo = "foo"; hide foo; hide foo"#, "did not find")
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
fn hides_def_runs_env() -> TestResult {
|
||||
// TODO: We need some precedence system to handle this. Currently, 'hide foo' hides both the
|
||||
// def and env var.
|
||||
#[test]
|
||||
fn hides_def_runs_env_1() -> TestResult {
|
||||
run_test(
|
||||
r#"let-env foo = "bar"; def foo [] { "foo" }; hide foo; $nu.env.foo"#,
|
||||
"bar",
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_def_runs_env_2() -> TestResult {
|
||||
run_test(
|
||||
r#"def foo [] { "foo" }; let-env foo = "bar"; hide foo; $nu.env.foo"#,
|
||||
"bar",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hides_def_and_env() -> TestResult {
|
||||
// TODO: We need some precedence system to handle this. Currently, 'hide foo' hides both the
|
||||
// def and env var.
|
||||
fail_test(
|
||||
r#"let-env foo = "bar"; def foo [] { "foo" }; hide foo; hide foo; $nu.env.foo"#,
|
||||
not_found_msg(),
|
||||
"did you mean",
|
||||
)
|
||||
}
|
||||
|
||||
@ -666,7 +687,7 @@ fn hides_def_import_6() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_import_1() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" } }; use spam; hide spam foo; $nu.env.'spam foo'"#,
|
||||
@ -674,7 +695,7 @@ fn hides_env_import_1() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_import_2() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" } }; use spam; hide spam *; $nu.env.'spam foo'"#,
|
||||
@ -682,15 +703,15 @@ fn hides_env_import_2() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_import_3() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" }; } use spam; hide spam [foo]; $nu.env.'spam foo'"#,
|
||||
r#"module spam { export env foo { "foo" } }; use spam; hide spam [foo]; $nu.env.'spam foo'"#,
|
||||
"did you mean",
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_import_4() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" } }; use spam foo; hide foo; $nu.env.foo"#,
|
||||
@ -698,7 +719,7 @@ fn hides_env_import_4() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_import_5() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" } }; use spam *; hide foo; $nu.env.foo"#,
|
||||
@ -706,7 +727,7 @@ fn hides_env_import_5() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_env_import_6() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" } }; use spam; hide spam; $nu.env.'spam foo'"#,
|
||||
@ -714,6 +735,30 @@ fn hides_env_import_6() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hides_def_runs_env_import() -> TestResult {
|
||||
run_test(
|
||||
r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; hide foo; $nu.env.foo"#,
|
||||
"foo",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hides_def_and_env_import_1() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; hide foo; hide foo; $nu.env.foo"#,
|
||||
"did you mean",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hides_def_and_env_import_2() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; hide foo; hide foo; foo"#,
|
||||
not_found_msg(),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_twice_should_fail() -> TestResult {
|
||||
fail_test(
|
||||
@ -730,7 +775,7 @@ fn use_def_import_after_hide() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn use_env_import_after_hide() -> TestResult {
|
||||
run_test(
|
||||
r#"module spam { export env foo { "foo" } }; use spam foo; hide foo; use spam foo; $nu.env.foo"#,
|
||||
@ -746,9 +791,8 @@ fn hide_shadowed_decl() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hide_shadowed_env() -> TestResult {
|
||||
// TODO: waiting for a fix
|
||||
run_test(
|
||||
r#"module spam { export env foo { "bar" } }; let-env foo = "foo"; do { use spam foo; hide foo; $nu.env.foo }"#,
|
||||
"foo",
|
||||
@ -763,7 +807,7 @@ fn hides_all_decls_within_scope() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn hides_all_envs_within_scope() -> TestResult {
|
||||
fail_test(
|
||||
r#"module spam { export env foo { "bar" } }; let-env foo = "foo"; use spam foo; hide foo; $nu.env.foo"#,
|
||||
|
Reference in New Issue
Block a user