]> 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 bc49657850347620803c106a05e6db09178f5d6c..dd730c468ed3d348d7d6f72ddec1cdc09ab210ff 100644 (file)
 Test varstash integration.
 
-  $ source $TESTDIR/setup.sh
+  $ source $TESTDIR/setup.zsh || return 1
 
 Setup test environment.
 
-# Defaults:
-# $ DOTENV_FILE_ENTER=.env
-# $ DOTENV_FILE_LEAVE=.env.leave
-# $ DOTENV_HANDLE_LEAVE=1
-
   $ mkdir sub
   $ cd sub
-  $ echo "autostash FOO=baz" > $DOTENV_FILE_ENTER
-  $ echo "autounstash" > $DOTENV_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 "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $AUTOENV_ENV_FILENAME
-  $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME
+  $ echo 'echo ENTER; autostash FOO=changed' > $AUTOENV_FILE_ENTER
+  $ echo 'echo LEAVE; autounstash' > $AUTOENV_FILE_LEAVE
+  $ test_autoenv_auth_env_files
 
 Set environment variable.
 
-  $ FOO=bar
+  $ FOO=orig
 
 Activating the env stashes it and applies a new value.
 
-  $ cd .
+  $ cd ..
+  LEAVE
+  $ cd sub
+  ENTER
+  $ type -w autostash
+  autostash: function
   $ echo $FOO
-  baz
+  changed
 
 Leaving the directory unstashes it.
 
   $ cd ..
+  LEAVE
   $ echo $FOO
-  bar
+  orig
+
+
+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
+  $ test_autoenv_auth_env_files
+
+$VAR is unset:
+
+  $ echo VAR_set:$+VAR
+  VAR_set:0
+
+Trigger the autostashing in the enter file.
+
+  $ cd ..
+  LEAVE
+  no explicit call to autounstash
+  $ cd sub
+  ENTER
+  $ echo $VAR
+  changed
+
+Now leave again.
+
+  $ cd ..
+  LEAVE
+  no explicit call to autounstash
+  $ echo VAR_set:$+VAR
+  VAR_set:0
+
+Remove the leave file, auto-unstashing should still happen.
+
+  $ rm sub/$AUTOENV_FILE_LEAVE
+  $ cd sub
+  ENTER
+  $ 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_2
+  $ cd sub
+  ENTER
+  $ echo $VAR
+  changed
+  $ cd ..
+  $ echo $VAR
+  orig_2
+
+}}}