Skip to content

Commit 3417298

Browse files
committed
tests: Set ZSH explicitly and avoid 'env'
'env -i' clears the complete environment, including PATH. In that case, on most platforms, when excuting commands without PATH being set, /usr/bin and /bin are searched, e.g. on Linux: $ strace env -i asdf |& grep asdf execve("/usr/bin/env", ["env", "-i", "asdf"], 0x7ffc3e3c0890 /* 27 vars */) = 0 execve("/bin/asdf", ["asdf"], 0x55be2da090d0 /* 0 vars */) = -1 ENOENT (No such file or directory) execve("/usr/bin/asdf", ["asdf"], 0x55be2da090d0 /* 0 vars */) = -1 ENOENT (No such file or directory) write(2, "\342\200\230asdf\342\200\231", 10‘asdf’) = 10 Howver, this does not hold on every platform. E.g. on Cygwin, so such fallback paths are searched: $ strace env -i asdf |& grep asdf 37 25736 [main] env 3516 build_argv: argv[2] = 'asdf' 643 30373 [main] env 3516 find_exec: find_exec (asdf) 35 30408 [main] env 3516 find_exec: (null) = find_exec (asdf) 36 30444 [main] env 3516 spawnve: spawnve (, asdf, 0x10040B000) ‘asdf’ 199 53601 [main] env 3516 write: 10 = write(2, 0x10040B040, 10) $ env -i zsh env: ‘zsh’: No such file or directory Therefore, avoid the need for 'env' to do the searching and invoke the proper zsh binary explicitly.
1 parent 6d5372a commit 3417298

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ INSTALL?=install -c
44
PREFIX?=/usr/local
55
SHARE_DIR?=$(DESTDIR)$(PREFIX)/share/$(NAME)
66
DOC_DIR?=$(DESTDIR)$(PREFIX)/share/doc/$(NAME)
7-
ZSH?=zsh # zsh binary to run tests with
7+
ZSH?="`which zsh`" # zsh binary to run tests with
88

99
all:
1010
cd docs && \
@@ -41,7 +41,7 @@ test:
4141
for test in highlighters/*; do \
4242
if [ -d $$test/test-data ]; then \
4343
echo "Running test $${test##*/}"; \
44-
env -i QUIET=$$QUIET $${TERM:+"TERM=$$TERM"} $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \
44+
env -i QUIET=$$QUIET $${TERM:+"TERM=$$TERM"} ZSH=${ZSH} $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \
4545
: $$(( result |= $$? )); \
4646
fi \
4747
done; \

tests/test-highlighting.zsh

+4-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
# vim: ft=zsh sw=2 ts=2 et
2929
# -------------------------------------------------------------------------------------------------
3030

31-
3231
setopt NO_UNSET WARN_CREATE_GLOBAL
3332

3433
# Required for add-zle-hook-widget.
@@ -72,8 +71,8 @@ fi
7271

7372
# Load the main script.
7473
# While here, test that it doesn't eat aliases.
75-
print > >($results_filter | $root/tests/tap-colorizer.zsh) -r -- "# global (driver) tests"
76-
print > >($results_filter | $root/tests/tap-colorizer.zsh) -r -- "1..1"
74+
print > >($results_filter | $ZSH $root/tests/tap-colorizer.zsh) -r -- "# global (driver) tests"
75+
print > >($results_filter | $ZSH $root/tests/tap-colorizer.zsh) -r -- "1..1"
7776
alias -- +plus=plus
7877
alias -- _other=other
7978
local original_alias_dash_L_output="$(alias -L)"
@@ -83,7 +82,7 @@ if [[ $original_alias_dash_L_output == $(alias -L) ]]; then
8382
else
8483
print -r -- "not ok 1 # 'alias -- +foo=bar' is preserved"
8584
exit 1
86-
fi > >($results_filter | $root/tests/tap-colorizer.zsh)
85+
fi > >($results_filter | $ZSH $root/tests/tap-colorizer.zsh)
8786

8887
# Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style
8988
_zsh_highlight_add_highlight()
@@ -283,7 +282,7 @@ integer something_failed=0
283282
ZSH_HIGHLIGHT_STYLES=()
284283
local data_file
285284
for data_file in $root/highlighters/$1/test-data/*.zsh; do
286-
run_test "$data_file" | tee >($results_filter | $root/tests/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -Eq '^not ok|^ok.*# TODO' && (( something_failed=1 ))
285+
run_test "$data_file" | tee >($results_filter | $ZSH $root/tests/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -Eq '^not ok|^ok.*# TODO' && (( something_failed=1 ))
287286
(( $pipestatus[1] )) && exit 2
288287
done
289288

0 commit comments

Comments
 (0)