[07/12] t5520: replace test -{n,z} with test-lib functions
diff mbox series

Message ID d6b74c5e58d9a45ca8b915ba699cafe08f300723.1571354136.git.liu.denton@gmail.com
State New
Headers show
Series
  • t5520: various test cleanup
Related show

Commit Message

Denton Liu Oct. 17, 2019, 11:17 p.m. UTC
Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Eric Sunshine Oct. 17, 2019, 11:31 p.m. UTC | #1
On Thu, Oct 17, 2019 at 7:17 PM Denton Liu <liu.denton@gmail.com> wrote:
> Instead of using `test -n` or `test -z`, replace them respectively with
> invocations of test_file_not_empty() and test_must_be_empty().
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> @@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
> -       test -z "$(git ls-files -u)" &&
> +       git ls-files -u >unmerged &&
> +       test_must_be_empty unmerged &&

A better justification for these change (and all others in this patch)
is that the original threw away the exit code of the "git ls-files -u"
invocation, whereas the new code takes the exit code into account. The
commit message perhaps instead ought to focus on that benefit.

Patch
diff mbox series

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 9452779f40..c7797b13e6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -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
 	)
 '