2005-09-20 13:31:55 +00:00
|
|
|
#
|
2017-08-04 20:33:47 +00:00
|
|
|
# Test function, loops, conditionals and some basic elements
|
2005-09-20 13:31:55 +00:00
|
|
|
#
|
|
|
|
|
2017-08-04 20:33:47 +00: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 13:31:55 +00:00
|
|
|
for j in a b
|
2017-08-04 20:33:47 +00:00
|
|
|
# Double loop
|
2005-09-20 13:31:55 +00:00
|
|
|
echo $i$j
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
|
2017-08-04 20:33:47 +00:00
|
|
|
logmsg Escaped newlines
|
2012-11-22 09:09:07 +00:00
|
|
|
echo foo\ bar
|
|
|
|
echo foo\
|
|
|
|
bar
|
|
|
|
echo "foo\
|
|
|
|
bar"
|
|
|
|
echo 'foo\
|
|
|
|
bar'
|
|
|
|
|
2012-11-23 20:03:36 +00:00
|
|
|
for i in \
|
|
|
|
a b c
|
|
|
|
echo $i
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-08-04 20:33:47 +00:00
|
|
|
logmsg Simple function tests
|
2005-09-20 13:31:55 +00:00
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function foo
|
2016-02-07 02:08:22 +00:00
|
|
|
echo >../test/temp/fish_foo.txt $argv
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
foo hello
|
|
|
|
|
2016-02-07 02:08:22 +00:00
|
|
|
cat ../test/temp/fish_foo.txt |read foo
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
if test $foo = hello;
|
|
|
|
echo Test 2 pass
|
|
|
|
else
|
|
|
|
echo Test 2 fail
|
|
|
|
end
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function foo
|
2017-07-03 22:36:38 +00:00
|
|
|
printf 'Test %s' $argv[1]; echo ' pass'
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
2017-07-03 22:36:38 +00:00
|
|
|
foo 3a
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
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
|
2018-03-31 23:48:57 +00:00
|
|
|
case "for"
|
2017-07-03 22:36:38 +00:00
|
|
|
printf "%s " 3b
|
2005-09-20 13:31:55 +00:00
|
|
|
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
|
|
|
|
2019-04-13 17:04:44 +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
|
2012-10-17 09:56:03 +00:00
|
|
|
|
2017-08-04 20:33:47 +00:00
|
|
|
####################
|
|
|
|
logmsg echo tests
|
2012-10-17 09:56:03 +00: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 09:59:43 +00:00
|
|
|
echo -e 'abc\cdef' # won't output a newline!
|
|
|
|
echo ''
|
2014-05-16 07:19:07 +00:00
|
|
|
echo -
|
2017-06-19 05:25:00 +00:00
|
|
|
echo -h
|
2017-02-01 02:44:02 +00:00
|
|
|
echo -ne '\376' | display_bytes
|
2012-10-17 09:56:03 +00:00
|
|
|
echo -e Catch your breath
|
|
|
|
echo -e 'abc\x21def'
|
|
|
|
echo -e 'abc\x211def'
|
2014-02-12 09:39:06 +00:00
|
|
|
|
2017-08-04 20:33:47 +00:00
|
|
|
logmsg 'Comments allowed in between lines (#1987)'
|
2015-04-06 06:47:04 +00:00
|
|
|
echo before comment \
|
|
|
|
# comment
|
|
|
|
after comment
|
|
|
|
|
2017-08-04 20:33:47 +00:00
|
|
|
logmsg 'Backslashes are part of comments and do not join lines (#1255)'
|
2015-05-03 01:22:20 +00:00
|
|
|
# This should execute false, not echo it
|
|
|
|
echo -n # comment\
|
|
|
|
false
|
|
|
|
|
2014-02-12 09:39:06 +00:00
|
|
|
function always_fails
|
|
|
|
if true
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-04 20:33:47 +00:00
|
|
|
logmsg 'Verify $argv set correctly in sourced scripts (#139)'
|
2016-04-06 20:04:44 +00: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 09:39:06 +00:00
|
|
|
|
2017-08-04 20:33:47 +00:00
|
|
|
always_fails
|
|
|
|
echo $status
|