]> Sergey Matveev's repositories - zsh-autoenv.git/blobdiff - tests/varstash.t
Only source varstash lib if it's being used
[zsh-autoenv.git] / tests / varstash.t
index 30a45dd8f618bf1515e99ac7c3111c74843a2226..dd730c468ed3d348d7d6f72ddec1cdc09ab210ff 100644 (file)
@@ -1,16 +1,27 @@
 Test varstash integration.
 
-  $ source $TESTDIR/setup.sh
+  $ source $TESTDIR/setup.zsh || return 1
 
 Setup test environment.
 
   $ mkdir sub
   $ cd sub
-  $ echo 'echo ENTER; autostash FOO=changed' > $AUTOENV_FILE_ENTER
-  $ echo 'echo LEAVE; autounstash' > $AUTOENV_FILE_LEAVE
 
-Manually create auth file
+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.
@@ -19,8 +30,12 @@ Set environment variable.
 
 Activating the env stashes it and applies a new value.
 
-  $ cd .
+  $ cd ..
+  LEAVE
+  $ cd sub
   ENTER
+  $ type -w autostash
+  autostash: function
   $ echo $FOO
   changed
 
@@ -36,31 +51,23 @@ 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
+  $ 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 empty:
+$VAR is unset:
 
-  $ echo VAR:$VAR
-  VAR:
+  $ echo VAR_set:$+VAR
+  VAR_set:0
 
-Set it:
+Trigger the autostashing in the enter file.
 
-  $ VAR=orig
   $ cd ..
   LEAVE
   no explicit call to autounstash
-
-Leaving the directory keeps it intact - nothing had been stashed yet.
-
-  $ echo $VAR
-  orig
-
-Enter the dir, trigger the autostashing.
-
   $ cd sub
   ENTER
   $ echo $VAR
@@ -71,9 +78,8 @@ Now leave again.
   $ cd ..
   LEAVE
   no explicit call to autounstash
-  $ echo $VAR
-  orig
-
+  $ echo VAR_set:$+VAR
+  VAR_set:0
 
 Remove the leave file, auto-unstashing should still happen.
 
@@ -83,7 +89,20 @@ Remove the leave file, auto-unstashing should still happen.
   $ 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
+  orig_2
+  $ cd sub
+  ENTER
+  $ echo $VAR
+  changed
+  $ cd ..
+  $ echo $VAR
+  orig_2
 
 }}}