]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5520: replace test -{n,z} with test-lib functions
authorDenton Liu <liu.denton@gmail.com>
Tue, 12 Nov 2019 23:08:02 +0000 (15:08 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Nov 2019 00:41:51 +0000 (09:41 +0900)
When wrapping a git command in a command substitution within another
command, we throw away the git command's exit code. In case the git
command fails, we would like to know about it rather than the failure
being silent. Extract git commands so that their exit codes are not
lost.

Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty() so that we
get better debugging information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5520-pull.sh

index 0ca4867e9683fe84e3019324b7781d6bb9a3bedf..18225d84306615cddff6806eb17bfa5d0e0bd740 100755 (executable)
@@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
        test_when_finished "git checkout -f copy && git branch -D third" &&
        test "$(cat file)" = file &&
        test_commit modified2 file &&
-       test -z "$(git ls-files -u)" &&
+       git ls-files -u >unmerged &&
+       test_must_be_empty unmerged &&
        test_must_fail git pull . second &&
-       test -n "$(git ls-files -u)" &&
+       git ls-files -u >unmerged &&
+       test_file_not_empty unmerged &&
        cp file expected &&
        test_must_fail git pull . second 2>err &&
        test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
        test_cmp expected file &&
        git add file &&
-       test -z "$(git ls-files -u)" &&
+       git ls-files -u >unmerged &&
+       test_must_be_empty unmerged &&
        test_must_fail git pull . second 2>err &&
        test_i18ngrep "You have not concluded your merge" err &&
        test_cmp expected file
@@ -667,7 +670,8 @@ test_expect_success 'git pull --rebase detects upstreamed changes' '
        (
                cd dst &&
                git pull --rebase &&
-               test -z "$(git ls-files -u)"
+               git ls-files -u >untracked &&
+               test_must_be_empty untracked
        )
 '