1
0
mirror of https://github.com/Tarrasch/zsh-autoenv.git synced 2024-11-05 01:10:59 +02:00
zsh-autoenv/tests/varstash.t
Daniel Hahler ecf2b2961f Only source varstash lib if it's being used
I have noticed that `autostash` called an (accidentally)
defined/overwritten `stash` function.

While it's not possible to put this into a local scope, this will at
least make it less polluting by default (when autostashing is not used).

Additionally we could source it always (not just once), but then it
would only re-overwrite the function.

A better fix would be to prefix the functions explicitly, e.g.
`autoenv_autostash` etc.

Closes https://github.com/Tarrasch/zsh-autoenv/pull/42.
2016-04-28 20:44:05 +02:00

109 lines
1.7 KiB
Perl

Test varstash integration.
$ source $TESTDIR/setup.zsh || return 1
Setup test environment.
$ mkdir sub
$ cd sub
The varstash library should not get loaded always.
$ echo 'echo ENTER' > $AUTOENV_FILE_ENTER
$ echo 'echo LEAVE' > $AUTOENV_FILE_LEAVE
$ test_autoenv_auth_env_files
$ cd .
ENTER
$ type -w autostash
autostash: none
[1]
Now on to some stashing.
$ echo 'echo ENTER; autostash FOO=changed' > $AUTOENV_FILE_ENTER
$ echo 'echo LEAVE; autounstash' > $AUTOENV_FILE_LEAVE
$ test_autoenv_auth_env_files
Set environment variable.
$ FOO=orig
Activating the env stashes it and applies a new value.
$ cd ..
LEAVE
$ cd sub
ENTER
$ type -w autostash
autostash: function
$ echo $FOO
changed
Leaving the directory unstashes it.
$ cd ..
LEAVE
$ echo $FOO
orig
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 unset:
$ echo VAR_set:$+VAR
VAR_set:0
Trigger the autostashing in the enter file.
$ cd ..
LEAVE
no explicit call to autounstash
$ cd sub
ENTER
$ echo $VAR
changed
Now leave again.
$ cd ..
LEAVE
no explicit call to autounstash
$ echo VAR_set:$+VAR
VAR_set:0
Remove the leave file, auto-unstashing should still happen.
$ rm sub/$AUTOENV_FILE_LEAVE
$ cd sub
ENTER
$ 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_2
$ cd sub
ENTER
$ echo $VAR
changed
$ cd ..
$ echo $VAR
orig_2
}}}