]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t1020: avoid aborting entire test script when one test fails
authorEric Sunshine <sunshine@sunshineco.com>
Thu, 9 Dec 2021 05:10:59 +0000 (00:10 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 18:29:48 +0000 (10:29 -0800)
Although `exit 1` is the proper way to signal a test failure from within
a subshell, its use outside any subshell should be avoided since it
aborts the entire script rather than aborting only the failed test.
Instead, a simple `return 1` is the proper idiom for signaling failure
outside a subshell since it aborts only the test in question, not the
entire script.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1020-subdirectory.sh

index c2df75e4953d897acee5cf590b9c358e5a0b77c2..da19c06fb5a7302cb41cc32b3f41baed5b5f6484 100755 (executable)
@@ -22,7 +22,7 @@ test_expect_success 'update-index and ls-files' '
        git update-index --add one &&
        case "$(git ls-files)" in
        one) echo pass one ;;
-       *) echo bad one; exit 1 ;;
+       *) echo bad one; return 1 ;;
        esac &&
        (
                cd dir &&
@@ -34,7 +34,7 @@ test_expect_success 'update-index and ls-files' '
        ) &&
        case "$(git ls-files)" in
        dir/two"$LF"one) echo pass both ;;
-       *) echo bad; exit 1 ;;
+       *) echo bad; return 1 ;;
        esac
 '
 
@@ -57,7 +57,7 @@ test_expect_success 'diff-files' '
        echo d >>dir/two &&
        case "$(git diff-files --name-only)" in
        dir/two"$LF"one) echo pass top ;;
-       *) echo bad top; exit 1 ;;
+       *) echo bad top; return 1 ;;
        esac &&
        # diff should not omit leading paths
        (