mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
ee8ca246f8
This one tests a bunch of separate stuff, so we put it into a few different files. The main, new one is "slices.fish", which tests various index expressions.
92 lines
1.7 KiB
Fish
92 lines
1.7 KiB
Fish
#RUN: %fish %s
|
|
|
|
function never_runs
|
|
while false
|
|
end
|
|
end
|
|
|
|
function early_return
|
|
while true
|
|
return 2
|
|
end
|
|
end
|
|
|
|
function runs_once
|
|
set -l i 1
|
|
while test $i -ne 0 && set i (math $i - 1)
|
|
end
|
|
end
|
|
|
|
# this should return 0
|
|
never_runs; echo "Empty Loop in Function: $status"
|
|
#CHECK: Empty Loop in Function: 0
|
|
|
|
# this should return 0
|
|
runs_once; echo "Runs Once: $status"
|
|
#CHECK: Runs Once: 0
|
|
|
|
# this should return 2
|
|
early_return; echo "Early Return: $status"
|
|
#CHECK: Early Return: 2
|
|
|
|
function set_status ; return $argv[1]; end
|
|
|
|
# The previous status is visible in the loop condition.
|
|
# This includes both the incoming status, and the last command in the
|
|
# loop body.
|
|
set_status 36
|
|
while begin
|
|
set -l saved $status
|
|
echo "Condition Status: $status"
|
|
set_status $saved
|
|
end
|
|
true
|
|
end
|
|
#CHECK: Condition Status: 36
|
|
|
|
# The condition status IS visible in the loop body.
|
|
set_status 55
|
|
while true
|
|
echo "Body Status: $status"
|
|
break
|
|
end
|
|
#CHECK: Body Status: 0
|
|
|
|
# The status of the last command is visible in the loop condition
|
|
set_status 13
|
|
while begin
|
|
set -l saved $status
|
|
echo "Condition 2 Status: $saved"
|
|
test $saved -ne 5
|
|
end
|
|
set_status 5
|
|
end
|
|
#CHECK: Condition 2 Status: 13
|
|
#CHECK: Condition 2 Status: 5
|
|
|
|
# The status of the last command is visible outside the loop
|
|
set rem 5 7 11
|
|
while [ (count $rem) -gt 0 ]
|
|
set_status $rem[1]
|
|
set rem $rem[2..-1]
|
|
end
|
|
echo "Loop Exit Status: $status"
|
|
#CHECK: Loop Exit Status: 11
|
|
|
|
# Empty loops succeed.
|
|
false
|
|
while false; end
|
|
echo "Empty Loop Status: $status"
|
|
#CHECK: Empty Loop Status: 0
|
|
|
|
# Loop control in conditions, should have no output.
|
|
for i in 1 2 3
|
|
while break; end
|
|
echo $i
|
|
end
|
|
for i in 1 2 3
|
|
while continue; end
|
|
echo $i
|
|
end
|
|
|
|
if false ; or --help ; end
|