2014-10-02 23:32:16 +00:00
|
|
|
# vim: set filetype=fish:
|
2013-06-17 06:26:43 +00:00
|
|
|
# ensure that builtins that produce no output can still truncate files
|
|
|
|
# (bug PCA almost reintroduced!)
|
|
|
|
echo "Testing that builtins can truncate files"
|
2016-02-07 02:08:22 +00:00
|
|
|
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
|
2013-06-17 06:26:43 +00:00
|
|
|
|
2017-07-17 21:33:51 +00:00
|
|
|
# Test events.
|
2012-12-19 14:56:19 +00:00
|
|
|
|
2013-06-17 06:26:43 +00:00
|
|
|
|
2012-12-19 14:56:19 +00:00
|
|
|
# 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
|
2012-12-22 17:38:28 +00:00
|
|
|
|
|
|
|
# test empty argument
|
2013-06-17 06:26:43 +00:00
|
|
|
emit
|
2013-12-29 06:52:06 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-12-30 00:23:26 +00:00
|
|
|
# Test implicit cd. This should do nothing.
|
|
|
|
./
|
2013-12-29 06:52:06 +00:00
|
|
|
|
2014-02-22 02:20:51 +00:00
|
|
|
# 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
|
|
|
|
|
2014-03-02 00:04:13 +00:00
|
|
|
# Test status -n
|
|
|
|
eval 'status -n
|
|
|
|
status -n
|
|
|
|
status -n'
|
|
|
|
|
2014-10-14 07:37:01 +00:00
|
|
|
# Test support for unbalanced blocks
|
|
|
|
function try_unbalanced_block
|
2016-02-07 02:08:22 +00:00
|
|
|
../test/root/bin/fish -c "echo $argv | source " 2>&1 | grep "Missing end" 1>&2
|
2014-10-14 07:37:01 +00:00
|
|
|
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'
|
|
|
|
|
2014-10-15 19:49:02 +00:00
|
|
|
# Ensure that quoted keywords work
|
|
|
|
'while' false; end
|
|
|
|
"while" false; end
|
|
|
|
"wh"'ile' false; "e"nd
|
|
|
|
|
2017-04-12 04:53:13 +00:00
|
|
|
# BOM checking (see #1518). But only in UTF8 locales.
|
2018-12-16 19:39:03 +00:00
|
|
|
# (locale guarded because of musl)
|
|
|
|
if command -sq locale; and string match -qi '*utf-8*' -- (locale)
|
2014-11-02 07:14:16 +00:00
|
|
|
echo \uFEFF"echo bom_test" | source
|
|
|
|
else
|
|
|
|
echo "echo bom_test" | source
|
|
|
|
end
|
2014-11-01 23:25:28 +00:00
|
|
|
|
2014-11-02 04:06:16 +00:00
|
|
|
# Comments abutting text (#953)
|
|
|
|
echo not#a#comment
|
|
|
|
echo is # a # comment
|