mirror of
https://github.com/Tarrasch/zsh-autoenv.git
synced 2024-11-26 08:50:59 +02:00
Merge pull request #16 from Tarrasch/tests-with-clobber
tests: setup for multiple ZDOTDIRs, fix/add "setopt clobber"
This commit is contained in:
commit
07069d8cbe
@ -4,4 +4,4 @@ python:
|
|||||||
before_script:
|
before_script:
|
||||||
- "sudo apt-get install zsh"
|
- "sudo apt-get install zsh"
|
||||||
install: "sudo pip install cram"
|
install: "sudo pip install cram"
|
||||||
script: "make test"
|
script: "make test_full"
|
||||||
|
15
Makefile
15
Makefile
@ -1,10 +1,17 @@
|
|||||||
.PHONY: itest test
|
export ZDOTDIR=${PWD}/tests/ZDOTDIR
|
||||||
|
|
||||||
test:
|
test:
|
||||||
ZDOTDIR="${PWD}/tests" cram --shell=zsh -v tests
|
cram --shell=zsh -v tests
|
||||||
|
|
||||||
itest:
|
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.
|
# Define targets for test files, with relative and abolute path.
|
||||||
# Use verbose output, which is useful with Vim's 'errorformat'.
|
# 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):
|
$(_TESTS_REL_AND_ABS):
|
||||||
ZDOTDIR="${PWD}/tests" cram --shell=zsh -v $@
|
ZDOTDIR="${PWD}/tests" cram --shell=zsh -v $@
|
||||||
.PHONY: $(_TESTS_REL_AND_ABS)
|
.PHONY: $(_TESTS_REL_AND_ABS)
|
||||||
|
|
||||||
|
.PHONY: itest test
|
||||||
|
@ -147,7 +147,7 @@ _autoenv_authorized_env_file() {
|
|||||||
_autoenv_authorize() {
|
_autoenv_authorize() {
|
||||||
local env_file=${1:A}
|
local env_file=${1:A}
|
||||||
_autoenv_deauthorize $env_file
|
_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.
|
# Deauthorize a given filename, by removing it from the auth file.
|
||||||
@ -156,7 +156,7 @@ _autoenv_authorize() {
|
|||||||
_autoenv_deauthorize() {
|
_autoenv_deauthorize() {
|
||||||
local env_file=${1:A}
|
local env_file=${1:A}
|
||||||
if [[ -s $AUTOENV_ENV_FILENAME ]]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
tests/ZDOTDIR.clobber/.zshenv
Normal file
3
tests/ZDOTDIR.clobber/.zshenv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
source ${ZDOTDIR}/../ZDOTDIR/.zshenv
|
||||||
|
|
||||||
|
setopt noclobber
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Lets set a simple .env action
|
Lets set a simple .env action
|
||||||
|
|
||||||
$ echo 'echo ENTERED' >> .env
|
$ echo 'echo ENTERED' > .env
|
||||||
|
|
||||||
Manually create auth file
|
Manually create auth file
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ Lets set a simple .env action
|
|||||||
|
|
||||||
$ mkdir sub
|
$ mkdir sub
|
||||||
$ cd sub
|
$ cd sub
|
||||||
$ echo 'echo ENTERED' >> .env
|
$ echo 'echo ENTERED' > .env
|
||||||
$ echo 'echo LEFT' >> .env.leave
|
$ echo 'echo LEFT' > .env.leave
|
||||||
|
|
||||||
Change to the directory.
|
Change to the directory.
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ Prepend call to autoenv_source_parent to sub/.env file.
|
|||||||
|
|
||||||
Add sub/sub2/.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
|
$ test_autoenv_add_to_env sub2/.env
|
||||||
$ cd sub2
|
$ cd sub2
|
||||||
autoenv_source_parent_from_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".
|
First, let's answer "no".
|
||||||
|
|
||||||
$ echo "echo NEW" > .env
|
$ echo "echo NEW" >| .env
|
||||||
$ _autoenv_ask_for_yes() { echo "no"; return 1 }
|
$ _autoenv_ask_for_yes() { echo "no"; return 1 }
|
||||||
$ cd sub
|
$ cd sub
|
||||||
autoenv_source_parent_from_sub:
|
autoenv_source_parent_from_sub:
|
||||||
|
@ -8,11 +8,11 @@
|
|||||||
[[ $AUTOENV_ENV_FILENAME[0,4] == '/tmp' ]] || return 1
|
[[ $AUTOENV_ENV_FILENAME[0,4] == '/tmp' ]] || return 1
|
||||||
|
|
||||||
# Reset any authentication.
|
# Reset any authentication.
|
||||||
echo -n > $AUTOENV_ENV_FILENAME
|
echo -n >| $AUTOENV_ENV_FILENAME
|
||||||
|
|
||||||
# Add file $1 (with optional hash $2) to authentication file.
|
# Add file $1 (with optional hash $2) to authentication file.
|
||||||
test_autoenv_add_to_env() {
|
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.
|
# Add enter and leave env files to authentication file.
|
||||||
|
@ -39,8 +39,8 @@ Setup:
|
|||||||
$ unset VAR
|
$ unset VAR
|
||||||
$ cd sub
|
$ cd sub
|
||||||
ENTER
|
ENTER
|
||||||
$ echo 'echo ENTER; autostash VAR=changed' > $AUTOENV_FILE_ENTER
|
$ echo 'echo ENTER; autostash VAR=changed' >| $AUTOENV_FILE_ENTER
|
||||||
$ echo 'echo LEAVE; echo "no explicit call to autounstash"' > $AUTOENV_FILE_LEAVE
|
$ echo 'echo LEAVE; echo "no explicit call to autounstash"' >| $AUTOENV_FILE_LEAVE
|
||||||
$ test_autoenv_auth_env_files
|
$ test_autoenv_auth_env_files
|
||||||
|
|
||||||
$VAR is unset:
|
$VAR is unset:
|
||||||
|
Loading…
Reference in New Issue
Block a user