Tests: Don't cd to the tests directory!

We:

1. Set up a nice TMPDIR for our tests to use
2. Immediately `cd` to the directory containing the test runner.

So instead we don't do (2), and stay in the temp directory, and
explicitly use all the things from the test runner directory.

I am fairly certain that cmake papered over this by adding a second
layer of temp dir.
This commit is contained in:
Fabian Boehm 2024-12-27 20:02:11 +01:00
parent 050fe09af1
commit 5e10d75a19
16 changed files with 46 additions and 40 deletions

View File

@ -141,7 +141,7 @@ echo $status
abbr --query banana --function abbr --query banana --function
echo $status echo $status
# CHECKERR: abbr: --function: option requires an argument # CHECKERR: abbr: --function: option requires an argument
# CHECKERR: checks/abbr.fish (line 141): # CHECKERR: {{.*}}checks/abbr.fish (line 141):
# CHECKERR: abbr --query banana --function # CHECKERR: abbr --query banana --function
# CHECKERR: ^ # CHECKERR: ^
# CHECKERR: (Type 'help abbr' for related documentation) # CHECKERR: (Type 'help abbr' for related documentation)

View File

@ -11,7 +11,7 @@
# No args (not even --) is an error # No args (not even --) is an error
argparse argparse
#CHECKERR: argparse: Missing -- separator #CHECKERR: argparse: Missing -- separator
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse #CHECKERR: argparse
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -19,7 +19,7 @@ argparse
# Missing -- is an error # Missing -- is an error
argparse h/help argparse h/help
#CHECKERR: argparse: Missing -- separator #CHECKERR: argparse: Missing -- separator
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse h/help #CHECKERR: argparse h/help
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -40,27 +40,27 @@ argparse h/help:
argparse h-help:: argparse h-help::
argparse h-help=x argparse h-help=x
#CHECKERR: argparse: Invalid option spec 'h-' at char '-' #CHECKERR: argparse: Invalid option spec 'h-' at char '-'
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse h- #CHECKERR: argparse h-
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
#CHECKERR: argparse: Short flag '+' invalid, must be alphanum or '#' #CHECKERR: argparse: Short flag '+' invalid, must be alphanum or '#'
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse +help #CHECKERR: argparse +help
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
#CHECKERR: argparse: Invalid option spec 'h/help:' at char ':' #CHECKERR: argparse: Invalid option spec 'h/help:' at char ':'
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse h/help: #CHECKERR: argparse h/help:
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
#CHECKERR: argparse: Invalid option spec 'h-help::' at char ':' #CHECKERR: argparse: Invalid option spec 'h-help::' at char ':'
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse h-help:: #CHECKERR: argparse h-help::
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
#CHECKERR: argparse: Invalid option spec 'h-help=x' at char 'x' #CHECKERR: argparse: Invalid option spec 'h-help=x' at char 'x'
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse h-help=x #CHECKERR: argparse h-help=x
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -89,7 +89,7 @@ end
begin begin
argparse '#-val=' -- abc -x def argparse '#-val=' -- abc -x def
# CHECKERR: argparse: Implicit int short flag '#' does not allow modifiers like '=' # CHECKERR: argparse: Implicit int short flag '#' does not allow modifiers like '='
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse '#-val=' -- abc -x def #CHECKERR: argparse '#-val=' -- abc -x def
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -105,7 +105,7 @@ end
begin begin
argparse s/short x/xray s/long -- -s -x --long argparse s/short x/xray s/long -- -s -x --long
# CHECKERR: argparse: Short flag 's' already defined # CHECKERR: argparse: Short flag 's' already defined
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse s/short x/xray s/long -- -s -x --long #CHECKERR: argparse s/short x/xray s/long -- -s -x --long
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -115,7 +115,7 @@ end
begin begin
argparse s/short x/xray l/short -- -s -x --long argparse s/short x/xray l/short -- -s -x --long
# CHECKERR: argparse: Long flag 'short' already defined # CHECKERR: argparse: Long flag 'short' already defined
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse s/short x/xray l/short -- -s -x --long #CHECKERR: argparse s/short x/xray l/short -- -s -x --long
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -125,7 +125,7 @@ end
begin begin
argparse '#-val' x/xray 'v#val' -- -s -x --long argparse '#-val' x/xray 'v#val' -- -s -x --long
# CHECKERR: argparse: Implicit int flag '#' already defined # CHECKERR: argparse: Implicit int flag '#' already defined
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse '#-val' x/xray 'v#val' -- -s -x --long #CHECKERR: argparse '#-val' x/xray 'v#val' -- -s -x --long
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -135,7 +135,7 @@ end
begin begin
argparse 'v#val=' -- argparse 'v#val=' --
# CHECKERR: argparse: Implicit int short flag 'v' does not allow modifiers like '=' # CHECKERR: argparse: Implicit int short flag 'v' does not allow modifiers like '='
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse 'v#val=' -- #CHECKERR: argparse 'v#val=' --
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)
@ -500,7 +500,7 @@ end
begin begin
argparse '' argparse ''
#CHECKERR: argparse: An option spec must have at least a short or a long flag #CHECKERR: argparse: An option spec must have at least a short or a long flag
#CHECKERR: checks/argparse.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}):
#CHECKERR: argparse '' #CHECKERR: argparse ''
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help argparse' for related documentation) #CHECKERR: (Type 'help argparse' for related documentation)

View File

@ -1,6 +1,6 @@
#RUN: %fish -C 'set -g fish %fish' %s #RUN: %fish -C 'set -g fish %fish' %s
begin begin
set -l dir $PWD/(dirname (status -f)) set -l dir (dirname (status -f))
set -gx XDG_CONFIG_HOME $dir/broken-config/ set -gx XDG_CONFIG_HOME $dir/broken-config/
set -gx HOME $dir/broken-config/ set -gx HOME $dir/broken-config/
$fish -l -c 'echo but still going' $fish -l -c 'echo but still going'

View File

@ -35,7 +35,7 @@ echo $status
set -g PATH . set -g PATH .
echo banana > foobar echo banana > foobar
foobar --banana foobar --banana
# CHECKERR: checks/command-not-found.fish (line {{\d+}}): Unknown command. './foobar' exists but is not an executable file. # CHECKERR: {{.*}}checks/command-not-found.fish (line {{\d+}}): Unknown command. './foobar' exists but is not an executable file.
# CHECKERR: foobar --banana # CHECKERR: foobar --banana
# CHECKERR: ^~~~~^ # CHECKERR: ^~~~~^

View File

@ -40,6 +40,8 @@ complete -c t -fa '(t)'
complete -C't ' complete -C't '
# CHECK: t # CHECK: t
touch test.fish
# Ensure file completion happens even though it was disabled above. # Ensure file completion happens even though it was disabled above.
complete -c t -l fileoption -rF complete -c t -l fileoption -rF
# Only match one file because I don't want to touch this any time we add a test file. # Only match one file because I don't want to touch this any time we add a test file.

View File

@ -65,7 +65,7 @@ source /banana/\t/foo
function eval function eval
builtin eval $argv builtin eval $argv
end end
# CHECKERR: checks/eval.fish (line {{\d+}}): function: eval: cannot use reserved keyword as function name # CHECKERR: {{.*}}checks/eval.fish (line {{\d+}}): function: eval: cannot use reserved keyword as function name
# CHECKERR: function eval # CHECKERR: function eval
# CHECKERR: ^ # CHECKERR: ^

View File

@ -337,7 +337,7 @@ printf '<%s>\n' ($fish -c 'echo "$abc["' 2>&1)
set -l pager command less set -l pager command less
echo foo | $pager echo foo | $pager
#CHECKERR: checks/expansion.fish (line 339): The expanded command is a keyword. #CHECKERR: {{.*}}checks/expansion.fish (line 339): The expanded command is a keyword.
#CHECKERR: echo foo | $pager #CHECKERR: echo foo | $pager
#CHECKERR: ^~~~~^ #CHECKERR: ^~~~~^

View File

@ -170,7 +170,7 @@ functions --no-details t2
functions --no-details --details t functions --no-details --details t
# CHECKERR: functions: invalid option combination # CHECKERR: functions: invalid option combination
# CHECKERR: # CHECKERR:
# CHECKERR: checks/functions.fish (line {{\d+}}): # CHECKERR: {{.*}}checks/functions.fish (line {{\d+}}):
# CHECKERR: functions --no-details --details t # CHECKERR: functions --no-details --details t
# CHECKERR: ^ # CHECKERR: ^
# CHECKERR: (Type 'help functions' for related documentation) # CHECKERR: (Type 'help functions' for related documentation)
@ -205,7 +205,7 @@ functions --names -a | string match __fish_config_interactive
functions --description "" functions --description ""
# CHECKERR: functions: Expected exactly one function name # CHECKERR: functions: Expected exactly one function name
# CHECKERR: checks/functions.fish (line {{\d+}}): # CHECKERR: {{.*}}checks/functions.fish (line {{\d+}}):
# CHECKERR: functions --description "" # CHECKERR: functions --description ""
# CHECKERR: ^ # CHECKERR: ^
# CHECKERR: (Type 'help functions' for related documentation) # CHECKERR: (Type 'help functions' for related documentation)

View File

@ -953,7 +953,7 @@ end
set -e undefined[x..] set -e undefined[x..]
# CHECKERR: set: Invalid index starting at 'undefined' # CHECKERR: set: Invalid index starting at 'undefined'
# CHECKERR: checks/set.fish (line 954): # CHECKERR: {{.*}}checks/set.fish (line {{\d+}}):
# CHECKERR: set -e undefined[x..] # CHECKERR: set -e undefined[x..]
# CHECKERR: ^ # CHECKERR: ^
# CHECKERR: (Type 'help set' for related documentation) # CHECKERR: (Type 'help set' for related documentation)

View File

@ -889,7 +889,7 @@ echo $status
function string function string
builtin string $argv builtin string $argv
end end
# CHECKERR: checks/string.fish (line {{\d+}}): function: string: cannot use reserved keyword as function name # CHECKERR: {{.*}}checks/string.fish (line {{\d+}}): function: string: cannot use reserved keyword as function name
# CHECKERR: function string # CHECKERR: function string
# CHECKERR: ^ # CHECKERR: ^

View File

@ -108,12 +108,12 @@ begin
echo Matched! echo Matched!
end end
# CHECKERR: fish: Unknown command: doesnotexist # CHECKERR: fish: Unknown command: doesnotexist
# CHECKERR: checks/switch.fish (line {{\d+}}): # CHECKERR: {{.*}}checks/switch.fish (line {{\d+}}):
# CHECKERR: doesnotexist # CHECKERR: doesnotexist
# CHECKERR: ^~~~~~~~~~~^ # CHECKERR: ^~~~~~~~~~~^
# CHECKERR: in command substitution # CHECKERR: in command substitution
# CHECKERR: {{\t}}called on line {{\d+}} of file checks/switch.fish # CHECKERR: {{\t}}called on line {{\d+}} of file {{.*}}checks/switch.fish
# CHECKERR: checks/switch.fish (line {{\d+}}): Unknown command # CHECKERR: {{.*}}checks/switch.fish (line {{\d+}}): Unknown command
# CHECKERR: switch (doesnotexist) # CHECKERR: switch (doesnotexist)
# CHECKERR: ^~~~~~~~~~~~~^ # CHECKERR: ^~~~~~~~~~~~~^
end end

View File

@ -21,6 +21,7 @@ else
echo fish_variables is still a symlink echo fish_variables is still a symlink
end end
# CHECK: fish_variables is still a symlink # CHECK: fish_variables is still a symlink
rm $fish_variables
# fish_history # fish_history
@ -45,3 +46,4 @@ else
echo fish_history is still a symlink echo fish_history is still a symlink
end end
# CHECK: fish_history is still a symlink # CHECK: fish_history is still a symlink
rm $history_file

View File

@ -9,7 +9,7 @@ ulimit --core-size
ulimit 4352353252352352334 ulimit 4352353252352352334
#CHECKERR: ulimit: Invalid limit '4352353252352352334' #CHECKERR: ulimit: Invalid limit '4352353252352352334'
#CHECKERR: #CHECKERR:
#CHECKERR: checks/ulimit.fish (line {{\d+}}): #CHECKERR: {{.*}}checks/ulimit.fish (line {{\d+}}):
#CHECKERR: ulimit 4352353252352352334 #CHECKERR: ulimit 4352353252352352334
#CHECKERR: ^ #CHECKERR: ^
#CHECKERR: (Type 'help ulimit' for related documentation) #CHECKERR: (Type 'help ulimit' for related documentation)

View File

@ -12,7 +12,7 @@ touch ./b/file.txt
set dirs ./a ./b set dirs ./a ./b
echo $dirs/*.txt # CHECK: ./b/file.txt echo $dirs/*.txt # CHECK: ./b/file.txt
echo */foo/ echo */foo/
# CHECKERR: checks/wildcard.fish (line {{\d+}}): No matches for wildcard '*/foo/'. See `help wildcards-globbing`. # CHECKERR: {{.*}}checks/wildcard.fish (line {{\d+}}): No matches for wildcard '*/foo/'. See `help wildcards-globbing`.
# CHECKERR: echo */foo/ # CHECKERR: echo */foo/
# CHECKERR: ^~~~~^ # CHECKERR: ^~~~~^

View File

@ -6,21 +6,23 @@
# `fish_update_completions` when running tests. # `fish_update_completions` when running tests.
set -gx FISH_UNIT_TESTS_RUNNING 1 set -gx FISH_UNIT_TESTS_RUNNING 1
# Change to directory containing this script # Save the directory containing this script
cd (status dirname) # Do not *cd* here, otherwise you'll ruin our nice tmpdir setup!!!
set -l scriptdir (status dirname)
# Test files specified on commandline, or all pexpect files. # Test files specified on commandline, or all pexpect files.
if set -q argv[1] && test -n "$argv[1]" if set -q argv[1] && test -n "$argv[1]"
set pexpect_files_to_test pexpects/$argv set pexpect_files_to_test $scriptdir/pexpects/$argv
else if set -q FISH_PEXPECT_FILES else if set -q FISH_PEXPECT_FILES
set pexpect_files_to_test (string replace -r '^.*/(?=pexpects/)' '' -- $FISH_PEXPECT_FILES) set pexpect_files_to_test (string replace -r '^.*/(?=pexpects/)' '' -- $FISH_PEXPECT_FILES)
else else
say -o cyan "Testing interactive functionality" say -o cyan "Testing interactive functionality"
set pexpect_files_to_test pexpects/*.py set pexpect_files_to_test $scriptdir/pexpects/*.py
end end
source test_util.fish || exit source $scriptdir/test_util.fish || exit
cat interactive.config >>$XDG_CONFIG_HOME/fish/config.fish cat $scriptdir/interactive.config >>$XDG_CONFIG_HOME/fish/config.fish
set -lx --prepend PYTHONPATH (realpath $scriptdir)
function test_pexpect_file function test_pexpect_file
set -l file $argv[1] set -l file $argv[1]
@ -33,7 +35,6 @@ function test_pexpect_file
# Help the script find the pexpect_helper module in our parent directory. # Help the script find the pexpect_helper module in our parent directory.
set -q FISHDIR set -q FISHDIR
or set -l FISHDIR ../test/root/bin/ or set -l FISHDIR ../test/root/bin/
set -lx --prepend PYTHONPATH (realpath $PWD)
set -lx fish $FISHDIR/fish set -lx fish $FISHDIR/fish
set -lx fish_key_reader $FISHDIR/fish_key_reader set -lx fish_key_reader $FISHDIR/fish_key_reader
path is -fx -- $FISHDIR/fish_test_helper path is -fx -- $FISHDIR/fish_test_helper

View File

@ -8,15 +8,16 @@
# `fish_update_completions` when running tests. # `fish_update_completions` when running tests.
set -x FISH_UNIT_TESTS_RUNNING 1 set -x FISH_UNIT_TESTS_RUNNING 1
# Change to directory containing this script # Save the directory containing this script
cd (status dirname) # Do not *cd* here, otherwise you'll ruin our nice tmpdir setup!!!
set -l scriptdir (status dirname)
# Test files specified on commandline, or all checks. # Test files specified on commandline, or all checks.
set -l files_to_test set -l files_to_test
if set -q argv[1] if set -q argv[1]
set files_to_test checks/$argv.fish set files_to_test $scriptdir/checks/$argv.fish
else else
set files_to_test checks/*.fish set files_to_test $scriptdir/checks/*.fish
end end
# Be less verbose when running tests one-by-one # Be less verbose when running tests one-by-one
@ -41,11 +42,11 @@ if set -q files_to_test[1]
test "$FISH_FORCE_COLOR" = 1 test "$FISH_FORCE_COLOR" = 1
and set force_color --force-color and set force_color --force-color
$python -S littlecheck.py \ $python -S $scriptdir/littlecheck.py \
--progress $force_color \ --progress $force_color \
-s fish=$FISHDIR/fish \ -s fish=$FISHDIR/fish \
-s fish_test_helper=$fish_test_helper \ -s fish_test_helper=$fish_test_helper \
-s filter-control-sequences="$FISHDIR/fish ../tests/filter-control-sequences.fish" \ -s filter-control-sequences="$FISHDIR/fish $scriptdir/filter-control-sequences.fish" \
$files_to_test $files_to_test
set -l littlecheck_status $status set -l littlecheck_status $status