From 5e6c9508e93e60ce2b6f4298bdde373efc92ba7e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 8 Feb 2020 17:45:22 +0100 Subject: [PATCH] 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 --- tests/checks/loops.fish | 94 ++++++++++++++++++++++++++++++++++++----- tests/test1.err | 18 -------- tests/test1.in | 43 ------------------- tests/test1.out | 40 ------------------ 4 files changed, 84 insertions(+), 111 deletions(-) diff --git a/tests/checks/loops.fish b/tests/checks/loops.fish index 5b21ed1b7..9342c463e 100644 --- a/tests/checks/loops.fish +++ b/tests/checks/loops.fish @@ -1,4 +1,4 @@ -#RUN: %fish %s +#RUN: %fish -C 'set -g fish %fish' %s function never_runs while false @@ -36,11 +36,11 @@ function set_status ; return $argv[1]; end # loop body. set_status 36 while begin - set -l saved $status - echo "Condition Status: $status" - set_status $saved - end - true + set -l saved $status + echo "Condition Status: $status" + set_status $saved +end +true end #CHECK: Condition Status: 36 @@ -81,12 +81,86 @@ echo "Empty Loop Status: $status" # Loop control in conditions, should have no output. for i in 1 2 3 - while break; end - echo $i + while break; end + echo $i end for i in 1 2 3 - while continue; end - echo $i + while continue; end + echo $i 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 diff --git a/tests/test1.err b/tests/test1.err index ee269e5a2..0c81bfb90 100644 --- a/tests/test1.err +++ b/tests/test1.err @@ -26,24 +26,6 @@ #################### # 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) diff --git a/tests/test1.in b/tests/test1.in index 2d1b81009..8013c09f0 100644 --- a/tests/test1.in +++ b/tests/test1.in @@ -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 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)' echo before comment \ # comment diff --git a/tests/test1.out b/tests/test1.out index 7e01503c8..ee2d0a047 100644 --- a/tests/test1.out +++ b/tests/test1.out @@ -75,46 +75,6 @@ pipe 10 pipe 11 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) before comment after comment