]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/varstash.t
Call `autounstash` automatically/always when leaving a directory
[zsh-autoenv.git] / tests / varstash.t
1 Test varstash integration.
2
3   $ source $TESTDIR/setup.sh
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   $ cd sub
40   ENTER
41   $ echo 'echo ENTER; autostash VAR=changed' > $AUTOENV_FILE_ENTER
42   $ echo 'echo LEAVE; echo "no explicit call to autounstash"' > $AUTOENV_FILE_LEAVE
43   $ test_autoenv_auth_env_files
44
45 $VAR is empty:
46
47   $ echo VAR:$VAR
48   VAR:
49
50 Set it:
51
52   $ VAR=orig
53   $ cd ..
54   LEAVE
55   no explicit call to autounstash
56
57 Leaving the directory keeps it intact - nothing had been stashed yet.
58
59   $ echo $VAR
60   orig
61
62 Enter the dir, trigger the autostashing.
63
64   $ cd sub
65   ENTER
66   $ echo $VAR
67   changed
68
69 Now leave again.
70
71   $ cd ..
72   LEAVE
73   no explicit call to autounstash
74   $ echo $VAR
75   orig
76
77
78 Remove the leave file, auto-unstashing should still happen.
79
80   $ rm sub/$AUTOENV_FILE_LEAVE
81   $ cd sub
82   ENTER
83   $ echo $VAR
84   changed
85   $ cd ..
86   $ echo $VAR
87   orig
88
89 }}}