]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/setup.sh
tests: define/use $TEST_SOURCE_AUTOENV
[zsh-autoenv.git] / tests / setup.sh
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 if [[ $AUTOENV_ENV_FILENAME[0,4] != '/tmp' ]]; then
13   echo "AUTOENV_ENV_FILENAME is not in /tmp. Aborting."
14   return 1
15 fi
16
17 # Abort this setup script on any error.
18 _save_errexit=${options[errexit]}
19 set -e
20
21 if (( ${+functions[antigen-like-loader-function]} )); then
22   TEST_SOURCE_AUTOENV=antigen-like-loader-function
23 else
24   TEST_SOURCE_AUTOENV=(source $TESTDIR/../autoenv.plugin.zsh)
25 fi
26 $TEST_SOURCE_AUTOENV
27
28 # Reset any authentication.
29 echo -n >| $AUTOENV_ENV_FILENAME
30
31 # Add file $1 (with optional hash $2) to authentication file.
32 test_autoenv_add_to_env() {
33   _autoenv_hash_pair $1 ${2:-} >>| $AUTOENV_ENV_FILENAME
34 }
35
36 # Add enter and leave env files to authentication file.
37 test_autoenv_auth_env_files() {
38   test_autoenv_add_to_env $PWD/$AUTOENV_FILE_ENTER
39   test_autoenv_add_to_env $PWD/$AUTOENV_FILE_LEAVE
40 }
41
42 # Now keep on going on errors again.
43 options[errexit]=$_save_errexit
44 unset _save_errexit