mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Tweak test runner to set up environment better
Update the test runners so they set up their own environment in test_util.fish. This simplifies the Makefile and paves the way for adding utility functions for use in the tests themselves.
This commit is contained in:
parent
eafd577629
commit
e13d423b68
5 changed files with 76 additions and 30 deletions
14
Makefile.in
14
Makefile.in
|
@ -315,20 +315,14 @@ test_low_level: fish_tests $(call filter_up_to,test_low_level,$(active_test_goal
|
||||||
test_high_level: test_fishscript test_interactive
|
test_high_level: test_fishscript test_interactive
|
||||||
.PHONY: test_high_level
|
.PHONY: test_high_level
|
||||||
|
|
||||||
test_fishscript: $(PROGRAMS) test_fishscript_config $(call filter_up_to,test_fishscript,$(active_test_goals))
|
test_fishscript: $(PROGRAMS) $(call filter_up_to,test_fishscript,$(active_test_goals))
|
||||||
cd tests; XDG_CONFIG_HOME="$$PWD"/tmp.config ../fish test.fish
|
cd tests && ../fish test.fish
|
||||||
.PHONY: test_fishscript
|
.PHONY: test_fishscript
|
||||||
|
|
||||||
test_interactive: $(PROGRAMS) test_fishscript_config $(call filter_up_to,test_interactive,$(active_test_goals))
|
test_interactive: $(PROGRAMS) $(call filter_up_to,test_interactive,$(active_test_goals))
|
||||||
cd tests; XDG_CONFIG_HOME="$$PWD"/tmp.config ../fish interactive.fish
|
cd tests && ../fish interactive.fish
|
||||||
.PHONY: test_interactive
|
.PHONY: test_interactive
|
||||||
|
|
||||||
test_fishscript_config:
|
|
||||||
@rm -rf tests/tmp.config
|
|
||||||
@mkdir -p tests/tmp.config/fish
|
|
||||||
@echo 'set fish_function_path "$$PWD/../share/functions"' > tests/tmp.config/fish/config.fish
|
|
||||||
.PHONY: test_fishscript_config
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# commands.hdr collects documentation on all commands, functions and
|
# commands.hdr collects documentation on all commands, functions and
|
||||||
# builtins
|
# builtins
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
# vim: set filetype=fish sw=4 ts=4 et:
|
# vim: set filetype=fish sw=4 ts=4 et:
|
||||||
|
|
||||||
# source the non-interactive config
|
|
||||||
source $XDG_CONFIG_HOME/../tmp.config/fish/config.fish
|
|
||||||
|
|
||||||
set -g prompt_counter 0
|
set -g prompt_counter 0
|
||||||
set -g prompt_counter_incr 0
|
set -g prompt_counter_incr 0
|
||||||
function fish_prompt
|
function fish_prompt
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# Interactive tests using `expect`
|
# Interactive tests using `expect`
|
||||||
|
|
||||||
source test_util.fish
|
source test_util.fish (status -f); or exit
|
||||||
|
|
||||||
say -o cyan "Testing interactive functionality"
|
say -o cyan "Testing interactive functionality"
|
||||||
if not type -q expect
|
if not type -q expect
|
||||||
|
@ -13,7 +13,8 @@ end
|
||||||
function test_file
|
function test_file
|
||||||
rm -Rf tmp.interactive.config; or die "Couldn't remove tmp.interactive.config"
|
rm -Rf tmp.interactive.config; or die "Couldn't remove tmp.interactive.config"
|
||||||
mkdir -p tmp.interactive.config/fish; or die "Couldn't create tmp.interactive.config/fish"
|
mkdir -p tmp.interactive.config/fish; or die "Couldn't create tmp.interactive.config/fish"
|
||||||
cp interactive.config tmp.interactive.config/fish/config.fish; or die "Couldn't create tmp.interactive.config/fish/config.fish"
|
cat $XDG_CONFIG_HOME/fish/config.fish interactive.config > tmp.interactive.config/fish/config.fish
|
||||||
|
or die "Couldn't create tmp.interactive.config/fish/config.fish"
|
||||||
|
|
||||||
set -l file $argv[1]
|
set -l file $argv[1]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# Fishscript tests
|
# Fishscript tests
|
||||||
|
|
||||||
source test_util.fish
|
source test_util.fish (status -f); or exit
|
||||||
|
|
||||||
say -o cyan "Testing high level script functionality"
|
say -o cyan "Testing high level script functionality"
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,73 @@
|
||||||
# Utilities for the test runners
|
# Utilities for the test runners
|
||||||
|
|
||||||
function die
|
if test "$argv[1]" = (status -f)
|
||||||
echo $argv[1] >&2
|
echo 'test_util.fish requires sourcing script as argument to `source`' >&2
|
||||||
|
echo 'use `source test_util.fish (status -f); or exit`' >&2
|
||||||
|
status --print-stack-trace >&2
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if not tty 0>&1 >/dev/null
|
function die
|
||||||
function set_color
|
set -q argv[1]; and echo $argv[1] >&2
|
||||||
# do nothing
|
exit 1
|
||||||
return 0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function say
|
# check if we're running in the test environment
|
||||||
|
# if not, set it up and rerun fish with exec.
|
||||||
|
# The test is whether the special var __fish_is_running_tests
|
||||||
|
# exists and contains the same value as XDG_CONFIG_HOME. It checks
|
||||||
|
# the value and not just the presence because we're going to delete
|
||||||
|
# the config directory later if we're exiting successfully.
|
||||||
|
if not set -q __fish_is_running_tests
|
||||||
|
# set up our test environment and re-run the original script
|
||||||
|
set -l script $argv[1]
|
||||||
|
switch $script
|
||||||
|
case '/*'
|
||||||
|
# path is absolute
|
||||||
|
case '*'
|
||||||
|
# path is relative, make it absolute
|
||||||
|
set script $PWD/$script
|
||||||
|
end
|
||||||
|
set -l IFS # clear IFS so cmd substitution doesn't split
|
||||||
|
cd (dirname $script); or die
|
||||||
|
set -xl XDG_CONFIG_HOME (printf '%s/tmp.config/%s' $PWD %self); or die
|
||||||
|
if test -d $XDG_CONFIG_HOME
|
||||||
|
# if the dir already exists, we've reused a pid
|
||||||
|
# this would be surprising to reuse a fish pid that failed in the past,
|
||||||
|
# but clear it anyway
|
||||||
|
rm -r $XDG_CONFIG_HOME; or die
|
||||||
|
end
|
||||||
|
mkdir -p $XDG_CONFIG_HOME/fish; or die
|
||||||
|
set -l escaped_parent (dirname $PWD | sed -e 's/[\'\\\\]/\\\\&/g'); or die
|
||||||
|
printf 'set fish_function_path \'%s/share/functions\'\n' $escaped_parent > $XDG_CONFIG_HOME/fish/config.fish; or die
|
||||||
|
set -xl __fish_is_running_tests $XDG_CONFIG_HOME
|
||||||
|
exec ../fish $script
|
||||||
|
die 'exec failed'
|
||||||
|
else if test "$__fish_is_running_tests" != "$XDG_CONFIG_HOME"
|
||||||
|
echo 'Something went wrong with the test runner.' >&2
|
||||||
|
echo "__fish_is_running_tests: $__fish_is_running_tests" >&2
|
||||||
|
echo "XDG_CONFIG_HOME: $XDG_CONFIG_HOME" >&2
|
||||||
|
exit 10
|
||||||
|
else
|
||||||
|
# we're running tests with a temporary config directory
|
||||||
|
function test_util_on_exit --on-process-exit %self -V __fish_is_running_tests
|
||||||
|
# remove the temporary config directory
|
||||||
|
# unfortunately if this fails we can't alter the exit status of fish
|
||||||
|
if not rm -r "$__fish_is_running_tests"
|
||||||
|
echo "error: Couldn't remove temporary config directory '$__fish_is_running_tests'" >&2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# unset __fish_is_running_tests so any children that source
|
||||||
|
# test_util.fish will set up a new test environment.
|
||||||
|
set -e __fish_is_running_tests
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l suppress_color
|
||||||
|
if not tty 0>&1 >/dev/null
|
||||||
|
set suppress_color yes
|
||||||
|
end
|
||||||
|
|
||||||
|
function say -V suppress_color
|
||||||
set -l color_flags
|
set -l color_flags
|
||||||
set -l suppress_newline
|
set -l suppress_newline
|
||||||
while set -q argv[1]
|
while set -q argv[1]
|
||||||
|
@ -32,15 +87,14 @@ function say
|
||||||
set -e argv[1]
|
set -e argv[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
if not set -q argv[1]
|
if not set -q argv[2]
|
||||||
echo 'usage: say [flags] color [string...]' >&2
|
echo 'usage: say [flags] color string [string...]' >&2
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if set_color $color_flags $argv[1]
|
if begin; test -n "$suppress_color"; or set_color $color_flags $argv[1]; end
|
||||||
set -e argv[1]
|
printf '%s' $argv[2..-1]
|
||||||
echo -n $argv
|
test -z "$suppress_color"; and set_color reset
|
||||||
set_color reset
|
|
||||||
if test -z "$suppress_newline"
|
if test -z "$suppress_newline"
|
||||||
echo
|
echo
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue