make testing on local servers hermetic

I noticed while fixing issue #2702 that the fish program being tested
was sourcing config.fish files outside of the current build. This also
happens when Travis CI runs the tests but isn't an issue there because
of how Travis is configured to execute the tests.

I also noticed that running `make test` was polluting my personal fish
history; which will become a bigger problem if and when the fishd universal
var file is moved from $XDG_CONFIG_HOME to $XDG_DATA_HOME.

This change makes it possible for an individual to run the tests on
their local machine secure in the knowledge that only the config.fish and
related files from their git repository will be used and doing so won't
pollute their personal fish history.

Resolves #469
This commit is contained in:
Kurtis Rader
2016-02-06 18:08:22 -08:00
parent c79ade9627
commit 8b67a1b26f
15 changed files with 155 additions and 142 deletions

View File

@@ -19,8 +19,8 @@ function die
exit 1
end
# check if we're running in the test environment
# if not, set it up and rerun fish with exec.
# 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
@@ -37,19 +37,21 @@ if not set -q __fish_is_running_tests
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
set -lx XDG_DATA_HOME ../test/data
rm -rf $XDG_DATA_HOME/fish
mkdir -p $XDG_DATA_HOME/fish; or die
set -lx XDG_CONFIG_HOME ../test/home
rm -rf $XDG_CONFIG_HOME/fish
mkdir -p $XDG_CONFIG_HOME/fish; or die
ln -s $PWD/test_functions $XDG_CONFIG_HOME/fish/functions; or die
set -l escaped_parent (dirname $PWD | sed -e 's/[\'\\\\]/\\\\&/g'); or die
set -l escaped_config (printf '%s/fish' $XDG_CONFIG_HOME | sed -e 's/[\'\\\\]/\\\\&/g'); or die
printf 'set fish_function_path \'%s/functions\' \'%s/share/functions\'\n' $escaped_config $escaped_parent > $XDG_CONFIG_HOME/fish/config.fish; or die
set -xl __fish_is_running_tests $XDG_CONFIG_HOME
# set locale information to be consistent
set -lx LANG C
set -lx LC_ALL ''
@@ -57,27 +59,13 @@ if not set -q __fish_is_running_tests
set -lx LC_$var ''
end
set -lx LC_CTYPE en_US.UTF-8
exec ../fish $script $args_for_test_script
exec ../test/root/bin/fish $script $args_for_test_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
if not set -q __fish_test_keep_tmp_config
# 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
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