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