]> Sergey Matveev's repositories - zsh-autoenv.git/blobdiff - tests/setup.zsh
tests: test_autoenv_add_to_env: create auth file parent dir (#59)
[zsh-autoenv.git] / tests / setup.zsh
index d8a018e173d0d26115c03107bcdf4598c63c93b5..31aee201214e80dd66c3cf9bd23ffa34f405c6d6 100644 (file)
@@ -2,17 +2,17 @@
 #
 # It returns 1 in case of errors, and no tests should be run then!
 #
-# Ensure we have our mocked out AUTOENV_ENV_FILENAME
+# Ensure we have our mocked out AUTOENV_AUTH_FILE
 # (via .zshenv).
 
 # Treat unset variables as errors.
 # Not handled in varstash yet.
 # setopt nounset
 
-export AUTOENV_ENV_FILENAME="$CRAMTMP/.env_auth"
+export AUTOENV_AUTH_FILE="$CRAMTMP/autoenv/.autoenv_auth"
 
-if [[ $AUTOENV_ENV_FILENAME[0,4] != '/tmp' ]]; then
-  echo "AUTOENV_ENV_FILENAME is not in /tmp. Aborting."
+if [[ $AUTOENV_AUTH_FILE[0,4] != '/tmp' ]]; then
+  echo "AUTOENV_AUTH_FILE is not in /tmp. Aborting."
   return 1
 fi
 
@@ -24,17 +24,21 @@ set -e
 $TEST_SOURCE_AUTOENV
 
 # Reset any authentication.
-echo -n >| $AUTOENV_ENV_FILENAME
+if [[ -f $AUTOENV_AUTH_FILE ]]; then
+  echo -n >| $AUTOENV_AUTH_FILE
+fi
 
-# Add file $1 (with optional hash $2) to authentication file.
+# Add file ($1), version ($2), and optional hash ($3) to authentication file.
 test_autoenv_add_to_env() {
-  _autoenv_hash_pair $1 ${2:-} >>| $AUTOENV_ENV_FILENAME
+  [[ -d ${AUTOENV_AUTH_FILE:h} ]] || mkdir -p ${AUTOENV_AUTH_FILE:h}
+  _autoenv_hash_pair $1 1 ${2:-} >>| $AUTOENV_AUTH_FILE
 }
 
 # Add enter and leave env files to authentication file.
 test_autoenv_auth_env_files() {
-  test_autoenv_add_to_env $PWD/$AUTOENV_FILE_ENTER
-  test_autoenv_add_to_env $PWD/$AUTOENV_FILE_LEAVE
+  local dir=${1:-$PWD}
+  test_autoenv_add_to_env $dir/$AUTOENV_FILE_ENTER
+  test_autoenv_add_to_env $dir/$AUTOENV_FILE_LEAVE
 }
 
 # Now keep on going on errors again.