mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 14:50:02 +02:00
Make sure that overwritten vals are restored
This commit is contained in:
parent
adad7e8aac
commit
55e4e84f5d
@ -244,38 +244,32 @@ mod tests {
|
|||||||
use nu_test_support::playground::Playground;
|
use nu_test_support::playground::Playground;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_autoenv_vars_are_added_and_removed() {
|
fn autoenv() {
|
||||||
Playground::setup("autoenv_test_1", |dirs, sandbox| {
|
Playground::setup("autoenv_test_1", |dirs, sandbox| {
|
||||||
sandbox.mkdir("foo/bar");
|
sandbox.mkdir("foo/bar");
|
||||||
sandbox.with_files(vec![
|
sandbox.with_files(vec![
|
||||||
FileWithContent(
|
FileWithContent(
|
||||||
".nu-env",
|
".nu-env",
|
||||||
r#"
|
r#"[env]
|
||||||
[env]
|
|
||||||
testkey = "testvalue"
|
testkey = "testvalue"
|
||||||
[scriptvars]
|
[scriptvars]
|
||||||
myscript = "echo 'myval'"
|
myscript = "echo 'myval'"
|
||||||
|
|
||||||
[scripts]
|
[scripts]
|
||||||
entryscripts = ["touch hello.txt"]
|
entryscripts = ["touch hello.txt"]
|
||||||
exitscripts = ["touch bye.txt"]
|
exitscripts = ["touch bye.txt"]"#,
|
||||||
"#,
|
|
||||||
),
|
),
|
||||||
FileWithContent(
|
FileWithContent(
|
||||||
"foo/.nu-env",
|
"foo/.nu-env",
|
||||||
r#"
|
r#"[env]
|
||||||
[env]
|
overwrite_me = "set_in_foo"
|
||||||
overwrite_me = "set_in_foo"
|
fookey = "fooval""#,
|
||||||
fookey = "fooval"
|
|
||||||
"#,
|
|
||||||
),
|
),
|
||||||
FileWithContent(
|
FileWithContent(
|
||||||
"foo/bar/.nu-env",
|
"foo/bar/.nu-env",
|
||||||
r#"
|
r#"[env]
|
||||||
[env]
|
overwrite_me = "set_in_bar""#,
|
||||||
overwrite_me = "set_in_bar"
|
),
|
||||||
"#,
|
|
||||||
)
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Make sure basic keys are set
|
//Make sure basic keys are set
|
||||||
@ -326,8 +320,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert!(actual.out.ends_with("set_in_bar"));
|
assert!(actual.out.ends_with("set_in_bar"));
|
||||||
|
|
||||||
|
//Variables set in parent directories should be set even if you directly cd to a subdir
|
||||||
//Variables set in parent directories should be set even if you cd to a subdir
|
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: dirs.test(),
|
cwd: dirs.test(),
|
||||||
r#"autoenv trust foo
|
r#"autoenv trust foo
|
||||||
@ -336,6 +329,18 @@ mod tests {
|
|||||||
echo $nu.env.fookey"#
|
echo $nu.env.fookey"#
|
||||||
);
|
);
|
||||||
assert!(actual.out.ends_with("fooval"));
|
assert!(actual.out.ends_with("fooval"));
|
||||||
|
|
||||||
|
//Make sure that overwritten values are restored.
|
||||||
|
//By deleting foo/.nu-env, we make sure that the value is actually restored and not just set again by autoenv when we re-visit foo.
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
r#"cd foo
|
||||||
|
cd bar
|
||||||
|
rm ../.nu-env
|
||||||
|
cd ..
|
||||||
|
echo $nu.env.overwrite_me"#
|
||||||
|
);
|
||||||
|
assert!(actual.out.ends_with("set_in_foo"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user