Port "test1" to littlecheck

This, together with the other testX, really just tests some basic
syntax. So let's just call it "basic".

Note that this file uses escaped newlines on purpose, so restyling it
would currently break it. I'm not sure what the best thing to do here is.
This commit is contained in:
Fabian Homborg 2020-03-17 20:48:40 +01:00
parent 2731bcec70
commit e78db2bcb8
3 changed files with 47 additions and 96 deletions

View file

@ -1,8 +1,9 @@
#RUN: %fish %s
# #
# Test function, loops, conditionals and some basic elements # Test function, loops, conditionals and some basic elements
# #
logmsg "Comments in odd places don't cause problems" # Comments in odd places don't cause problems
for i in 1 2 # Comment on same line as command for i in 1 2 # Comment on same line as command
# Comment inside loop # Comment inside loop
for j in a b for j in a b
@ -10,8 +11,12 @@ for i in 1 2 # Comment on same line as command
echo $i$j echo $i$j
end; end;
end end
#CHECK: 1a
#CHECK: 1b
#CHECK: 2a
#CHECK: 2b
logmsg Escaped newlines # Escaped newlines
echo foo\ bar echo foo\ bar
echo foo\ echo foo\
bar bar
@ -19,14 +24,22 @@ echo "foo\
bar" bar"
echo 'foo\ echo 'foo\
bar' bar'
#CHECK: foo bar
#CHECK: foobar
#CHECK: foobar
#CHECK: foo\
#CHECK: bar
for i in \ for i in \
a b c a b c
echo $i echo $i
end end
#CHECK: a
#CHECK: b
#CHECK: c
logmsg Simple function tests # Simple function tests
function foo function foo
echo >../test/temp/fish_foo.txt $argv echo >../test/temp/fish_foo.txt $argv
@ -41,12 +54,14 @@ if test $foo = hello;
else else
echo Test 2 fail echo Test 2 fail
end end
#CHECK: Test 2 pass
function foo function foo
printf 'Test %s' $argv[1]; echo ' pass' printf 'Test %s' $argv[1]; echo ' pass'
end end
foo 3a foo 3a
#CHECK: Test 3a pass
for i in Test for continue break and switch builtins problems; for i in Test for continue break and switch builtins problems;
switch $i switch $i
@ -66,6 +81,7 @@ for i in Test for continue break and switch builtins problems;
echo fail echo fail
end end
end end
#CHECK: Test 3b pass
set -l sta set -l sta
if eval true if eval true
@ -78,8 +94,9 @@ else
set sta fail set sta fail
end end
echo Test 4 $sta echo Test 4 $sta
#CHECK: Test 4 pass
logmsg "Testing builtin status" # Testing builtin status
function test_builtin_status function test_builtin_status
return 1 return 1
@ -91,31 +108,47 @@ else
set sta fail set sta fail
end end
echo Test 5 $sta echo Test 5 $sta
#CHECK: Test 5 pass
#################### ####################
logmsg echo tests # echo tests
echo 'abc\ndef' echo 'abc\ndef'
#CHECK: abc\ndef
echo -e 'abc\ndef' echo -e 'abc\ndef'
#CHECK: abc
#CHECK: def
echo -e 'abc\zdef' echo -e 'abc\zdef'
#CHECK: abc\zdef
echo -e 'abc\41def' echo -e 'abc\41def'
echo -e 'abc\041def' echo -e 'abc\041def'
#CHECK: abc!def
#CHECK: abc!def
echo -e 'abc\121def' echo -e 'abc\121def'
echo -e 'abc\1212def' echo -e 'abc\1212def'
#CHECK: abcQdef
#CHECK: abcQ2def
echo -e 'abc\cdef' # won't output a newline! echo -e 'abc\cdef' # won't output a newline!
#CHECK: abc
echo '' echo ''
echo - echo -
#CHECK: -
echo -h echo -h
#CHECK: -h
echo -ne '\376' | display_bytes echo -ne '\376' | display_bytes
echo -e Catch your breath #CHECK: 0000000 376
#CHECK: 0000001
echo -e 'abc\x21def' echo -e 'abc\x21def'
echo -e 'abc\x211def' echo -e 'abc\x211def'
#CHECK: abc!def
#CHECK: abc!1def
logmsg 'Comments allowed in between lines (#1987)' # Comments allowed in between lines (#1987)
echo before comment \ echo before comment \
# comment # comment
after comment after comment
#CHECK: before comment after comment
logmsg 'Backslashes are part of comments and do not join lines (#1255)' # Backslashes are part of comments and do not join lines (#1255)
# This should execute false, not echo it # This should execute false, not echo it
echo -n # comment\ echo -n # comment\
false false
@ -126,11 +159,16 @@ function always_fails
end end
end end
logmsg 'Verify $argv set correctly in sourced scripts (#139)' # Verify $argv set correctly in sourced scripts (#139)
echo 'echo "source argv {$argv}"' | source echo 'echo "source argv {$argv}"' | source
#CHECK: source argv {}
echo 'echo "source argv {$argv}"' | source - echo 'echo "source argv {$argv}"' | source -
#CHECK: source argv {}
echo 'echo "source argv {$argv}"' | source - abc echo 'echo "source argv {$argv}"' | source - abc
#CHECK: source argv {abc}
echo 'echo "source argv {$argv}"' | source - abc def echo 'echo "source argv {$argv}"' | source - abc def
#CHECK: source argv {abc def}
always_fails always_fails
echo $status echo $status
#CHECK: 1

View file

@ -1,24 +0,0 @@
####################
# Comments in odd places don't cause problems
####################
# Escaped newlines
####################
# Simple function tests
####################
# Testing builtin status
####################
# echo tests
####################
# Comments allowed in between lines (#1987)
####################
# Backslashes are part of comments and do not join lines (#1255)
####################
# Verify $argv set correctly in sourced scripts (#139)

View file

@ -1,63 +0,0 @@
####################
# Comments in odd places don't cause problems
1a
1b
2a
2b
####################
# Escaped newlines
foo bar
foobar
foobar
foo\
bar
a
b
c
####################
# Simple function tests
Test 2 pass
Test 3a pass
Test 3b pass
Test 4 pass
####################
# Testing builtin status
Test 5 pass
####################
# echo tests
abc\ndef
abc
def
abc\zdef
abc!def
abc!def
abcQdef
abcQ2def
abc
-
-h
0000000 376
0000001
Catch your breath
abc!def
abc!1def
####################
# Comments allowed in between lines (#1987)
before comment after comment
####################
# Backslashes are part of comments and do not join lines (#1255)
####################
# Verify $argv set correctly in sourced scripts (#139)
source argv {}
source argv {}
source argv {abc}
source argv {abc def}
1