diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-02-06 18:08:22 -0800 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-02-25 17:16:36 -0800 |
commit | 8b67a1b26f2525f7de1e2a64dee6ab48b72b0e33 (patch) | |
tree | 5e0a33d532f47c5b1909b46116247f16f9707d52 /tests/test_util.fish | |
parent | c79ade9627b116a0dc4aecd27d1ff61e68fe595b (diff) |
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
Diffstat (limited to 'tests/test_util.fish')
-rw-r--r-- | tests/test_util.fish | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/tests/test_util.fish b/tests/test_util.fish index 22744b34..7e8f1fd6 100644 --- a/tests/test_util.fish +++ b/tests/test_util.fish @@ -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 |