fish-shell/tests/test1.in

137 lines
2.1 KiB
Fish
Raw Normal View History

#
# Test function, loops, conditionals and some basic elements
#
logmsg "Comments in odd places don't cause problems"
for i in 1 2 # Comment on same line as command
# Comment inside loop
for j in a b
# Double loop
echo $i$j
end;
end
logmsg Escaped newlines
echo foo\ bar
echo foo\
bar
echo "foo\
bar"
echo 'foo\
bar'
for i in \
a b c
echo $i
end
logmsg Simple function tests
2010-09-18 02:18:26 +00:00
function foo
echo >../test/temp/fish_foo.txt $argv
end
foo hello
cat ../test/temp/fish_foo.txt |read foo
if test $foo = hello;
echo Test 2 pass
else
echo Test 2 fail
end
2010-09-18 02:18:26 +00:00
function foo
printf 'Test %s' $argv[1]; echo ' pass'
end
foo 3a
for i in Test for continue break and switch builtins problems;
switch $i
case Test
2010-09-18 02:18:26 +00:00
printf "%s " $i
case "for"
printf "%s " 3b
case "c*"
echo pass
case break
continue
echo fail
case and
break
echo fail
case "*"
echo fail
end
end
2010-11-23 15:05:21 +00: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-23 16:35:56 +00:00
logmsg "Testing builtin status"
2015-01-17 23:22:37 +00:00
2010-11-23 16:35:56 +00: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
####################
logmsg echo tests
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'
echo -e 'abc\cdef' # won't output a newline!
echo ''
echo -
2017-06-19 05:25:00 +00:00
echo -h
2017-02-01 02:44:02 +00:00
echo -ne '\376' | display_bytes
echo -e Catch your breath
echo -e 'abc\x21def'
echo -e 'abc\x211def'
logmsg 'Comments allowed in between lines (#1987)'
2015-04-06 06:47:04 +00:00
echo before comment \
# comment
after comment
logmsg 'Backslashes are part of comments and do not join lines (#1255)'
# This should execute false, not echo it
echo -n # comment\
false
function always_fails
if true
return 1
end
end
logmsg 'Verify $argv set correctly in sourced scripts (#139)'
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
always_fails
echo $status