]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t4000-t4999: detect and signal failure within loop
authorEric Sunshine <sunshine@sunshineco.com>
Thu, 9 Dec 2021 05:11:13 +0000 (00:11 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 18:29:48 +0000 (10:29 -0800)
Failures within `for` and `while` loops can go unnoticed if not detected
and signaled manually since the loop itself does not abort when a
contained command fails, nor will a failure necessarily be detected when
the loop finishes since the loop returns the exit code of the last
command it ran on the final iteration, which may not be the command
which failed. Therefore, detect and signal failures manually within
loops using the idiom `|| return 1` (or `|| exit 1` within subshells).

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
16 files changed:
t/t4001-diff-rename.sh
t/t4012-diff-binary.sh
t/t4014-format-patch.sh
t/t4015-diff-whitespace.sh
t/t4018-diff-funcname.sh
t/t4024-diff-optimize-common.sh
t/t4038-diff-combined.sh
t/t4046-diff-unmerged.sh
t/t4049-diff-stat-count.sh
t/t4052-stat-output.sh
t/t4057-diff-combined-paths.sh
t/t4124-apply-ws-rule.sh
t/t4138-apply-ws-expansion.sh
t/t4205-log-pretty-formats.sh
t/t4211-line-log.sh
t/t4216-log-bloom.sh

index 68f2ebca58a3213fa438a792510efab84d71871a..3dc90470446dbb81e9c9421dbc7c21d3648d91f4 100755 (executable)
@@ -174,7 +174,7 @@ test_expect_success 'setup for many rename source candidates' '
        do
                for j in 0 1 2 3 4 5 6 7 8 9;
                do
-                       echo "$i$j" >"path$i$j"
+                       echo "$i$j" >"path$i$j" || return 1
                done
        done &&
        git add "path??" &&
index 33ff588ebca03807da91c4a786df76c03fb9bff7..b0f16ff5c05b493335c9494a277d487e58ed3170 100755 (executable)
@@ -122,7 +122,7 @@ test_expect_success 'diff --stat with binary files and big change count' '
        i=0 &&
        while test $i -lt 10000; do
                echo $i &&
-               i=$(($i + 1))
+               i=$(($i + 1)) || return 1
        done >textfile &&
        git add textfile &&
        git diff --cached --stat binfile textfile >output &&
index eefe815fca8e31ef2f9010cbb4c4749ee365deb2..7dc5a5c736e3f2db0c4bc29c20321b6a386661df 100755 (executable)
@@ -325,7 +325,7 @@ test_expect_success 'filename length limit' '
                max=$(
                        for patch in 000[1-9]-*.patch
                        do
-                               echo "$patch" | wc -c
+                               echo "$patch" | wc -c || exit 1
                        done |
                        sort -nr |
                        head -n 1
@@ -343,7 +343,7 @@ test_expect_success 'filename length limit from config' '
                max=$(
                        for patch in 000[1-9]-*.patch
                        do
-                               echo "$patch" | wc -c
+                               echo "$patch" | wc -c || exit 1
                        done |
                        sort -nr |
                        head -n 1
@@ -361,7 +361,7 @@ test_expect_success 'filename limit applies only to basename' '
                max=$(
                        for patch in patches/000[1-9]-*.patch
                        do
-                               echo "${patch#patches/}" | wc -c
+                               echo "${patch#patches/}" | wc -c || exit 1
                        done |
                        sort -nr |
                        head -n 1
index 2c13b62d3c654807b85307748c1ec52b6f4155ff..ca5adabe14a13e7590213a1e7f199f14068a06b3 100755 (executable)
@@ -843,7 +843,7 @@ test_expect_success 'whitespace changes with modification reported (diffstat)' '
 
 test_expect_success 'whitespace-only changes reported across renames (diffstat)' '
        git reset --hard &&
-       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
+       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x &&
        git add x &&
        git commit -m "base" &&
        sed -e "5s/^/ /" x >z &&
@@ -859,7 +859,7 @@ test_expect_success 'whitespace-only changes reported across renames (diffstat)'
 
 test_expect_success 'whitespace-only changes reported across renames' '
        git reset --hard HEAD~1 &&
-       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
+       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x &&
        git add x &&
        hash_x=$(git hash-object x) &&
        before=$(git rev-parse --short "$hash_x") &&
index 740696c8f7f2c437ce9260ed30e4ba2b563a30ab..42a2b9a13b7a5bd6cf28cfbe9bbfb9a5a3e5f3e6 100755 (executable)
@@ -75,7 +75,7 @@ test_expect_success 'last regexp must not be negated' '
 test_expect_success 'setup hunk header tests' '
        for i in $diffpatterns
        do
-               echo "$i-* diff=$i"
+               echo "$i-* diff=$i" || return 1
        done > .gitattributes &&
 
        # add all test files to the index
index 6b44ce14933f8ceaa7e5e93eb9eaa0ff2527b66c..b98ac0a0c039c048a3f6413c4389617396b8fe26 100755 (executable)
@@ -148,7 +148,7 @@ test_expect_success 'diff -U0' '
 
        for n in $sample
        do
-               git diff -U0 file-?$n
+               git diff -U0 file-?$n || return 1
        done | zc >actual &&
        test_cmp expect actual
 
index aeac203c424905be395d5ef6d43f2b606dc3bb1d..9a292bac70c248c9273bf29a94d5ce39f17551df 100755 (executable)
@@ -100,7 +100,7 @@ test_expect_success 'setup for --cc --raw' '
        for i in $(test_seq 1 40)
        do
                blob=$(echo file$i | git hash-object --stdin -w) &&
-               trees="$trees$(echo "100644 blob $blob  file" | git mktree)$LF"
+               trees="$trees$(echo "100644 blob $blob  file" | git mktree)$LF" || return 1
        done
 '
 
index 8c3d48e25703ed3d2f32abca9329893250cdde91..1828a72e0ba58c26fbf88d7a3e6657559e105119 100755 (executable)
@@ -37,7 +37,7 @@ test_expect_success 'diff-files -0' '
        for path in $paths
        do
                >"$path" &&
-               echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path"
+               echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" || return 1
        done >diff-files-0.expect &&
        git diff-files -0 >diff-files-0.actual &&
        test_cmp diff-files-0.expect diff-files-0.actual
@@ -50,7 +50,7 @@ test_expect_success 'diff-files -1' '
                echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" &&
                case "$path" in
                x??) echo ":100644 100644 $blob1 $ZERO_OID M    $path"
-               esac
+               esac || return 1
        done >diff-files-1.expect &&
        git diff-files -1 >diff-files-1.actual &&
        test_cmp diff-files-1.expect diff-files-1.actual
@@ -63,7 +63,7 @@ test_expect_success 'diff-files -2' '
                echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" &&
                case "$path" in
                ?x?) echo ":100644 100644 $blob2 $ZERO_OID M    $path"
-               esac
+               esac || return 1
        done >diff-files-2.expect &&
        git diff-files -2 >diff-files-2.actual &&
        test_cmp diff-files-2.expect diff-files-2.actual &&
@@ -78,7 +78,7 @@ test_expect_success 'diff-files -3' '
                echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" &&
                case "$path" in
                ??x) echo ":100644 100644 $blob3 $ZERO_OID M    $path"
-               esac
+               esac || return 1
        done >diff-files-3.expect &&
        git diff-files -3 >diff-files-3.actual &&
        test_cmp diff-files-3.expect diff-files-3.actual
index 53061b104ecc1af2eebb9d79fa2af5655236471d..e74baa0635dc96427492da5d012853a2c252344b 100755 (executable)
@@ -51,7 +51,7 @@ test_expect_success 'exclude unmerged entries from total file count' '
        git rm -f d &&
        for stage in 1 2 3
        do
-               sed -e "s/ 0    a/ $stage       d/" x
+               sed -e "s/ 0    a/ $stage       d/" x || return 1
        done |
        git update-index --index-info &&
        echo d >d &&
index 9eba436211f147864e0ce6afbcfa3166eedc0255..b5c281edaa7037097f3c8fad28c1bb1994607a20 100755 (executable)
@@ -101,7 +101,7 @@ test_expect_success 'preparation for big change tests' '
        i=0 &&
        while test $i -lt 1000
        do
-               echo $i && i=$(($i + 1))
+               echo $i && i=$(($i + 1)) || return 1
        done >abcd &&
        git commit -m message abcd
 '
index 7e5b74f72ee975ef87c8d5e539bc287268e18493..04b8a1542a8ec3ad2ffc28964f21940d034c2ed6 100755 (executable)
@@ -18,13 +18,13 @@ test_expect_success 'trivial merge - combine-diff empty' '
        for i in $(test_seq 1 9)
        do
                echo $i >$i.txt &&
-               git add $i.txt
+               git add $i.txt || return 1
        done &&
        git commit -m "init" &&
        git checkout -b side &&
        for i in $(test_seq 2 9)
        do
-               echo $i/2 >>$i.txt
+               echo $i/2 >>$i.txt || return 1
        done &&
        git commit -a -m "side 2-9" &&
        git checkout main &&
@@ -40,14 +40,14 @@ test_expect_success 'only one truly conflicting path' '
        git checkout side &&
        for i in $(test_seq 2 9)
        do
-               echo $i/3 >>$i.txt
+               echo $i/3 >>$i.txt || return 1
        done &&
        echo "4side" >>4.txt &&
        git commit -a -m "side 2-9 +4" &&
        git checkout main &&
        for i in $(test_seq 1 9)
        do
-               echo $i/3 >>$i.txt
+               echo $i/3 >>$i.txt || return 1
        done &&
        echo "4main" >>4.txt &&
        git commit -a -m "main 1-9 +4" &&
@@ -69,13 +69,13 @@ test_expect_success 'merge introduces new file' '
        git checkout side &&
        for i in $(test_seq 5 9)
        do
-               echo $i/4 >>$i.txt
+               echo $i/4 >>$i.txt || return 1
        done &&
        git commit -a -m "side 5-9" &&
        git checkout main &&
        for i in $(test_seq 1 3)
        do
-               echo $i/4 >>$i.txt
+               echo $i/4 >>$i.txt || return 1
        done &&
        git commit -a -m "main 1-3 +4hello" &&
        git merge side &&
@@ -90,13 +90,13 @@ test_expect_success 'merge removed a file' '
        git checkout side &&
        for i in $(test_seq 5 9)
        do
-               echo $i/5 >>$i.txt
+               echo $i/5 >>$i.txt || return 1
        done &&
        git commit -a -m "side 5-9" &&
        git checkout main &&
        for i in $(test_seq 1 3)
        do
-               echo $i/4 >>$i.txt
+               echo $i/4 >>$i.txt || return 1
        done &&
        git commit -a -m "main 1-3" &&
        git merge side &&
index ec5c10d2a0bd27f18d9de399d5128d24c9dacd11..485c7d2d124ade54d00f8752399be91f43eefbc8 100755 (executable)
@@ -333,7 +333,7 @@ test_expect_success 'applying beyond EOF requires one non-blank context line' '
 
 test_expect_success 'tons of blanks at EOF should not apply' '
        for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
-               test_write_lines "" "" "" ""
+               test_write_lines "" "" "" "" || return 1
        done >one &&
        git add one &&
        echo a >>one &&
@@ -396,7 +396,7 @@ test_expect_success 'shrink file with tons of missing blanks at end of file' '
        test_write_lines a b c >one &&
        cp one no-blank-lines &&
        for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
-               test_write_lines "" "" "" ""
+               test_write_lines "" "" "" "" || return 1
        done >>one &&
        git add one &&
        echo a >one &&
index 4ba52bbb61395208e67dfcae5a3e3792c329b9ae..8bbf8260fa6b982e82f3ecb1e41d81f08adb9f4b 100755 (executable)
@@ -30,7 +30,7 @@ test_expect_success setup '
        while test $x -lt $n
        do
                printf "%63s%d\n" "" $x >>after &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "\t%s\n" d e f >>after &&
        test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
@@ -41,7 +41,7 @@ test_expect_success setup '
        while test $x -lt $n
        do
                printf "%63s%d\n" "" $x >>expect-2 &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "%64s\n" d e f >>expect-2 &&
 
@@ -53,7 +53,7 @@ test_expect_success setup '
        while test $x -lt $n
        do
                printf "%63s%02d\n" "" $x >>after &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "\t%s\n" d e f >>after &&
        test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
@@ -64,7 +64,7 @@ test_expect_success setup '
        while test $x -lt $n
        do
                printf "%63s%02d\n" "" $x >>expect-3 &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "%64s\n" d e f >>expect-3 &&
 
@@ -74,7 +74,7 @@ test_expect_success setup '
        while test $x -lt 50
        do
                printf "\t%02d\n" $x >>before &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
        cat before >after &&
        printf "%64s\n" a b c >>after &&
@@ -82,7 +82,7 @@ test_expect_success setup '
        do
                printf "\t%02d\n" $x >>before &&
                printf "\t%02d\n" $x >>after &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
        test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
        sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
@@ -91,7 +91,7 @@ test_expect_success setup '
        while test $x -lt 50
        do
                printf "%63s%02d\n" "" $x >>test-4 &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
        cat test-4 >expect-4 &&
        printf "%64s\n" a b c >>expect-4 &&
@@ -99,7 +99,7 @@ test_expect_success setup '
        do
                printf "%63s%02d\n" "" $x >>test-4 &&
                printf "%63s%02d\n" "" $x >>expect-4 &&
-               x=$(( $x + 1 ))
+               x=$(( $x + 1 )) || return 1
        done &&
 
        git config core.whitespace tab-in-indent,tabwidth=63 &&
index 5865daa8f8d2234f0379d25bda47d5d3142f3fc8..f4ce7c59a4cc63b7e5607aec91316ba6abf12cf9 100755 (executable)
@@ -976,7 +976,7 @@ test_expect_success '%(describe) vs git describe' '
                else
                        : >expect-contains-bad
                fi &&
-               echo "$hash $desc"
+               echo "$hash $desc" || return 1
        done >expect &&
        test_path_exists expect-contains-good &&
        test_path_exists expect-contains-bad &&
index 560127cc078ad09c7fd87e7d5dc0a4d65fcb22d3..ac9e4d0928593cd37b4a79e27f5fe99b6e4a3faf 100755 (executable)
@@ -137,7 +137,7 @@ test_expect_success 'range_set_union' '
        test_seq 1000 > c.c &&
        git add c.c &&
        git commit -m "modify many lines" &&
-       git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done)
+       git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c || return 1; done)
 '
 
 test_expect_success '-s shows only line-log commits' '
index 50f206db55043ff3481b4db4b23937b01bc43cab..41355f038b0dc2cfe991562cb698187dde8236e2 100755 (executable)
@@ -376,7 +376,7 @@ test_expect_success 'Bloom generation backfills empty commits' '
                cd empty &&
                for i in $(test_seq 1 6)
                do
-                       git commit --allow-empty -m "$i"
+                       git commit --allow-empty -m "$i" || return 1
                done &&
 
                # Generate Bloom filters for empty commits 1-6, two at a time.
@@ -389,7 +389,7 @@ test_expect_success 'Bloom generation backfills empty commits' '
                        test_filter_computed 2 trace.event &&
                        test_filter_not_computed 4 trace.event &&
                        test_filter_trunc_empty 2 trace.event &&
-                       test_filter_trunc_large 0 trace.event
+                       test_filter_trunc_large 0 trace.event || return 1
                done &&
 
                # Finally, make sure that once all commits have filters, that