]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/setup.zsh
tests: streamline ZDOTDIR layout, AUTOENV_ENV_FILENAME via setup
[zsh-autoenv.git] / tests / setup.zsh
1 # Setup for tests.
2 #
3 # It returns 1 in case of errors, and no tests should be run then!
4 #
5 # Ensure we have our mocked out AUTOENV_ENV_FILENAME
6 # (via .zshenv).
7
8 # Treat unset variables as errors.
9 # Not handled in varstash yet.
10 # setopt nounset
11
12 export AUTOENV_ENV_FILENAME="$CRAMTMP/.env_auth"
13
14 if [[ $AUTOENV_ENV_FILENAME[0,4] != '/tmp' ]]; then
15   echo "AUTOENV_ENV_FILENAME is not in /tmp. Aborting."
16   return 1
17 fi
18
19 # Abort this setup script on any error.
20 _save_errexit=${options[errexit]}
21 set -e
22
23 # Defined in .zshenv, e.g. tests/ZDOTDIR/.zshenv.
24 $TEST_SOURCE_AUTOENV
25
26 # Reset any authentication.
27 echo -n >| $AUTOENV_ENV_FILENAME
28
29 # Add file $1 (with optional hash $2) to authentication file.
30 test_autoenv_add_to_env() {
31   _autoenv_hash_pair $1 ${2:-} >>| $AUTOENV_ENV_FILENAME
32 }
33
34 # Add enter and leave env files to authentication file.
35 test_autoenv_auth_env_files() {
36   test_autoenv_add_to_env $PWD/$AUTOENV_FILE_ENTER
37   test_autoenv_add_to_env $PWD/$AUTOENV_FILE_LEAVE
38 }
39
40 # Now keep on going on errors again.
41 options[errexit]=$_save_errexit
42 unset _save_errexit