git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 8/8] tests: use "test_cmp_cmd" in misc tests

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Dec 2, 2022, 00:06 UTC
Message-ID
<patch-v2-8.8-979a7f003f8-20221202T000227Z-avarab@gmail.com>
In-Reply-To
<cover-v2-0.8-00000000000-20221202T000227Z-avarab@gmail.com>

Change a few miscellaneous tests to use "test_cmp_cmd" to avoid losing the exit code of "git".

There's many offenders left that match patterns like:
	/test .*\$\((test-tool|git)/

What these all have in common is that they were the rare odd cases out in test files that were otherwise consistently checking the exit code.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1401-symbolic-ref.sh            | 3 ++-
 t/t2005-checkout-index-symlinks.sh | 2 +-
 t/t3701-add-interactive.sh         | 9 ++++++---
 t/t5522-pull-symlink.sh            | 2 +-
 t/t7402-submodule-rebase.sh        | 4 ++--
 t/t7504-commit-msg-hook.sh         | 2 +-
 t/t7516-commit-races.sh            | 3 ++-
 t/t7810-grep.sh                    | 2 +-
 8 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
index d708acdb819..5e36899d207 100755
--- a/t/t1401-symbolic-ref.sh
+++ b/t/t1401-symbolic-ref.sh
@@ -33,7 +33,8 @@ test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
 reset_to_sane
 
 test_expect_success 'symbolic-ref refuses bare sha1' '
-	test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
+	rev=$(git rev-parse HEAD) &&
+	test_must_fail git symbolic-ref HEAD "$rev"
 '
 
 reset_to_sane
diff --git a/t/t2005-checkout-index-symlinks.sh b/t/t2005-checkout-index-symlinks.sh
index 112682a45a1..aee80d39221 100755
--- a/t/t2005-checkout-index-symlinks.sh
+++ b/t/t2005-checkout-index-symlinks.sh
@@ -24,6 +24,6 @@ test -f symlink'
 
 test_expect_success \
 'the file must be the blob we added during the setup' '
-test "$(git hash-object -t blob symlink)" = $l'
+test_cmp_cmd "$l" git hash-object -t blob symlink'
 
 test_done
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 5841f280fb2..3e59ffd18a0 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -296,9 +296,12 @@ test_expect_success FILEMODE 'stage mode and hunk' '
 	echo content >>file &&
 	chmod +x file &&
 	printf "y\\ny\\n" | git add -p &&
-	git diff --cached file | grep "new mode" &&
-	git diff --cached file | grep "+content" &&
-	test -z "$(git diff file)"
+	git diff --cached file >out &&
+	grep "new mode" <out &&
+	git diff --cached file >out &&
+	grep "+content" <out &&
+	git diff file >out &&
+	test_must_be_empty out
 '
 
 # end of tests disabled when filemode is not usable
diff --git a/t/t5522-pull-symlink.sh b/t/t5522-pull-symlink.sh
index bcff460d0a2..b36dd40e34e 100755
--- a/t/t5522-pull-symlink.sh
+++ b/t/t5522-pull-symlink.sh
@@ -78,7 +78,7 @@ test_expect_success SYMLINKS 'pushing from symlinked subdir' '
 		git commit -m push ./file &&
 		git push
 	) &&
-	test push = $(git show HEAD:subdir/file)
+	test_cmp_cmd push git show HEAD:subdir/file
 '
 
 test_done
diff --git a/t/t7402-submodule-rebase.sh b/t/t7402-submodule-rebase.sh
index 277bb8ae520..b27d8da69ee 100755
--- a/t/t7402-submodule-rebase.sh
+++ b/t/t7402-submodule-rebase.sh
@@ -55,11 +55,11 @@ chmod a+x fake-editor.sh
 
 test_expect_success 'interactive rebase with a dirty submodule' '
 
-	test submodule = $(git diff --name-only) &&
+	test_cmp_cmd submodule git diff --name-only &&
 	HEAD=$(git rev-parse HEAD) &&
 	GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
 		git rebase -i HEAD^ &&
-	test submodule = $(git diff --name-only)
+	test_cmp_cmd submodule git diff --name-only
 
 '
 
diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh
index a39de8c1126..2b94237f9d1 100755
--- a/t/t7504-commit-msg-hook.sh
+++ b/t/t7504-commit-msg-hook.sh
@@ -101,7 +101,7 @@ test_expect_success 'setup: commit-msg hook that always fails' '
 '
 
 commit_msg_is () {
-	test "$(git log --pretty=format:%s%b -1)" = "$1"
+	test_cmp_cmd "$1" git log --pretty=tformat:%s%b -1
 }
 
 test_expect_success 'with failing hook' '
diff --git a/t/t7516-commit-races.sh b/t/t7516-commit-races.sh
index f2ce14e9071..2d38a16480e 100755
--- a/t/t7516-commit-races.sh
+++ b/t/t7516-commit-races.sh
@@ -10,7 +10,8 @@ test_expect_success 'race to create orphan commit' '
 	test_must_fail env EDITOR=./hare-editor git commit --allow-empty -m tortoise -e &&
 	git show -s --pretty=format:%s >subject &&
 	grep hare subject &&
-	test -z "$(git show -s --pretty=format:%P)"
+	git show -s --pretty=format:%P >out &&
+	test_must_be_empty out
 '
 
 test_expect_success 'race to create non-orphan commit' '
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 8eded6ab274..232b041b0cf 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -1001,7 +1001,7 @@ test_expect_success 'log --committer does not search in timestamp' '
 test_expect_success 'grep with CE_VALID file' '
 	git update-index --assume-unchanged t/t &&
 	rm t/t &&
-	test "$(git grep test)" = "t/t:test" &&
+	test_cmp_cmd "t/t:test" git grep test &&
 	git update-index --no-assume-unchanged t/t &&
 	git checkout t/t
 '
-- 
2.39.0.rc1.980.g92d3d4579ad
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 35 of 83 in “tests: fix ignored & hidden exit codes”
  1. 0/6 tests: fix ignored & hidden exit codesÆvar Arnfjörð Bjarmason, Jul 21, 2022
  2. 1/6 diff tests: fix ignored exit codes in t4023Ævar Arnfjörð Bjarmason, Jul 21, 2022
  3. 2/6 t/lib-patch-mode.sh: fix ignored "git" exit codesÆvar Arnfjörð Bjarmason, Jul 21, 2022
  4. 3/6 auto-crlf tests: check "git checkout" exit codeÆvar Arnfjörð Bjarmason, Jul 21, 2022
  5. 4/6 test-lib-functions: add and use test_cmp_cmdÆvar Arnfjörð Bjarmason, Jul 21, 2022
  6. 5/6 merge tests: don't ignore "rev-parse" exit code in helperÆvar Arnfjörð Bjarmason, Jul 21, 2022
  7. 6/6 log tests: don't use "exit 1" outside a sub-shellÆvar Arnfjörð Bjarmason, Jul 21, 2022
  8. 0/8 tests: fix ignored & hidden exit codesÆvar Arnfjörð Bjarmason, Dec 2, 2022
  9. 1/8 log tests: don't use "exit 1" outside a sub-shellÆvar Arnfjörð Bjarmason, Dec 2, 2022
  10. Eric SunshineDec 2, 2022
  11. Junio C HamanoDec 2, 2022
  12. Ævar Arnfjörð BjarmasonDec 2, 2022
  13. Eric SunshineDec 2, 2022
  14. Ævar Arnfjörð BjarmasonDec 2, 2022
  15. Eric SunshineDec 7, 2022
  16. Junio C HamanoDec 2, 2022
  17. 2/8 auto-crlf tests: check "git checkout" exit codeÆvar Arnfjörð Bjarmason, Dec 2, 2022
  18. René ScharfeDec 2, 2022
  19. Eric SunshineDec 2, 2022
  20. Torsten BögershausenDec 2, 2022
  21. Eric SunshineDec 2, 2022
  22. 3/8 diff tests: fix ignored exit codes in t4023Ævar Arnfjörð Bjarmason, Dec 2, 2022
  23. Junio C HamanoDec 2, 2022
  24. 5/8 t/lib-patch-mode.sh: fix ignored "git" exit codesÆvar Arnfjörð Bjarmason, Dec 2, 2022
  25. René ScharfeDec 2, 2022
  26. 4/8 test-lib-functions: add and use test_cmp_cmdÆvar Arnfjörð Bjarmason, Dec 2, 2022
  27. René ScharfeDec 2, 2022
  28. Eric SunshineDec 2, 2022
  29. Eric SunshineDec 2, 2022
  30. Eric SunshineDec 2, 2022
  31. Junio C HamanoDec 2, 2022
  32. 6/8 merge tests: don't ignore "rev-parse" exit code in helperÆvar Arnfjörð Bjarmason, Dec 2, 2022
  33. René ScharfeDec 2, 2022
  34. 7/8 tests: use "test_cmp_cmd" instead of "test" in sub-shellsÆvar Arnfjörð Bjarmason, Dec 2, 2022
  35. 8/8 tests: use "test_cmp_cmd" in misc testsÆvar Arnfjörð Bjarmason, Dec 2, 2022
  36. Junio C HamanoDec 2, 2022
  37. 0/8 tests: fix ignored & hidden exit codesÆvar Arnfjörð Bjarmason, Dec 2, 2022
  38. 1/8 merge tests: don't ignore "rev-parse" exit code in helperÆvar Arnfjörð Bjarmason, Dec 2, 2022
  39. Junio C HamanoDec 5, 2022
  40. 2/8 auto-crlf tests: don't lose exit code in loops and outside testsÆvar Arnfjörð Bjarmason, Dec 2, 2022
  41. René ScharfeDec 2, 2022
  42. 3/8 diff tests: fix ignored exit codes in t4023Ævar Arnfjörð Bjarmason, Dec 2, 2022
  43. Junio C HamanoDec 5, 2022
  44. 4/8 t/lib-patch-mode.sh: fix ignored exit codesÆvar Arnfjörð Bjarmason, Dec 2, 2022
  45. René ScharfeDec 2, 2022
  46. Eric SunshineDec 4, 2022
  47. 5/8 tests: use "test_cmp" instead of "test" in sub-shellsÆvar Arnfjörð Bjarmason, Dec 2, 2022
  48. Junio C HamanoDec 5, 2022
  49. 7/8 tests: don't lose "git" exit codes in "! ( git ... | grep )"Ævar Arnfjörð Bjarmason, Dec 2, 2022
  50. René ScharfeDec 2, 2022
  51. 6/8 tests: don't lose 'test <str> = $(cmd ...)"' exit codeÆvar Arnfjörð Bjarmason, Dec 2, 2022
  52. 8/8 tests: don't lose mist "git" exit codesÆvar Arnfjörð Bjarmason, Dec 2, 2022
  53. Eric SunshineDec 4, 2022
  54. Junio C HamanoDec 5, 2022
  55. 0/6 tests: fix ignored & hidden exit codesÆvar Arnfjörð Bjarmason, Dec 19, 2022
  56. 1/6 auto-crlf tests: don't lose exit code in loops and outside testsÆvar Arnfjörð Bjarmason, Dec 19, 2022
  57. René ScharfeDec 19, 2022
  58. 2/6 t/lib-patch-mode.sh: fix ignored exit codesÆvar Arnfjörð Bjarmason, Dec 19, 2022
  59. Junio C HamanoDec 20, 2022
  60. Phillip WoodDec 27, 2022
  61. Ævar Arnfjörð BjarmasonDec 27, 2022
  62. 3/6 tests: don't lose exit status with "(cd ...; test <op> $(git ...))"Ævar Arnfjörð Bjarmason, Dec 19, 2022
  63. Junio C HamanoDec 20, 2022
  64. 4/6 tests: don't lose exit status with "test <op> $(git ...)"Ævar Arnfjörð Bjarmason, Dec 19, 2022
  65. Junio C HamanoDec 26, 2022
  66. 5/6 tests: don't lose "git" exit codes in "! ( git ... | grep )"Ævar Arnfjörð Bjarmason, Dec 19, 2022
  67. Junio C HamanoDec 26, 2022
  68. Phillip WoodDec 27, 2022
  69. Phillip WoodDec 27, 2022
  70. Junio C HamanoDec 27, 2022
  71. 6/6 tests: don't lose misc "git" exit codesÆvar Arnfjörð Bjarmason, Dec 19, 2022
  72. Phillip WoodDec 27, 2022
  73. Ævar Arnfjörð BjarmasonDec 27, 2022
  74. Junio C HamanoDec 27, 2022
  75. Junio C HamanoDec 20, 2022
  76. 0/6 tests: fix ignored & hidden exit codesÆvar Arnfjörð Bjarmason, Feb 6, 2023
  77. 1/6 auto-crlf tests: don't lose exit code in loops and outside testsÆvar Arnfjörð Bjarmason, Feb 6, 2023
  78. 2/6 t/lib-patch-mode.sh: fix ignored exit codesÆvar Arnfjörð Bjarmason, Feb 6, 2023
  79. 3/6 tests: don't lose exit status with "(cd ...; test <op> $(git ...))"Ævar Arnfjörð Bjarmason, Feb 6, 2023
  80. 5/6 tests: don't lose "git" exit codes in "! ( git ... | grep )"Ævar Arnfjörð Bjarmason, Feb 6, 2023
  81. 4/6 tests: don't lose exit status with "test <op> $(git ...)"Ævar Arnfjörð Bjarmason, Feb 6, 2023
  82. 6/6 tests: don't lose misc "git" exit codesÆvar Arnfjörð Bjarmason, Feb 6, 2023
  83. Junio C HamanoFeb 6, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.