mirror of
https://github.com/Tarrasch/zsh-autoenv.git
synced 2025-12-14 02:15:11 +02:00
Fixes after using setopt nounset during tests
Also add tests for unset variable with varstash.
This commit is contained in:
@@ -12,7 +12,7 @@ Manually create auth file
|
||||
|
||||
Now try to make it accept it
|
||||
|
||||
$ unset _autoenv_stack_entered
|
||||
$ _autoenv_stack_entered=()
|
||||
$ rm $AUTOENV_ENV_FILENAME
|
||||
$ _autoenv_ask_for_yes() { echo "yes" }
|
||||
$ cd .
|
||||
@@ -33,11 +33,11 @@ The last "ENTERED" is because it executed the command.
|
||||
|
||||
Now lets see that it actually checks the shasum value.
|
||||
|
||||
$ unset _autoenv_stack_entered
|
||||
$ _autoenv_stack_entered=()
|
||||
$ cd .
|
||||
ENTERED
|
||||
|
||||
$ unset _autoenv_stack_entered
|
||||
$ _autoenv_stack_entered=()
|
||||
$ rm $AUTOENV_ENV_FILENAME
|
||||
$ test_autoenv_add_to_env $PWD/.env mischief
|
||||
$ cd .
|
||||
@@ -56,7 +56,7 @@ Now lets see that it actually checks the shasum value.
|
||||
|
||||
Now, will it take no for an answer?
|
||||
|
||||
$ unset _autoenv_stack_entered
|
||||
$ _autoenv_stack_entered=()
|
||||
$ rm $AUTOENV_ENV_FILENAME
|
||||
$ _autoenv_ask_for_yes() { echo "no"; return 1 }
|
||||
$ cd .
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# Ensure we have our mocked out AUTOENV_ENV_FILENAME
|
||||
# (via .zshenv).
|
||||
|
||||
# Treat unset variables as errors.
|
||||
# Not handled in varstash yet.
|
||||
# setopt nounset
|
||||
|
||||
[[ $AUTOENV_ENV_FILENAME[0,4] == '/tmp' ]] || return 1
|
||||
|
||||
# Reset any authentication.
|
||||
@@ -8,7 +12,7 @@ echo -n > $AUTOENV_ENV_FILENAME
|
||||
|
||||
# Add file $1 (with optional hash $2) to authentication file.
|
||||
test_autoenv_add_to_env() {
|
||||
_autoenv_hash_pair $1 $2 >> $AUTOENV_ENV_FILENAME
|
||||
_autoenv_hash_pair $1 ${2:-} >> $AUTOENV_ENV_FILENAME
|
||||
}
|
||||
|
||||
# Add enter and leave env files to authentication file.
|
||||
|
||||
@@ -36,31 +36,23 @@ Test autounstashing when leaving a directory. {{{
|
||||
|
||||
Setup:
|
||||
|
||||
$ unset VAR
|
||||
$ cd sub
|
||||
ENTER
|
||||
$ echo 'echo ENTER; autostash VAR=changed' > $AUTOENV_FILE_ENTER
|
||||
$ echo 'echo LEAVE; echo "no explicit call to autounstash"' > $AUTOENV_FILE_LEAVE
|
||||
$ test_autoenv_auth_env_files
|
||||
|
||||
$VAR is empty:
|
||||
$VAR is unset:
|
||||
|
||||
$ echo VAR:$VAR
|
||||
VAR:
|
||||
$ echo VAR_set:$+VAR
|
||||
VAR_set:0
|
||||
|
||||
Set it:
|
||||
Trigger the autostashing in the enter file.
|
||||
|
||||
$ VAR=orig
|
||||
$ cd ..
|
||||
LEAVE
|
||||
no explicit call to autounstash
|
||||
|
||||
Leaving the directory keeps it intact - nothing had been stashed yet.
|
||||
|
||||
$ echo $VAR
|
||||
orig
|
||||
|
||||
Enter the dir, trigger the autostashing.
|
||||
|
||||
$ cd sub
|
||||
ENTER
|
||||
$ echo $VAR
|
||||
@@ -71,9 +63,8 @@ Now leave again.
|
||||
$ cd ..
|
||||
LEAVE
|
||||
no explicit call to autounstash
|
||||
$ echo $VAR
|
||||
orig
|
||||
|
||||
$ echo VAR_set:$+VAR
|
||||
VAR_set:0
|
||||
|
||||
Remove the leave file, auto-unstashing should still happen.
|
||||
|
||||
@@ -83,7 +74,20 @@ Remove the leave file, auto-unstashing should still happen.
|
||||
$ echo $VAR
|
||||
changed
|
||||
$ cd ..
|
||||
$ echo VAR_set:$+VAR
|
||||
VAR_set:0
|
||||
|
||||
And once again where a value gets restored.
|
||||
|
||||
$ VAR=orig_2
|
||||
$ echo $VAR
|
||||
orig
|
||||
orig_2
|
||||
$ cd sub
|
||||
ENTER
|
||||
$ echo $VAR
|
||||
changed
|
||||
$ cd ..
|
||||
$ echo $VAR
|
||||
orig_2
|
||||
|
||||
}}}
|
||||
|
||||
Reference in New Issue
Block a user