From 13519f96012cf0c1a2f52bcddb6ec92dea8ac854 Mon Sep 17 00:00:00 2001 From: Sam Hedin Date: Fri, 10 Jul 2020 03:14:11 +0200 Subject: [PATCH] Tests --- .../src/env/directory_specific_environment.rs | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/nu-cli/src/env/directory_specific_environment.rs b/crates/nu-cli/src/env/directory_specific_environment.rs index 2f8c98f63..cf5b85abf 100644 --- a/crates/nu-cli/src/env/directory_specific_environment.rs +++ b/crates/nu-cli/src/env/directory_specific_environment.rs @@ -244,26 +244,45 @@ mod tests { use nu_test_support::fs::Stub::FileWithContent; #[test] - fn basic_autoenv_vars_are_added(){ + fn basic_autoenv_vars_are_added_and_removed(){ Playground::setup("autoenv_test_1", |dirs, sandbox| { - // sandbox.mkdir("autoenv_test_dir"); + sandbox.with_files(vec![FileWithContent( ".nu-env", r#" [env] testkey = "testvalue" + [scriptvars] + myscript = "echo 'myval'" + + [scripts] + entryscripts = ["touch hello.txt"] + exitscripts = ["touch bye.txt"] "#, )]); - + //Make sure basic keys are set let actual = nu!( cwd: dirs.test(), r#"autoenv trust -echo $nu.env.testkey"# - // r#"open .nu-env | from toml | get env | echo $it"# + echo $nu.env.testkey"# ); - assert!(actual.out.ends_with("testvalue")); + + // //Make sure script keys are set + let actual = nu!( + cwd: dirs.test(), + r#"echo $nu.env.myscript"# + ); + assert!(actual.out.ends_with("myval")); + + //Back out of directory + let actual = nu!( + cwd: dirs.test(), + r#"cd .. + echo $nu.env.testkey"# + ); + assert!(!actual.out.ends_with("testvalue")); }) } }