From 9c829733ad2cb61b5873c1f20abeffea6af6043f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 8 Dec 2014 22:12:30 +0100 Subject: [PATCH] tests: setup for multiple ZDOTDIRs, fix/add "setopt clobber" --- .travis.yml | 2 +- Makefile | 15 ++++++++++++--- autoenv.zsh | 4 ++-- tests/ZDOTDIR.clobber/.zshenv | 3 +++ tests/{ => ZDOTDIR}/.zshenv | 0 tests/autoenv.t | 2 +- tests/leave.t | 4 ++-- tests/recurse-upwards.t | 4 ++-- tests/setup.sh | 4 ++-- tests/varstash.t | 4 ++-- 10 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 tests/ZDOTDIR.clobber/.zshenv rename tests/{ => ZDOTDIR}/.zshenv (100%) diff --git a/.travis.yml b/.travis.yml index 00828ba..715854b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,4 @@ python: before_script: - "sudo apt-get install zsh" install: "sudo pip install cram" -script: "make test" +script: "make test_full" diff --git a/Makefile b/Makefile index 0ffe150..db303fa 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,17 @@ -.PHONY: itest test +export ZDOTDIR=${PWD}/tests/ZDOTDIR test: - ZDOTDIR="${PWD}/tests" cram --shell=zsh -v tests + cram --shell=zsh -v tests itest: - ZDOTDIR="${PWD}/tests" cram -i --shell=zsh tests + cram -i --shell=zsh tests + +# Run tests with all ZDOTDIRs. +test_full: + for i in $(wildcard tests/ZDOTDIR*); do \ + echo "ZDOTDIR=$$i"; \ + ZDOTDIR=${PWD}/$$i cram --shell=zsh -v tests; \ + done # Define targets for test files, with relative and abolute path. # Use verbose output, which is useful with Vim's 'errorformat'. @@ -15,3 +22,5 @@ _TESTS_REL_AND_ABS:=$(call uniq,$(abspath $(TESTS)) $(TESTS)) $(_TESTS_REL_AND_ABS): ZDOTDIR="${PWD}/tests" cram --shell=zsh -v $@ .PHONY: $(_TESTS_REL_AND_ABS) + +.PHONY: itest test diff --git a/autoenv.zsh b/autoenv.zsh index 8bc39bf..e8d0b99 100644 --- a/autoenv.zsh +++ b/autoenv.zsh @@ -147,7 +147,7 @@ _autoenv_authorized_env_file() { _autoenv_authorize() { local env_file=${1:A} _autoenv_deauthorize $env_file - _autoenv_hash_pair $env_file >> $AUTOENV_ENV_FILENAME + _autoenv_hash_pair $env_file >>| $AUTOENV_ENV_FILENAME } # Deauthorize a given filename, by removing it from the auth file. @@ -156,7 +156,7 @@ _autoenv_authorize() { _autoenv_deauthorize() { local env_file=${1:A} if [[ -s $AUTOENV_ENV_FILENAME ]]; then - echo "$(\grep -vF :${env_file}: $AUTOENV_ENV_FILENAME)" > $AUTOENV_ENV_FILENAME + echo "$(\grep -vF :${env_file}: $AUTOENV_ENV_FILENAME)" >| $AUTOENV_ENV_FILENAME fi } diff --git a/tests/ZDOTDIR.clobber/.zshenv b/tests/ZDOTDIR.clobber/.zshenv new file mode 100644 index 0000000..62037dc --- /dev/null +++ b/tests/ZDOTDIR.clobber/.zshenv @@ -0,0 +1,3 @@ +source ${ZDOTDIR}/../ZDOTDIR/.zshenv + +setopt noclobber diff --git a/tests/.zshenv b/tests/ZDOTDIR/.zshenv similarity index 100% rename from tests/.zshenv rename to tests/ZDOTDIR/.zshenv diff --git a/tests/autoenv.t b/tests/autoenv.t index 701e3b4..aef6bb9 100644 --- a/tests/autoenv.t +++ b/tests/autoenv.t @@ -2,7 +2,7 @@ Lets set a simple .env action - $ echo 'echo ENTERED' >> .env + $ echo 'echo ENTERED' > .env Manually create auth file diff --git a/tests/leave.t b/tests/leave.t index 2e4e360..227da71 100644 --- a/tests/leave.t +++ b/tests/leave.t @@ -4,8 +4,8 @@ Lets set a simple .env action $ mkdir sub $ cd sub - $ echo 'echo ENTERED' >> .env - $ echo 'echo LEFT' >> .env.leave + $ echo 'echo ENTERED' > .env + $ echo 'echo LEFT' > .env.leave Change to the directory. diff --git a/tests/recurse-upwards.t b/tests/recurse-upwards.t index aa36edd..3e6067e 100644 --- a/tests/recurse-upwards.t +++ b/tests/recurse-upwards.t @@ -86,7 +86,7 @@ Prepend call to autoenv_source_parent to sub/.env file. Add sub/sub2/.env file. - $ echo -e "echo autoenv_source_parent_from_sub2:\nautoenv_source_parent\necho done_sub2\n" > sub2/.env + $ echo -e "echo autoenv_source_parent_from_sub2:\nautoenv_source_parent\necho done_sub2\n" >| sub2/.env $ test_autoenv_add_to_env sub2/.env $ cd sub2 autoenv_source_parent_from_sub2: @@ -109,7 +109,7 @@ Changing the root .env should trigger re-authentication via autoenv_source_paren First, let's answer "no". - $ echo "echo NEW" > .env + $ echo "echo NEW" >| .env $ _autoenv_ask_for_yes() { echo "no"; return 1 } $ cd sub autoenv_source_parent_from_sub: diff --git a/tests/setup.sh b/tests/setup.sh index 5c6ae9e..557b9e7 100644 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -8,11 +8,11 @@ [[ $AUTOENV_ENV_FILENAME[0,4] == '/tmp' ]] || return 1 # Reset any authentication. -echo -n > $AUTOENV_ENV_FILENAME +echo -n >| $AUTOENV_ENV_FILENAME # Add file $1 (with optional hash $2) to authentication file. test_autoenv_add_to_env() { - _autoenv_hash_pair $1 ${2:-} >> $AUTOENV_ENV_FILENAME + _autoenv_hash_pair $1 ${2:-} >>| $AUTOENV_ENV_FILENAME } # Add enter and leave env files to authentication file. diff --git a/tests/varstash.t b/tests/varstash.t index cdb47a8..487230b 100644 --- a/tests/varstash.t +++ b/tests/varstash.t @@ -39,8 +39,8 @@ 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 unset: