]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/varstash.t
85d665f47ea07a9aa7297d608f6704fd4ecd7618
[zsh-autoenv.git] / tests / varstash.t
1 Test varstash integration.
2
3   $ source $TESTDIR/setup.sh || return 1
4
5 Setup test environment.
6
7   $ mkdir sub
8   $ cd sub
9   $ echo 'echo ENTER; autostash FOO=changed' > $AUTOENV_FILE_ENTER
10   $ echo 'echo LEAVE; autounstash' > $AUTOENV_FILE_LEAVE
11
12 Manually create auth file
13
14   $ test_autoenv_auth_env_files
15
16 Set environment variable.
17
18   $ FOO=orig
19
20 Activating the env stashes it and applies a new value.
21
22   $ cd .
23   ENTER
24   $ echo $FOO
25   changed
26
27 Leaving the directory unstashes it.
28
29   $ cd ..
30   LEAVE
31   $ echo $FOO
32   orig
33
34
35 Test autounstashing when leaving a directory.  {{{
36
37 Setup:
38
39   $ unset VAR
40   $ cd sub
41   ENTER
42   $ echo 'echo ENTER; autostash VAR=changed' >| $AUTOENV_FILE_ENTER
43   $ echo 'echo LEAVE; echo "no explicit call to autounstash"' >| $AUTOENV_FILE_LEAVE
44   $ test_autoenv_auth_env_files
45
46 $VAR is unset:
47
48   $ echo VAR_set:$+VAR
49   VAR_set:0
50
51 Trigger the autostashing in the enter file.
52
53   $ cd ..
54   LEAVE
55   no explicit call to autounstash
56   $ cd sub
57   ENTER
58   $ echo $VAR
59   changed
60
61 Now leave again.
62
63   $ cd ..
64   LEAVE
65   no explicit call to autounstash
66   $ echo VAR_set:$+VAR
67   VAR_set:0
68
69 Remove the leave file, auto-unstashing should still happen.
70
71   $ rm sub/$AUTOENV_FILE_LEAVE
72   $ cd sub
73   ENTER
74   $ echo $VAR
75   changed
76   $ cd ..
77   $ echo VAR_set:$+VAR
78   VAR_set:0
79
80 And once again where a value gets restored.
81
82   $ VAR=orig_2
83   $ echo $VAR
84   orig_2
85   $ cd sub
86   ENTER
87   $ echo $VAR
88   changed
89   $ cd ..
90   $ echo $VAR
91   orig_2
92
93 }}}