From 5cfc69ad47a4b9736f96bfdec9a46fe5a510f612 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 25 Jan 2015 19:16:30 +0100 Subject: [PATCH 1/3] Improve ZDOTDIR setting in Makefile --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f59c91d..fc1e35d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ -export ZDOTDIR=${CURDIR}/tests/ZDOTDIR +# Default, can be overridden using "make test ZDOTDIR=...". +ZDOTDIR:=${CURDIR}/tests/ZDOTDIR + +# Export it, and make it absolute. +override export ZDOTDIR:=$(abspath $(ZDOTDIR)) test: cram --shell=zsh -v tests From 6fe08c3fdeec540d7f4dc126e6625e6ae3bbc213 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 25 Jan 2015 19:18:25 +0100 Subject: [PATCH 2/3] Improve zsh/zstat integration; also make it handle dirs --- autoenv.zsh | 34 +++++++++++++++++----------------- tests/_autoenv_stack.t | 4 +++- tests/_autoenv_utils.t | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/autoenv.zsh b/autoenv.zsh index 24f4b04..3ec01e9 100644 --- a/autoenv.zsh +++ b/autoenv.zsh @@ -60,13 +60,23 @@ _autoenv_stack_entered_add() { _autoenv_stack_entered_mtime[$env_file]=$(_autoenv_get_file_mtime $env_file) } -_autoenv_get_file_mtime() { - if [[ -f $1 ]]; then - zstat +mtime $1 - else - echo 0 - fi -} + +# zstat_mime helper, conditionally defined. +# Load zstat module, but only its builtin `zstat`. +if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then + # If the module is not available, define a wrapper around `stat`, and use its + # terse output instead of format, which is not supported by busybox. + # Assume '+mtime' as $1. + _autoenv_get_file_mtime() { + setopt localoptions pipefail + stat -t $1 2>/dev/null | cut -f13 -d ' ' || echo 0 + } +else + _autoenv_get_file_mtime() { + zstat +mtime $1 2>/dev/null || echo 0 + } +fi + # Remove an entry from the stack. _autoenv_stack_entered_remove() { @@ -132,16 +142,6 @@ _autoenv_debug() { } # }}} -# Load zstat module, but only its builtin `zstat`. -if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then - # If the module is not available, define a wrapper around `stat`, and use its - # terse output instead of format, which is not supported by busybox. - # Assume '+mtime' as $1. - zstat() { - stat -t $2 | cut -f13 -d ' ' - } -fi - # Generate hash pair for a given file ($1). # A fixed hash value can be given as 2nd arg, but is used with tests only. diff --git a/tests/_autoenv_stack.t b/tests/_autoenv_stack.t index 6f659c6..299d064 100644 --- a/tests/_autoenv_stack.t +++ b/tests/_autoenv_stack.t @@ -12,6 +12,8 @@ Add existing entries. $ mkdir -p sub/sub2 $ touch -t 201401010101 sub/file + $ touch -t 201401010102 sub + $ touch -t 201401010103 sub/sub2 $ _autoenv_stack_entered_add sub $ _autoenv_stack_entered_add sub/file $ _autoenv_stack_entered_add sub/sub2 @@ -26,7 +28,7 @@ Add existing entries. sub sub/file sub/sub2 non-existing $ echo $_autoenv_stack_entered_mtime - 0 1388538060 0 0 (glob) + 1388538180 1388538060 1388538120 0 Touch the file and re-add it. diff --git a/tests/_autoenv_utils.t b/tests/_autoenv_utils.t index 3da1fde..91fa1be 100644 --- a/tests/_autoenv_utils.t +++ b/tests/_autoenv_utils.t @@ -71,3 +71,17 @@ Re-add the first one, with a new hash. :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob) :/tmp/cramtests-*/_autoenv_utils.t/first:65eb010197b73ddc109b7210080f97a87f53451e:1 (glob) }}} + + +Explicit calls to _autoenv_get_file_mtime to test alternative implementation +of _autoenv_get_file_mtime (via ZDOTDIR.invalid-module_path/). + + $ _autoenv_get_file_mtime non-existing + 0 + $ touch -t 201401010101 file + $ _autoenv_get_file_mtime file + 1388538060 + $ mkdir dir + $ touch -t 201401010102 dir + $ _autoenv_get_file_mtime dir + 1388538120 From 5d65371786a1e97f73ba37bc2f6db29b31db9fab Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 25 Jan 2015 19:19:11 +0100 Subject: [PATCH 3/3] Test env for invalid zsh module_path, where zsh/zstat fails --- tests/ZDOTDIR.invalid-module_path/.zshenv | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/ZDOTDIR.invalid-module_path/.zshenv diff --git a/tests/ZDOTDIR.invalid-module_path/.zshenv b/tests/ZDOTDIR.invalid-module_path/.zshenv new file mode 100644 index 0000000..baa1de6 --- /dev/null +++ b/tests/ZDOTDIR.invalid-module_path/.zshenv @@ -0,0 +1,13 @@ +# Use invalid module path for zsh, to test alternative zstat implementation. + +# Pre-load zsh/parameter, where we do not have/need(?) an alternative +# implementation. +zmodload zsh/parameter + +module_path=(/dev/null) + +zstat() { + echo "Should not get called." +} + +source ${ZDOTDIR}/../ZDOTDIR/.zshenv