Skip to content

Commit

Permalink
[spec/loop] Add test case for multi-level continue.
Browse files Browse the repository at this point in the history
Part of #1459.

Didn't realize this worked.
  • Loading branch information
Andy C committed Jan 22, 2023
1 parent e4b9620 commit 62cfd7c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
12 changes: 11 additions & 1 deletion benchmarks/gc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,17 @@ gc-run-big() {
# This hit the 24-bit object ID limitation in 2.5 seconds
# Should be able to run indefinitely.
run-for-a-long-time() {
time _OIL_GC_VERBOSE=1 OIL_GC_STATS=1 _bin/cxx-opt/oils_cpp benchmarks/compute/fib.sh 10000
time _OIL_GC_VERBOSE=1 OIL_GC_STATS=1 _bin/cxx-opt/osh benchmarks/compute/fib.sh 10000
}

run-loop() {
ninja _bin/cxx-dbg/osh
time _OIL_GC_VERBOSE=1 OIL_GC_STATS=1 _bin/cxx-dbg/osh -c '
for x in $(seq 1000); do
echo $x
continue # make sure it does GC
done
'
}

"$@"
36 changes: 36 additions & 0 deletions spec/loop.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,39 @@ echo "$counterB"
99
50
## END


#### multi-level continue

for i in 1 2; do
for j in a b c; do
if test $j = b; then
continue
fi
echo $i $j
done
done

echo ---

for i in 1 2; do
for j in a b c; do
if test $j = b; then
continue 2 # MULTI-LEVEL
fi
echo $i $j
done
done


## STDOUT:
1 a
1 c
2 a
2 c
---
1 a
2 a
## END


2 changes: 1 addition & 1 deletion test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ quote() {
}

loop() {
sh-spec spec/loop.test.sh --osh-failures-allowed 1 \
sh-spec spec/loop.test.sh --osh-failures-allowed 2 \
${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
}

Expand Down

0 comments on commit 62cfd7c

Please sign in to comment.