From e96b6e157c9fb9c9b3fcd982db08d7052b56561f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 30 Jul 2021 19:21:36 -0500 Subject: [PATCH] Remove TMPDIR dependency from tests/ Tests are now executed in a test-specific temporary directory, so test output on failure should be reproducible/reusable as-is without needing to have TMPDIR defined (as it only exists by default under macOS). --- tests/checks/basic.fish | 12 ++++++------ tests/checks/redirect.fish | 9 +++++---- tests/checks/tmux-complete.fish | 6 +++--- tests/checks/wildcard.fish | 8 ++++---- tests/test_driver.sh | 8 +++++--- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index bf1193b34..1cf67c468 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -42,12 +42,12 @@ end # Simple function tests function foo - echo >$TMPDIR/fish_foo.txt $argv + echo >./fish_foo.txt $argv end foo hello -cat $TMPDIR/fish_foo.txt |read foo +cat ./fish_foo.txt |read foo if test $foo = hello; echo Test 2 pass @@ -327,10 +327,10 @@ type -q -f fish_test_type_zzz ; echo $status # ensure that builtins that produce no output can still truncate files # (bug PCA almost reintroduced!) -echo abc > $TMPDIR/file_truncation_test.txt -cat $TMPDIR/file_truncation_test.txt -echo -n > $TMPDIR/file_truncation_test.txt -cat $TMPDIR/file_truncation_test.txt +echo abc > ./file_truncation_test.txt +cat ./file_truncation_test.txt +echo -n > ./file_truncation_test.txt +cat ./file_truncation_test.txt #CHECK: abc # Test events. diff --git a/tests/checks/redirect.fish b/tests/checks/redirect.fish index 5a1af0a85..bd0956299 100644 --- a/tests/checks/redirect.fish +++ b/tests/checks/redirect.fish @@ -60,15 +60,16 @@ foo $tmpdir/bar cat $tmpdir/bar # CHECK: foo -rm -Rf $tmpdir - # Verify that we can turn stderr into stdout and then pipe it # Note that the order here has historically been unspecified - 'errput' could conceivably appear before 'output'. begin echo output echo errput 1>&2 -end 2>&1 | sort | tee $TMPDIR/tee_test.txt -cat $TMPDIR/tee_test.txt +end 2>&1 | sort | tee $tmpdir/tee_test.txt +cat $tmpdir/tee_test.txt + +rm -Rf $tmpdir + #CHECK: errput #CHECK: output #CHECK: errput diff --git a/tests/checks/tmux-complete.fish b/tests/checks/tmux-complete.fish index 4ee0f6474..b26e94090 100644 --- a/tests/checks/tmux-complete.fish +++ b/tests/checks/tmux-complete.fish @@ -6,9 +6,9 @@ set fish (builtin realpath $fish) # Isolated tmux. tmux can't handle session sockets in paths that are too long, and macOS has a very # long $TMPDIR, so use a relative path - except macOS doesn't have `realpath --relative-to`... -# We have a unique TMPDIR assigned by the test driver, so this will work so long as `tmux` is only -# invoked from the same PWD. -set tmpdir (command mktemp -d $TMPDIR/tmp.XXXXXXXX) +# We are cd'd into a unique temp dir created/assigned by the test driver, so this will work so long +# as `tmux` is only invoked from the same PWD. +set tmpdir (command mktemp -d ./tmp.XXXXXXXX) cd $tmpdir set -g tmux tmux -S ./.tmux-socket -f /dev/null diff --git a/tests/checks/wildcard.fish b/tests/checks/wildcard.fish index 2d2dcb0e5..189d6dff7 100644 --- a/tests/checks/wildcard.fish +++ b/tests/checks/wildcard.fish @@ -18,13 +18,13 @@ rm -Rf $dir # Verify that we can do wildcard expansion when we don't have read access to some path components. # See #2099 -set -l where $TMPDIR/fish_wildcard_permissions_test/noaccess/yesaccess +set -l where ./fish_wildcard_permissions_test/noaccess/yesaccess mkdir -p $where chmod 300 (dirname $where) # no read permissions mkdir -p $where # "__env.fish" here to confirm ordering - #6593. touch $where/alpha.txt $where/beta.txt $where/delta.txt $where/__env.fish -echo $where/* | string replace -a $TMPDIR '$TMPDIR' -#CHECK: $TMPDIR/fish_wildcard_permissions_test/noaccess/yesaccess/__env.fish $TMPDIR/fish_wildcard_permissions_test/noaccess/yesaccess/alpha.txt $TMPDIR/fish_wildcard_permissions_test/noaccess/yesaccess/beta.txt $TMPDIR/fish_wildcard_permissions_test/noaccess/yesaccess/delta.txt +echo $where/* +#CHECK: ./fish_wildcard_permissions_test/noaccess/yesaccess/__env.fish ./fish_wildcard_permissions_test/noaccess/yesaccess/alpha.txt ./fish_wildcard_permissions_test/noaccess/yesaccess/beta.txt ./fish_wildcard_permissions_test/noaccess/yesaccess/delta.txt chmod 700 (dirname $where) # so we can delete it -rm -rf $TMPDIR/fish_wildcard_permissions_test +rm -rf ./fish_wildcard_permissions_test diff --git a/tests/test_driver.sh b/tests/test_driver.sh index 4a0cd0492..6fac9ddac 100644 --- a/tests/test_driver.sh +++ b/tests/test_driver.sh @@ -112,10 +112,12 @@ export suppress_color # Source test util functions at startup fish_init_cmd="${fish_init_cmd} && source ${TESTS_ROOT}/test_util.fish"; -# Run the test script, but don't exec so we can do cleanup after it succeeds/fails -env HOME="$homedir" "${BUILD_ROOT}/test/root/bin/fish" \ +# Run the test script, but don't exec so we can do cleanup after it succeeds/fails. Each test is +# launched directly within its TMPDIR, so that the fish tests themselves do not need to refer to +# TMPDIR (to ensure their output as displayed in case of failure by littlecheck is reproducible). +(cd $TMPDIR; env HOME="$homedir" "${BUILD_ROOT}/test/root/bin/fish" \ --init-command "${fish_init_cmd}" \ - "$fish_script" "$script_args" + "$fish_script" "$script_args") test_status="$?" rm -rf "$homedir"