mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 00:52:46 +08:00
Port a part of test1 to littlecheck
Test1 is a grab bag of stuff, so we need to separate it. This part is concerned with for-loops, so we move it to loops.fish
This commit is contained in:
parent
ee8ca246f8
commit
5e6c9508e9
|
@ -1,4 +1,4 @@
|
||||||
#RUN: %fish %s
|
#RUN: %fish -C 'set -g fish %fish' %s
|
||||||
|
|
||||||
function never_runs
|
function never_runs
|
||||||
while false
|
while false
|
||||||
|
@ -90,3 +90,77 @@ for i in 1 2 3
|
||||||
end
|
end
|
||||||
|
|
||||||
if false ; or --help ; end
|
if false ; or --help ; end
|
||||||
|
|
||||||
|
# Make sure while loops don't run forever with no-exec (#1543)
|
||||||
|
echo "while true; end" | $fish --no-execute
|
||||||
|
|
||||||
|
# For loops with read-only vars is an error (#4342)
|
||||||
|
for status in a b c
|
||||||
|
echo $status
|
||||||
|
end
|
||||||
|
#CHECKERR: {{.*}}loops.fish (line {{\d+}}): You cannot use read-only variable 'status' in a for loop
|
||||||
|
#CHECKERR: for status in a b c
|
||||||
|
#CHECKERR: ^
|
||||||
|
|
||||||
|
# "That goes for non-electric ones as well (#5548)"
|
||||||
|
for hostname in a b c
|
||||||
|
echo $hostname
|
||||||
|
end
|
||||||
|
#CHECKERR: {{.*}}loops.fish (line {{\d+}}): You cannot use read-only variable 'hostname' in a for loop
|
||||||
|
#CHECKERR: for hostname in a b c
|
||||||
|
#CHECKERR: ^
|
||||||
|
|
||||||
|
# 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
|
||||||
|
#CHECK: $loop_var: set in local scope, unexported, with 1 elements
|
||||||
|
#CHECK: $loop_var[1]: length=1 value=|c|
|
||||||
|
#CHECK: $loop_var: not set in global scope
|
||||||
|
#CHECK: $loop_var: not set in universal scope
|
||||||
|
#CHECK:
|
||||||
|
#CHECK: $loop_var: set in local scope, unexported, with 1 elements
|
||||||
|
#CHECK: $loop_var[1]: length=1 value=|b|
|
||||||
|
#CHECK: $loop_var: set in global scope, unexported, with 1 elements
|
||||||
|
#CHECK: $loop_var[1]: length=10 value=|global_val|
|
||||||
|
#CHECK: $loop_var: not set in universal scope
|
||||||
|
#CHECK:
|
||||||
|
#CHECK: $loop_var: not set in local scope
|
||||||
|
#CHECK: $loop_var: set in global scope, unexported, with 1 elements
|
||||||
|
#CHECK: $loop_var[1]: length=10 value=|global_val|
|
||||||
|
#CHECK: $loop_var: not set in universal scope
|
||||||
|
#CHECK:
|
||||||
|
#CHECK: $loop_var: set in local scope, unexported, with 1 elements
|
||||||
|
#CHECK: $loop_var[1]: length=2 value=|cc|
|
||||||
|
#CHECK: $loop_var: set in global scope, unexported, with 1 elements
|
||||||
|
#CHECK: $loop_var[1]: length=10 value=|global_val|
|
||||||
|
#CHECK: $loop_var: not set in universal scope
|
||||||
|
#CHECK:
|
||||||
|
#CHECK: $loop_var: not set in local scope
|
||||||
|
#CHECK: $loop_var: set in global scope, unexported, with 1 elements
|
||||||
|
#CHECK: $loop_var[1]: length=10 value=|global_val|
|
||||||
|
#CHECK: $loop_var: not set in universal scope
|
||||||
|
|
|
@ -26,24 +26,6 @@
|
||||||
####################
|
####################
|
||||||
# Verify that pipes don't conflict with fd redirections
|
# Verify that pipes don't conflict with fd redirections
|
||||||
|
|
||||||
####################
|
|
||||||
# Make sure while loops don't run forever with no-exec (#1543)
|
|
||||||
|
|
||||||
####################
|
|
||||||
# For loops with read-only vars is an error (#4342)
|
|
||||||
fish: You cannot use read-only variable 'status' in a for loop
|
|
||||||
for status in a b c
|
|
||||||
^
|
|
||||||
|
|
||||||
####################
|
|
||||||
# That goes for non-electric ones as well (#5548)
|
|
||||||
fish: You cannot use read-only variable 'hostname' in a for loop
|
|
||||||
for hostname in a b c
|
|
||||||
^
|
|
||||||
|
|
||||||
####################
|
|
||||||
# For loop control vars available outside the for block
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Comments allowed in between lines (#1987)
|
# Comments allowed in between lines (#1987)
|
||||||
|
|
||||||
|
|
|
@ -138,49 +138,6 @@ echo "/bin/echo pipe 10 <&10 10<&-" | source 10<&0
|
||||||
echo "/bin/echo pipe 11 <&11 11<&-" | source 11<&0
|
echo "/bin/echo pipe 11 <&11 11<&-" | source 11<&0
|
||||||
echo "/bin/echo pipe 12 <&12 12<&-" | source 12<&0
|
echo "/bin/echo pipe 12 <&12 12<&-" | source 12<&0
|
||||||
|
|
||||||
logmsg "Make sure while loops don't run forever with no-exec (#1543)"
|
|
||||||
echo "Checking for infinite loops in no-execute"
|
|
||||||
echo "while true; end" | ../test/root/bin/fish --no-execute
|
|
||||||
|
|
||||||
logmsg "For loops with read-only vars is an error (#4342)"
|
|
||||||
for status in a b c
|
|
||||||
echo $status
|
|
||||||
end
|
|
||||||
|
|
||||||
logmsg "That goes for non-electric ones as well (#5548)"
|
|
||||||
for hostname in a b c
|
|
||||||
echo $hostname
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
logmsg 'Comments allowed in between lines (#1987)'
|
logmsg 'Comments allowed in between lines (#1987)'
|
||||||
echo before comment \
|
echo before comment \
|
||||||
# comment
|
# comment
|
||||||
|
|
|
@ -75,46 +75,6 @@ pipe 10
|
||||||
pipe 11
|
pipe 11
|
||||||
pipe 12
|
pipe 12
|
||||||
|
|
||||||
####################
|
|
||||||
# Make sure while loops don't run forever with no-exec (#1543)
|
|
||||||
Checking for infinite loops in no-execute
|
|
||||||
|
|
||||||
####################
|
|
||||||
# For loops with read-only vars is an error (#4342)
|
|
||||||
|
|
||||||
####################
|
|
||||||
# That goes for non-electric ones as well (#5548)
|
|
||||||
|
|
||||||
####################
|
|
||||||
# For loop control vars available outside the for block
|
|
||||||
$loop_var: set in local scope, unexported, with 1 elements
|
|
||||||
$loop_var[1]: length=1 value=|c|
|
|
||||||
$loop_var: not set in global scope
|
|
||||||
$loop_var: not set in universal scope
|
|
||||||
|
|
||||||
$loop_var: set in local scope, unexported, with 1 elements
|
|
||||||
$loop_var[1]: length=1 value=|b|
|
|
||||||
$loop_var: set in global scope, unexported, with 1 elements
|
|
||||||
$loop_var[1]: length=10 value=|global_val|
|
|
||||||
$loop_var: not set in universal scope
|
|
||||||
|
|
||||||
$loop_var: not set in local scope
|
|
||||||
$loop_var: set in global scope, unexported, with 1 elements
|
|
||||||
$loop_var[1]: length=10 value=|global_val|
|
|
||||||
$loop_var: not set in universal scope
|
|
||||||
|
|
||||||
$loop_var: set in local scope, unexported, with 1 elements
|
|
||||||
$loop_var[1]: length=2 value=|cc|
|
|
||||||
$loop_var: set in global scope, unexported, with 1 elements
|
|
||||||
$loop_var[1]: length=10 value=|global_val|
|
|
||||||
$loop_var: not set in universal scope
|
|
||||||
|
|
||||||
$loop_var: not set in local scope
|
|
||||||
$loop_var: set in global scope, unexported, with 1 elements
|
|
||||||
$loop_var[1]: length=10 value=|global_val|
|
|
||||||
$loop_var: not set in universal scope
|
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Comments allowed in between lines (#1987)
|
# Comments allowed in between lines (#1987)
|
||||||
before comment after comment
|
before comment after comment
|
||||||
|
|
Loading…
Reference in New Issue
Block a user