mirror of
https://github.com/git/git
synced 2024-10-31 00:45:12 +00:00
fd4094c3ca
Shell `for` and `while` loops do not terminate automatically just because a command fails within the loop body. Instead, the loop continues to iterate and eventually returns the exit status of the final command of the final iteration, which may not be the command which failed, thus it is possible for failures to go undetected. Consequently, it is important for test authors to explicitly handle failure within the loop body by terminating the loop manually upon failure. This can be done by returning a non-zero exit code from within the loop body (i.e. `|| return 1`) or exiting (i.e. `|| exit 1`) if the loop is within a subshell, or by manually checking `$?` and taking some appropriate action. Therefore, add logic to detect and complain about loops which lack explicit `return` or `exit`, or `$?` check. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
31 lines
519 B
Text
31 lines
519 B
Text
for i in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
for j in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
echo "$i$j" > "path$i$j" ?!LOOP?!
|
|
done ?!LOOP?!
|
|
done &&
|
|
|
|
for i in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
for j in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
echo "$i$j" > "path$i$j" || return 1
|
|
done
|
|
done &&
|
|
|
|
for i in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
for j in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
echo "$i$j" > "path$i$j" ?!LOOP?!
|
|
done || return 1
|
|
done &&
|
|
|
|
for i in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
for j in 0 1 2 3 4 5 6 7 8 9 ;
|
|
do
|
|
echo "$i$j" > "path$i$j" || return 1
|
|
done || return 1
|
|
done
|