mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-12 16:53:37 +08:00
8b67a1b26f
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
150 lines
3.0 KiB
Fish
150 lines
3.0 KiB
Fish
# vim: set filetype=fish:
|
|
# ensure that builtins that produce no output can still truncate files
|
|
# (bug PCA almost reintroduced!)
|
|
echo "Testing that builtins can truncate files"
|
|
echo abc > ../test/temp/file_truncation_test.txt
|
|
cat ../test/temp/file_truncation_test.txt
|
|
echo -n > ../test/temp/file_truncation_test.txt
|
|
cat ../test/temp/file_truncation_test.txt
|
|
|
|
# Test events.
|
|
|
|
|
|
# This pattern caused a crash; github issue #449
|
|
|
|
set -g var before
|
|
|
|
function test1 --on-event test
|
|
set -g var $var:test1
|
|
functions -e test2
|
|
end
|
|
|
|
function test2 --on-event test
|
|
# this should not run, as test2 gets removed before it has a chance of running
|
|
set -g var $var:test2a
|
|
end
|
|
emit test
|
|
|
|
echo $var
|
|
|
|
|
|
function test3 --on-event test3
|
|
echo received event test3 with args: $argv
|
|
end
|
|
|
|
emit test3 foo bar
|
|
|
|
# test empty argument
|
|
emit
|
|
|
|
echo "Test break and continue"
|
|
# This should output Ping once
|
|
for i in a b c
|
|
if not contains $i c ; continue ; end
|
|
echo Ping
|
|
end
|
|
|
|
# This should output Pong not at all
|
|
for i in a b c
|
|
if not contains $i c ; break ; end
|
|
echo Pong
|
|
end
|
|
|
|
# This should output Foop three times, and Boop not at all
|
|
set i a a a
|
|
while contains $i a
|
|
set -e i[-1]
|
|
echo Foop
|
|
continue
|
|
echo Boop
|
|
end
|
|
|
|
# This should output Doop once
|
|
set i a a a
|
|
while contains $i a
|
|
set -e i[-1]
|
|
echo Doop
|
|
break
|
|
echo Darp
|
|
end
|
|
|
|
# Test implicit cd. This should do nothing.
|
|
./
|
|
|
|
# Test special for loop expansion
|
|
# Here we the name of the variable is derived from another variable
|
|
echo "Testing for loop"
|
|
set var1 var2
|
|
for $var1 in 1 2 3
|
|
echo -n $var2
|
|
end
|
|
echo
|
|
|
|
# Test status -n
|
|
eval 'status -n
|
|
status -n
|
|
status -n'
|
|
|
|
# Test psub
|
|
cat (echo foo | psub)
|
|
cat (echo bar | psub)
|
|
cat (echo baz | psub)
|
|
|
|
set -l filename (echo foo | psub)
|
|
if test -e $filename
|
|
echo 'psub file was not deleted'
|
|
else
|
|
echo 'psub file was deleted'
|
|
end
|
|
|
|
if count (echo foo | psub -s .cc | grep -o '\.cc$') >/dev/null
|
|
echo 'psub filename ends with .cc'
|
|
else
|
|
echo 'psub filename does not end with .cc'
|
|
end
|
|
|
|
if count (echo foo | psub -f -s .cc | grep -o '\.cc$') >/dev/null
|
|
echo 'psub filename ends with .cc'
|
|
else
|
|
echo 'psub filename does not end with .cc'
|
|
end
|
|
|
|
set -l filename (echo foo | psub -s .fish)
|
|
if test -e (dirname $filename)
|
|
echo 'psub directory was not deleted'
|
|
else
|
|
echo 'psub directory was deleted'
|
|
end
|
|
|
|
diff -q (__fish_print_help psub | psub) (psub -hs banana | psub)
|
|
|
|
# Test support for unbalanced blocks
|
|
function try_unbalanced_block
|
|
../test/root/bin/fish -c "echo $argv | source " 2>&1 | grep "Missing end" 1>&2
|
|
end
|
|
try_unbalanced_block 'begin'
|
|
try_unbalanced_block 'while true'
|
|
try_unbalanced_block 'for x in 1 2 3'
|
|
try_unbalanced_block 'switch abc'
|
|
try_unbalanced_block 'function anything'
|
|
try_unbalanced_block 'if false'
|
|
|
|
# Ensure that quoted keywords work
|
|
'while' false; end
|
|
"while" false; end
|
|
"wh"'ile' false; "e"nd
|
|
|
|
# BOM checking (see #1518)
|
|
# But only in UTF8
|
|
if locale | __fish_sgrep -q -i utf-8
|
|
echo \uFEFF"echo bom_test" | source
|
|
else
|
|
echo "echo bom_test" | source
|
|
end
|
|
|
|
# Comments abutting text (#953)
|
|
echo not#a#comment
|
|
echo is # a # comment
|
|
|
|
false
|