]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/varstash_export.t
tests: define/use $TEST_SOURCE_AUTOENV
[zsh-autoenv.git] / tests / varstash_export.t
1 Test varstash with exported variables in subshell.
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 MYVAR=changed; autostash MYEXPORT=changed_export' > $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   $ MYVAR=orig
19   $ export MYEXPORT=orig_export
20
21 Activating the env stashes it and applies a new value.
22
23   $ cd .
24   ENTER
25   $ echo $MYVAR
26   changed
27   $ echo $MYEXPORT
28   changed_export
29
30 The variable is not available in a subshell, only the exported one.
31
32   $ $SHELL -c 'echo ${MYVAR:-empty}; echo $MYEXPORT'
33   empty
34   changed_export
35
36 Activate autoenv in the subshell.
37
38   $ $SHELL -c "$TEST_SOURCE_AUTOENV; echo \${MYVAR}; echo \$MYEXPORT"
39   ENTER
40   changed
41   changed_export
42
43 "autounstash" should handle the exported variables.
44
45   $ $SHELL -c "$TEST_SOURCE_AUTOENV; cd ..; echo \${MYVAR:-empty}; echo \$MYEXPORT"
46   ENTER
47   LEAVE
48   empty
49   orig_export
50 #
51 # Exiting the subshell should restore.
52 #
53 #   $ pwd
54 #   */varstash_export.t (glob)
55 #   $ echo $MYVAR
56 #   changed
57 #   $ echo $MYEXPORT
58 #   changed_export