2005-09-20 23:31:55 +10:00
|
|
|
#
|
2017-08-04 13:33:47 -07:00
|
|
|
# Test function, loops, conditionals and some basic elements
|
2005-09-20 23:31:55 +10:00
|
|
|
#
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg "Comments in odd places don't cause problems"
|
|
|
|
for i in 1 2 # Comment on same line as command
|
|
|
|
# Comment inside loop
|
2005-09-20 23:31:55 +10:00
|
|
|
for j in a b
|
2017-08-04 13:33:47 -07:00
|
|
|
# Double loop
|
2005-09-20 23:31:55 +10:00
|
|
|
echo $i$j
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
|
2019-05-18 20:31:41 +02:00
|
|
|
logmsg Brace expansion
|
2012-11-20 13:52:53 -08:00
|
|
|
echo x-{1}
|
|
|
|
echo x-{1,2}
|
|
|
|
echo foo-{1,2{3,4}}
|
2018-01-02 15:24:48 +01:00
|
|
|
|
2018-01-02 15:20:19 +01:00
|
|
|
echo foo-{} # literal "{}" expands to itself
|
|
|
|
echo foo-{{},{}} # the inner "{}" expand to themselves, the outer pair expands normally.
|
2019-05-18 20:31:41 +02:00
|
|
|
echo foo-{{a},{}} # also works with something in the braces.
|
|
|
|
echo foo-{""} # still expands to foo-{}
|
|
|
|
echo banana # just as a marker
|
2018-01-02 15:20:19 +01:00
|
|
|
echo foo-{$undefinedvar} # still expands to nothing
|
2012-11-20 13:52:53 -08:00
|
|
|
|
2018-01-02 15:24:48 +01:00
|
|
|
echo foo-{,,,} # four empty items in the braces.
|
|
|
|
echo foo-{,\,,} # an empty item, a "," and an empty item.
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg Escaped newlines
|
2012-11-22 01:09:07 -08:00
|
|
|
echo foo\ bar
|
|
|
|
echo foo\
|
|
|
|
bar
|
|
|
|
echo "foo\
|
|
|
|
bar"
|
|
|
|
echo 'foo\
|
|
|
|
bar'
|
|
|
|
|
2012-11-23 12:03:36 -08:00
|
|
|
for i in \
|
|
|
|
a b c
|
|
|
|
echo $i
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg Simple function tests
|
2005-09-20 23:31:55 +10:00
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function foo
|
2016-02-06 18:08:22 -08:00
|
|
|
echo >../test/temp/fish_foo.txt $argv
|
2005-09-20 23:31:55 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
foo hello
|
|
|
|
|
2016-02-06 18:08:22 -08:00
|
|
|
cat ../test/temp/fish_foo.txt |read foo
|
2005-09-20 23:31:55 +10:00
|
|
|
|
|
|
|
if test $foo = hello;
|
|
|
|
echo Test 2 pass
|
|
|
|
else
|
|
|
|
echo Test 2 fail
|
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function foo
|
2017-07-03 15:36:38 -07:00
|
|
|
printf 'Test %s' $argv[1]; echo ' pass'
|
2005-09-20 23:31:55 +10:00
|
|
|
end
|
|
|
|
|
2017-07-03 15:36:38 -07:00
|
|
|
foo 3a
|
2005-09-20 23:31:55 +10:00
|
|
|
|
|
|
|
for i in Test for continue break and switch builtins problems;
|
|
|
|
switch $i
|
|
|
|
case Test
|
2010-09-18 10:18:26 +08:00
|
|
|
printf "%s " $i
|
2018-03-31 16:48:57 -07:00
|
|
|
case "for"
|
2017-07-03 15:36:38 -07:00
|
|
|
printf "%s " 3b
|
2005-09-20 23:31:55 +10:00
|
|
|
case "c*"
|
|
|
|
echo pass
|
|
|
|
case break
|
|
|
|
continue
|
|
|
|
echo fail
|
|
|
|
case and
|
|
|
|
break
|
|
|
|
echo fail
|
|
|
|
case "*"
|
|
|
|
echo fail
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-23 23:05:21 +08:00
|
|
|
set -l sta
|
|
|
|
if eval true
|
|
|
|
if eval false
|
|
|
|
set sta fail
|
|
|
|
else
|
|
|
|
set sta pass
|
|
|
|
end
|
|
|
|
else
|
|
|
|
set sta fail
|
|
|
|
end
|
|
|
|
echo Test 4 $sta
|
2010-11-24 00:35:56 +08:00
|
|
|
|
2019-04-13 12:04:44 -05:00
|
|
|
logmsg "Testing builtin status"
|
2015-01-17 15:22:37 -08:00
|
|
|
|
2010-11-24 00:35:56 +08:00
|
|
|
function test_builtin_status
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
test_builtin_status
|
|
|
|
if [ $status -eq 1 ]
|
|
|
|
set sta pass
|
|
|
|
else
|
|
|
|
set sta fail
|
|
|
|
end
|
|
|
|
echo Test 5 $sta
|
2012-10-17 02:56:03 -07:00
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg Verify that we can turn stderr into stdout and then pipe it
|
2019-03-24 21:12:41 -07:00
|
|
|
# Note that the order here has historically been unspecified - 'errput' could conceivably appear before 'output'.
|
2019-04-03 16:47:05 -07:00
|
|
|
begin ; echo output ; echo errput 1>&2 ; end 2>&1 | sort | tee ../test/temp/tee_test.txt ; cat ../test/temp/tee_test.txt
|
2013-08-18 16:55:01 -07:00
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg "Test that trailing ^ doesn't trigger redirection, see #1873"
|
2016-06-12 02:16:46 -07:00
|
|
|
echo caret_no_redirect 12345^
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg Verify that we can pipe something other than stdout
|
2014-01-13 02:49:41 -08:00
|
|
|
# The first line should be printed, since we output to stdout but pipe stderr to /dev/null
|
|
|
|
# The second line should not be printed, since we output to stderr and pipe it to /dev/null
|
|
|
|
begin ; echo is_stdout ; end 2>| cat > /dev/null
|
|
|
|
begin ; echo is_stderr 1>&2 ; end 2>| cat > /dev/null
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
####################
|
|
|
|
logmsg echo tests
|
2012-10-17 02:56:03 -07:00
|
|
|
echo 'abc\ndef'
|
|
|
|
echo -e 'abc\ndef'
|
|
|
|
echo -e 'abc\zdef'
|
|
|
|
echo -e 'abc\41def'
|
|
|
|
echo -e 'abc\041def'
|
|
|
|
echo -e 'abc\121def'
|
|
|
|
echo -e 'abc\1212def'
|
2012-10-17 02:59:43 -07:00
|
|
|
echo -e 'abc\cdef' # won't output a newline!
|
|
|
|
echo ''
|
2014-05-16 15:19:07 +08:00
|
|
|
echo -
|
2017-06-18 22:25:00 -07:00
|
|
|
echo -h
|
2017-01-31 18:44:02 -08:00
|
|
|
echo -ne '\376' | display_bytes
|
2012-10-17 02:56:03 -07:00
|
|
|
echo -e Catch your breath
|
|
|
|
echo -e 'abc\x21def'
|
|
|
|
echo -e 'abc\x211def'
|
2014-02-12 01:39:06 -08:00
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg "Verify that pipes don't conflict with fd redirections"
|
2015-01-04 14:18:06 -08:00
|
|
|
# This code is very similar to eval. We go over a bunch of fads
|
|
|
|
# to make it likely that we will nominally conflict with a pipe
|
|
|
|
# fish is supposed to detect this case and dup the pipe to something else
|
|
|
|
echo "/bin/echo pipe 3 <&3 3<&-" | source 3<&0
|
|
|
|
echo "/bin/echo pipe 4 <&4 4<&-" | source 4<&0
|
|
|
|
echo "/bin/echo pipe 5 <&5 5<&-" | source 5<&0
|
|
|
|
echo "/bin/echo pipe 6 <&6 6<&-" | source 6<&0
|
|
|
|
echo "/bin/echo pipe 7 <&7 7<&-" | source 7<&0
|
|
|
|
echo "/bin/echo pipe 8 <&8 8<&-" | source 8<&0
|
|
|
|
echo "/bin/echo pipe 9 <&9 9<&-" | source 9<&0
|
|
|
|
echo "/bin/echo pipe 10 <&10 10<&-" | source 10<&0
|
|
|
|
echo "/bin/echo pipe 11 <&11 11<&-" | source 11<&0
|
|
|
|
echo "/bin/echo pipe 12 <&12 12<&-" | source 12<&0
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg "Make sure while loops don't run forever with no-exec (#1543)"
|
2014-07-11 11:28:10 -07:00
|
|
|
echo "Checking for infinite loops in no-execute"
|
2016-02-06 18:08:22 -08:00
|
|
|
echo "while true; end" | ../test/root/bin/fish --no-execute
|
2014-07-11 11:28:10 -07:00
|
|
|
|
2017-08-20 12:02:45 -07:00
|
|
|
logmsg "For loops with read-only vars is an error (#4342)"
|
|
|
|
for status in a b c
|
|
|
|
echo $status
|
|
|
|
end
|
|
|
|
|
2019-01-18 19:24:49 +01:00
|
|
|
logmsg "That goes for non-electric ones as well (#5548)"
|
|
|
|
for hostname in a b c
|
|
|
|
echo $hostname
|
|
|
|
end
|
|
|
|
|
2017-09-08 21:14:26 -07:00
|
|
|
logmsg For loop control vars available outside the for block
|
|
|
|
begin
|
|
|
|
set -l loop_var initial-value
|
|
|
|
for loop_var in a b c
|
|
|
|
# do nothing
|
|
|
|
end
|
|
|
|
set --show loop_var
|
|
|
|
end
|
|
|
|
|
|
|
|
set -g loop_var global_val
|
|
|
|
function loop_test
|
|
|
|
for loop_var in a b c
|
|
|
|
if test $loop_var = b
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
set --show loop_var
|
|
|
|
end
|
|
|
|
loop_test
|
|
|
|
set --show loop_var
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l loop_var
|
|
|
|
for loop_var in aa bb cc
|
|
|
|
end
|
|
|
|
set --show loop_var
|
|
|
|
end
|
|
|
|
set --show loop_var
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg 'Comments allowed in between lines (#1987)'
|
2015-04-05 23:47:04 -07:00
|
|
|
echo before comment \
|
|
|
|
# comment
|
|
|
|
after comment
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg 'Backslashes are part of comments and do not join lines (#1255)'
|
2015-05-02 18:22:20 -07:00
|
|
|
# This should execute false, not echo it
|
|
|
|
echo -n # comment\
|
|
|
|
false
|
|
|
|
|
2014-02-12 01:39:06 -08:00
|
|
|
function always_fails
|
|
|
|
if true
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
logmsg 'Verify $argv set correctly in sourced scripts (#139)'
|
2016-04-06 13:04:44 -07:00
|
|
|
echo 'echo "source argv {$argv}"' | source
|
|
|
|
echo 'echo "source argv {$argv}"' | source -
|
|
|
|
echo 'echo "source argv {$argv}"' | source - abc
|
|
|
|
echo 'echo "source argv {$argv}"' | source - abc def
|
2014-02-12 01:39:06 -08:00
|
|
|
|
2017-08-04 13:33:47 -07:00
|
|
|
always_fails
|
|
|
|
echo $status
|