mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 19:15:40 +08:00
Port expansion test to littlecheck
This one really is a lot easier to follow
This commit is contained in:
parent
7e594e692c
commit
52b5afe2f8
|
@ -66,3 +66,254 @@ end
|
|||
|
||||
echo {{a,b}}
|
||||
#CHECK: {a} {b}
|
||||
|
||||
# Test expansion of variables
|
||||
|
||||
# We don't use the test utility function of the same name because we want
|
||||
# different behavior. Specifically, that the expansion of any variables or
|
||||
# other strings before we are invoked produce the expected expansion.
|
||||
function expansion --description 'Prints argument count followed by arguments'
|
||||
echo (count $argv) $argv
|
||||
end
|
||||
|
||||
set -l foo
|
||||
expansion "$foo"
|
||||
expansion $foo
|
||||
expansion "prefix$foo"
|
||||
expansion prefix$foo
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1 prefix
|
||||
#CHECK: 0
|
||||
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1 prefix
|
||||
#CHECK: 0
|
||||
|
||||
set -l foo ''
|
||||
expansion "$foo"
|
||||
expansion $foo
|
||||
expansion "prefix$foo"
|
||||
expansion prefix$foo
|
||||
#CHECK: 1
|
||||
#CHECK: 1
|
||||
#CHECK: 1 prefix
|
||||
#CHECK: 1 prefix
|
||||
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1 prefix
|
||||
#CHECK: 0
|
||||
|
||||
set -l foo bar
|
||||
set -l bar
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1 prefix
|
||||
#CHECK: 0
|
||||
|
||||
set -l bar baz
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
#CHECK: 1 baz
|
||||
#CHECK: 1 baz
|
||||
#CHECK: 1 prefixbaz
|
||||
#CHECK: 1 prefixbaz
|
||||
|
||||
set -l bar baz quux
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
#CHECK: 1 baz quux
|
||||
#CHECK: 2 baz quux
|
||||
#CHECK: 1 prefixbaz quux
|
||||
#CHECK: 2 prefixbaz prefixquux
|
||||
|
||||
set -l foo bar fooer fooest
|
||||
set -l fooer
|
||||
set -l fooest
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
#CHECK: 1 baz quux fooer fooest
|
||||
#CHECK: 2 baz quux
|
||||
#CHECK: 1 prefixbaz quux fooer fooest
|
||||
#CHECK: 2 prefixbaz prefixquux
|
||||
|
||||
set -l fooer ''
|
||||
expansion $$foo
|
||||
expansion prefix$$foo
|
||||
#CHECK: 3 baz quux
|
||||
#CHECK: 3 prefixbaz prefixquux prefix
|
||||
|
||||
# Slices
|
||||
|
||||
set -l foo bar '' fooest
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
expansion $foo[-5..2] # No result, because the starting index is invalid and we force-reverse.
|
||||
expansion $foo[-2..-1]
|
||||
expansion $foo[-10..-5]
|
||||
expansion (printf '%s\n' $foo)[-5..2]
|
||||
expansion (printf '%s\n' $foo)[-2..-1]
|
||||
expansion (printf '%s\n' $foo)[-10..-5]
|
||||
expansion (echo one)[2..-1]
|
||||
#CHECK: 1 baz quux fooest
|
||||
#CHECK: 2 baz quux
|
||||
#CHECK: 1 prefixbaz quux fooest
|
||||
#CHECK: 2 prefixbaz prefixquux
|
||||
#CHECK: 0
|
||||
#CHECK: 2 fooest
|
||||
#CHECK: 0
|
||||
#CHECK: 0
|
||||
#CHECK: 2 fooest
|
||||
#CHECK: 0
|
||||
#CHECK: 0
|
||||
|
||||
set -l foo
|
||||
expansion "$foo[1]"
|
||||
expansion $foo[1]
|
||||
expansion "$foo[-1]"
|
||||
expansion $foo[-1]
|
||||
expansion "$foo[2]"
|
||||
expansion $foo[2]
|
||||
expansion "$foo[1 2]"
|
||||
expansion $foo[1 2]
|
||||
expansion "$foo[2 1]"
|
||||
expansion $foo[2 1]
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
#CHECK: 1
|
||||
#CHECK: 0
|
||||
set -l foo a b c
|
||||
expansion $foo[17]
|
||||
expansion $foo[-17]
|
||||
expansion $foo[17..18]
|
||||
expansion $foo[4..-2]
|
||||
#CHECK: 0
|
||||
#CHECK: 0
|
||||
#CHECK: 0
|
||||
#CHECK: 0
|
||||
set -l foo a
|
||||
expansion $foo[2..-1]
|
||||
#CHECK: 0
|
||||
|
||||
echo "$foo[d]"
|
||||
#CHECKERR: {{.*}}expansion.fish (line {{\d+}}): Invalid index value
|
||||
#CHECKERR: echo "$foo[d]"
|
||||
#CHECKERR: ^
|
||||
echo $foo[d]
|
||||
#CHECKERR: {{.*}}expansion.fish (line {{\d+}}): Invalid index value
|
||||
#CHECKERR: echo $foo[d]
|
||||
#CHECKERR: ^
|
||||
|
||||
echo ()[1]
|
||||
# No output
|
||||
echo ()[d]
|
||||
#CHECKERR: {{.*}}expansion.fish (line {{\d+}}): Invalid index value
|
||||
#CHECKERR: echo ()[d]
|
||||
#CHECKERR: ^
|
||||
|
||||
set -l outer out1 out2
|
||||
set -l inner 1 2
|
||||
echo $outer[$inner[2]]
|
||||
#CHECK: out2
|
||||
echo $outer[$inner[2..1]]
|
||||
#CHECK: out2 out1
|
||||
|
||||
# Percent self
|
||||
echo %selfNOT NOT%self \%self "%self" '%self'
|
||||
echo %self | string match -qr '^\\d+$'
|
||||
#CHECK: %selfNOT NOT%self %self %self %self
|
||||
echo "All digits: $status"
|
||||
#CHECK: All digits: 0
|
||||
|
||||
set paren ')'
|
||||
echo $$paren
|
||||
#CHECKERR: {{.*}}expansion.fish (line {{\d+}}): $) is not a valid variable in fish.
|
||||
#CHECKERR: echo $$paren
|
||||
#CHECKERR: ^
|
||||
|
||||
# Test tilde expansion
|
||||
# On OS X, /tmp is symlinked to /private/tmp
|
||||
# $PWD is our best bet for resolving it
|
||||
set -l saved $PWD
|
||||
cd (mktemp -d)
|
||||
set tmpdir $PWD
|
||||
cd $saved
|
||||
mkdir $tmpdir/realhome
|
||||
ln -s $tmpdir/realhome $tmpdir/linkhome
|
||||
set expandedtilde (env HOME=$tmpdir/linkhome ../test/root/bin/fish -c 'echo ~')
|
||||
if test $expandedtilde != $tmpdir/linkhome
|
||||
echo '~ expands to' $expandedtilde ' - expected ' $tmpdir/linkhome
|
||||
end
|
||||
rm $tmpdir/linkhome
|
||||
rmdir $tmpdir/realhome
|
||||
rmdir $tmpdir
|
||||
|
||||
# Test path variables
|
||||
set TEST_DELIMITER one two three
|
||||
set TEST_DELIMITER_PATH one two three
|
||||
echo TEST_DELIMITER: $TEST_DELIMITER "$TEST_DELIMITER"
|
||||
echo TEST_DELIMITER_PATH: $TEST_DELIMITER_PATH "$TEST_DELIMITER_PATH"
|
||||
#CHECK: TEST_DELIMITER: one two three one two three
|
||||
#CHECK: TEST_DELIMITER_PATH: one two three one:two:three
|
||||
|
||||
set testvar ONE:TWO:THREE
|
||||
echo "Not a path: $testvar" (count $testvar)
|
||||
#CHECK: Not a path: ONE:TWO:THREE 1
|
||||
set --path testvar $testvar
|
||||
echo "As a path: $testvar" (count $testvar)
|
||||
#CHECK: As a path: ONE:TWO:THREE 3
|
||||
set testvar "$testvar:FOUR"
|
||||
echo "Appended path: $testvar" (count $testvar)
|
||||
#CHECK: Appended path: ONE:TWO:THREE:FOUR 4
|
||||
set --unpath testvar $testvar
|
||||
echo "Back to normal variable: $testvar" (count $testvar)
|
||||
#CHECK: Back to normal variable: ONE TWO THREE FOUR 4
|
||||
|
||||
# Test fatal syntax errors
|
||||
$fish -c 'echo $,foo'
|
||||
#CHECKERR: fish: $, is not a valid variable in fish.
|
||||
#CHECKERR: echo $,foo
|
||||
#CHECKERR: ^
|
||||
$fish -c 'echo {'
|
||||
#CHECKERR: fish: Unexpected end of string, incomplete parameter expansion
|
||||
#CHECKERR: echo {
|
||||
#CHECKERR: ^
|
||||
#CHECKERR:
|
||||
$fish -c 'echo {}}'
|
||||
#CHECKERR: fish: Unexpected '}' for unopened brace expansion
|
||||
#CHECKERR: echo {}}
|
||||
#CHECKERR: ^
|
||||
#CHECKERR:
|
||||
$fish -c 'command (asd)'
|
||||
#CHECKERR: fish: Command substitutions not allowed
|
||||
#CHECKERR: command (asd)
|
||||
#CHECKERR: ^
|
||||
true
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
|
||||
####################
|
||||
# Slices
|
||||
fish: Invalid index value
|
||||
echo "$foo[d]"
|
||||
^
|
||||
fish: Invalid index value
|
||||
echo $foo[d]
|
||||
^
|
||||
fish: Invalid index value
|
||||
echo ()[d]
|
||||
^
|
||||
|
||||
####################
|
||||
# Percent self
|
||||
|
||||
####################
|
||||
# Catch your breath
|
||||
fish: $) is not a valid variable in fish.
|
||||
echo $$paren
|
||||
^
|
||||
|
||||
####################
|
||||
# Test tilde expansion
|
||||
|
||||
####################
|
||||
# Test path variables
|
||||
|
||||
####################
|
||||
# Test fatal syntax errors
|
||||
fish: $, is not a valid variable in fish.
|
||||
echo $,foo
|
||||
^
|
||||
fish: Unexpected end of string, incomplete parameter expansion
|
||||
echo {
|
||||
^
|
||||
|
||||
fish: Unexpected '}' for unopened brace expansion
|
||||
echo {}}
|
||||
^
|
||||
|
||||
fish: Command substitutions not allowed
|
||||
command (asd)
|
||||
^
|
|
@ -1,157 +0,0 @@
|
|||
# Test expansion of variables
|
||||
|
||||
# We don't use the test utility function of the same name because we want
|
||||
# different behavior. Specifically, that the expansion of any variables or
|
||||
# other strings before we are invoked produce the expected expansion.
|
||||
function expansion --description 'Prints argument count followed by arguments'
|
||||
echo (count $argv) $argv
|
||||
end
|
||||
|
||||
set -l foo
|
||||
expansion "$foo"
|
||||
expansion $foo
|
||||
expansion "prefix$foo"
|
||||
expansion prefix$foo
|
||||
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
|
||||
set -l foo ''
|
||||
expansion "$foo"
|
||||
expansion $foo
|
||||
expansion "prefix$foo"
|
||||
expansion prefix$foo
|
||||
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
|
||||
set -l foo bar
|
||||
set -l bar
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
|
||||
set -l bar baz
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
|
||||
set -l bar baz quux
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
|
||||
set -l foo bar fooer fooest
|
||||
set -l fooer
|
||||
set -l fooest
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
|
||||
set -l fooer ''
|
||||
expansion $$foo
|
||||
expansion prefix$$foo
|
||||
|
||||
logmsg Slices
|
||||
|
||||
set -l foo bar '' fooest
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
expansion "prefix$$foo"
|
||||
expansion prefix$$foo
|
||||
expansion $foo[-5..2] # No result, because the starting index is invalid and we force-reverse.
|
||||
expansion $foo[-2..-1]
|
||||
expansion $foo[-10..-5]
|
||||
expansion (printf '%s\n' $foo)[-5..2]
|
||||
expansion (printf '%s\n' $foo)[-2..-1]
|
||||
expansion (printf '%s\n' $foo)[-10..-5]
|
||||
expansion (echo one)[2..-1]
|
||||
|
||||
echo "# foo = "
|
||||
set -l foo
|
||||
expansion "$foo[1]"
|
||||
expansion $foo[1]
|
||||
expansion "$foo[-1]"
|
||||
expansion $foo[-1]
|
||||
expansion "$foo[2]"
|
||||
expansion $foo[2]
|
||||
expansion "$foo[1 2]"
|
||||
expansion $foo[1 2]
|
||||
expansion "$foo[2 1]"
|
||||
expansion $foo[2 1]
|
||||
echo "# foo = a b c"
|
||||
set -l foo a b c
|
||||
expansion $foo[17]
|
||||
expansion $foo[-17]
|
||||
expansion $foo[17..18]
|
||||
expansion $foo[4..-2]
|
||||
echo "# foo = a"
|
||||
set -l foo a
|
||||
expansion $foo[2..-1]
|
||||
|
||||
echo "$foo[d]"
|
||||
echo $foo[d]
|
||||
|
||||
echo ()[1]
|
||||
echo ()[d]
|
||||
|
||||
set -l outer out1 out2
|
||||
set -l inner 1 2
|
||||
echo $outer[$inner[2]] # out2
|
||||
echo $outer[$inner[2..1]] # out2 out1
|
||||
|
||||
logmsg Percent self
|
||||
echo %selfNOT NOT%self \%self "%self" '%self'
|
||||
echo %self | string match -qr '^\\d+$'
|
||||
echo "All digits: $status"
|
||||
|
||||
logmsg Catch your breath
|
||||
set paren ')'
|
||||
echo $$paren
|
||||
|
||||
logmsg Test tilde expansion
|
||||
# On OS X, /tmp is symlinked to /private/tmp
|
||||
# $PWD is our best bet for resolving it
|
||||
set -l saved $PWD
|
||||
cd (mktemp -d)
|
||||
set tmpdir $PWD
|
||||
cd $saved
|
||||
mkdir $tmpdir/realhome
|
||||
ln -s $tmpdir/realhome $tmpdir/linkhome
|
||||
set expandedtilde (env HOME=$tmpdir/linkhome ../test/root/bin/fish -c 'echo ~')
|
||||
if test $expandedtilde != $tmpdir/linkhome
|
||||
echo '~ expands to' $expandedtilde ' - expected ' $tmpdir/linkhome
|
||||
end
|
||||
rm $tmpdir/linkhome
|
||||
rmdir $tmpdir/realhome
|
||||
rmdir $tmpdir
|
||||
|
||||
logmsg Test path variables
|
||||
set TEST_DELIMITER one two three
|
||||
set TEST_DELIMITER_PATH one two three
|
||||
echo TEST_DELIMITER: $TEST_DELIMITER "$TEST_DELIMITER"
|
||||
echo TEST_DELIMITER_PATH: $TEST_DELIMITER_PATH "$TEST_DELIMITER_PATH"
|
||||
|
||||
set testvar ONE:TWO:THREE
|
||||
echo "Not a path: $testvar" (count $testvar)
|
||||
set --path testvar $testvar
|
||||
echo "As a path: $testvar" (count $testvar)
|
||||
set testvar "$testvar:FOUR"
|
||||
echo "Appended path: $testvar" (count $testvar)
|
||||
set --unpath testvar $testvar
|
||||
echo "Back to normal variable: $testvar" (count $testvar)
|
||||
|
||||
logmsg Test fatal syntax errors
|
||||
../test/root/bin/fish -c 'echo $,foo'
|
||||
../test/root/bin/fish -c 'echo {'
|
||||
../test/root/bin/fish -c 'echo {}}'
|
||||
../test/root/bin/fish -c 'command (asd)'
|
||||
true
|
|
@ -1,92 +0,0 @@
|
|||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1
|
||||
1
|
||||
1 prefix
|
||||
1 prefix
|
||||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1
|
||||
0
|
||||
1 prefix
|
||||
0
|
||||
1 baz
|
||||
1 baz
|
||||
1 prefixbaz
|
||||
1 prefixbaz
|
||||
1 baz quux
|
||||
2 baz quux
|
||||
1 prefixbaz quux
|
||||
2 prefixbaz prefixquux
|
||||
1 baz quux fooer fooest
|
||||
2 baz quux
|
||||
1 prefixbaz quux fooer fooest
|
||||
2 prefixbaz prefixquux
|
||||
3 baz quux
|
||||
3 prefixbaz prefixquux prefix
|
||||
|
||||
####################
|
||||
# Slices
|
||||
1 baz quux fooest
|
||||
2 baz quux
|
||||
1 prefixbaz quux fooest
|
||||
2 prefixbaz prefixquux
|
||||
0
|
||||
2 fooest
|
||||
0
|
||||
0
|
||||
2 fooest
|
||||
0
|
||||
0
|
||||
# foo =
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
# foo = a b c
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
# foo = a
|
||||
0
|
||||
|
||||
out2
|
||||
out2 out1
|
||||
|
||||
####################
|
||||
# Percent self
|
||||
%selfNOT NOT%self %self %self %self
|
||||
All digits: 0
|
||||
|
||||
####################
|
||||
# Catch your breath
|
||||
|
||||
####################
|
||||
# Test tilde expansion
|
||||
|
||||
####################
|
||||
# Test path variables
|
||||
TEST_DELIMITER: one two three one two three
|
||||
TEST_DELIMITER_PATH: one two three one:two:three
|
||||
Not a path: ONE:TWO:THREE 1
|
||||
As a path: ONE:TWO:THREE 3
|
||||
Appended path: ONE:TWO:THREE:FOUR 4
|
||||
Back to normal variable: ONE TWO THREE FOUR 4
|
||||
|
||||
####################
|
||||
# Test fatal syntax errors
|
Loading…
Reference in New Issue
Block a user