mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 01:37:49 +02:00
Run exitscripts in original dir (#2352)
* Modify testcase * Run exitscript in the folder it was specified * Update documentation * Add comment * Borrow instead of clone * Does this just... work on windows? * fmt * as_str * Collapse if by order of clippy * Support windows * fmt * refactor tests * fmt * This time it will work on windows FOR SURE * Remove debug prints * Comment * Refactor tests * fmt * fix spelling * update comment
This commit is contained in:
@ -48,36 +48,31 @@ fn autoenv() {
|
||||
sandbox.mkdir("bizz/buzz");
|
||||
sandbox.mkdir("foob");
|
||||
|
||||
let scriptfile = if cfg!(target_os = "windows") {
|
||||
FileWithContent(
|
||||
".nu-env",
|
||||
r#"[env]
|
||||
testkey = "testvalue"
|
||||
// Windows uses a different command to create an empty file so we need to have different content on windows.
|
||||
let full_nu_env = if cfg!(target_os = "windows") {
|
||||
r#"[env]
|
||||
testkey = "testvalue"
|
||||
|
||||
[scriptvars]
|
||||
myscript = "echo myval"
|
||||
[scriptvars]
|
||||
myscript = "echo myval"
|
||||
|
||||
[scripts]
|
||||
entryscripts = ["echo nul > hello.txt"]
|
||||
exitscripts = ["echo nul > bye.txt"]"#,
|
||||
)
|
||||
[scripts]
|
||||
entryscripts = ["echo nul > hello.txt"]
|
||||
exitscripts = ["echo nul > bye.txt"]"#
|
||||
} else {
|
||||
FileWithContent(
|
||||
".nu-env",
|
||||
r#"[env]
|
||||
testkey = "testvalue"
|
||||
r#"[env]
|
||||
testkey = "testvalue"
|
||||
|
||||
[scriptvars]
|
||||
myscript = "echo myval"
|
||||
[scriptvars]
|
||||
myscript = "echo myval"
|
||||
|
||||
[scripts]
|
||||
entryscripts = ["touch hello.txt"]
|
||||
exitscripts = ["touch bye.txt"]"#,
|
||||
)
|
||||
[scripts]
|
||||
entryscripts = ["touch hello.txt"]
|
||||
exitscripts = ["touch bye.txt"]"#
|
||||
};
|
||||
|
||||
sandbox.with_files(vec![
|
||||
scriptfile,
|
||||
FileWithContent(".nu-env", full_nu_env),
|
||||
FileWithContent(
|
||||
"foo/.nu-env",
|
||||
r#"[env]
|
||||
@ -89,14 +84,28 @@ fn autoenv() {
|
||||
r#"[env]
|
||||
overwrite_me = "set_in_bar""#,
|
||||
),
|
||||
FileWithContent(
|
||||
"bizz/.nu-env",
|
||||
r#"[scripts]
|
||||
entryscripts = ["touch hello.txt"]
|
||||
exitscripts = ["touch bye.txt"]"#,
|
||||
),
|
||||
FileWithContent("bizz/.nu-env", full_nu_env),
|
||||
]);
|
||||
|
||||
//Make sure basic keys are set
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"autoenv trust
|
||||
echo $nu.env.testkey"#
|
||||
);
|
||||
assert!(actual.out.ends_with("testvalue"));
|
||||
|
||||
// Make sure exitscripts are run in the directory they were specified.
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"autoenv trust
|
||||
cd ..
|
||||
cd autoenv_test
|
||||
ls
|
||||
ls | where name == "bye.txt" | get name"#
|
||||
);
|
||||
assert!(actual.out.contains("bye.txt"));
|
||||
|
||||
// Make sure entry scripts are run
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
@ -116,7 +125,7 @@ fn autoenv() {
|
||||
);
|
||||
assert!(!actual.out.contains("bye.txt"));
|
||||
|
||||
// Make sure entry scripts are run when re-visiting a directory
|
||||
// Make sure entryscripts are run when re-visiting a directory
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"autoenv trust bizz
|
||||
@ -138,14 +147,6 @@ fn autoenv() {
|
||||
);
|
||||
assert!(!actual.out.ends_with("hello.txt"));
|
||||
|
||||
//Make sure basic keys are set
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"autoenv trust
|
||||
echo $nu.env.testkey"#
|
||||
);
|
||||
assert!(actual.out.ends_with("testvalue"));
|
||||
|
||||
//Backing out of the directory should unset the keys
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
@ -189,14 +190,6 @@ fn autoenv() {
|
||||
);
|
||||
assert!(actual.out.contains("hello.txt"));
|
||||
|
||||
// Make sure exit scripts are run
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"cd ..
|
||||
ls | where name == "bye.txt" | get name"#
|
||||
);
|
||||
assert!(actual.out.contains("bye.txt"));
|
||||
|
||||
//Variables set in parent directories should be set even if you directly cd to a subdir
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
|
Reference in New Issue
Block a user