Skip to content

Commit

Permalink
tests: Set ZSH explicitly and avoid 'env'
Browse files Browse the repository at this point in the history
'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.
  • Loading branch information
m0vie committed Aug 15, 2020
1 parent 6d5372a commit 3417298
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ INSTALL?=install -c
PREFIX?=/usr/local
SHARE_DIR?=$(DESTDIR)$(PREFIX)/share/$(NAME)
DOC_DIR?=$(DESTDIR)$(PREFIX)/share/doc/$(NAME)
ZSH?=zsh # zsh binary to run tests with
ZSH?="`which zsh`" # zsh binary to run tests with

all:
cd docs && \
Expand Down Expand Up @@ -41,7 +41,7 @@ test:
for test in highlighters/*; do \
if [ -d $$test/test-data ]; then \
echo "Running test $${test##*/}"; \
env -i QUIET=$$QUIET $${TERM:+"TERM=$$TERM"} $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \
env -i QUIET=$$QUIET $${TERM:+"TERM=$$TERM"} ZSH=${ZSH} $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \
: $$(( result |= $$? )); \
fi \
done; \
Expand Down
9 changes: 4 additions & 5 deletions tests/test-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------


setopt NO_UNSET WARN_CREATE_GLOBAL

# Required for add-zle-hook-widget.
Expand Down Expand Up @@ -72,8 +71,8 @@ fi

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

# Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style
_zsh_highlight_add_highlight()
Expand Down Expand Up @@ -283,7 +282,7 @@ integer something_failed=0
ZSH_HIGHLIGHT_STYLES=()
local data_file
for data_file in $root/highlighters/$1/test-data/*.zsh; do
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 ))
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 ))
(( $pipestatus[1] )) && exit 2
done

Expand Down

0 comments on commit 3417298

Please sign in to comment.