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

[PATCH v5 5/6] tests: don't lose "git" exit codes in "! ( git ... | grep )"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 6, 2023, 22:44 UTC
Message-ID
<patch-v5-5.6-55abdbef49f-20230206T224200Z-avarab@gmail.com>
In-Reply-To
<cover-v5-0.6-00000000000-20230206T224200Z-avarab@gmail.com>

Change tests that would lose the "git" exit code via a negation pattern to:

- In the case of "t0055-beyond-symlinks.sh" compare against the
  expected output instead.
  We could use the same pattern as in the "t3700-add.sh" below, doing
  so would have the advantage that if we added an earlier test we
  wouldn't need to adjust the "expect" output.
  But as "t0055-beyond-symlinks.sh" is a small and focused test (less
  than 40 lines in total) let's use "test_cmp" instead.
- For "t3700-add.sh" use "sed -n" to print the expected "bad" part,
  and use "test_must_be_empty" to assert that it's not there. If we used
  "grep" we'd get a non-zero exit code.
  We could use "test_expect_code 1 grep", but this is more consistent
  with existing patterns in the test suite.
  We can also remove a repeated invocation of "git ls-files" for the
  last test that's being modified in that file, and search the
  existing "files" output instead.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0055-beyond-symlinks.sh | 14 ++++++++++++--
 t/t3700-add.sh             | 18 +++++++++++++-----
 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/t/t0055-beyond-symlinks.sh b/t/t0055-beyond-symlinks.sh
index 6bada370225..c3eb1158ef9 100755
--- a/t/t0055-beyond-symlinks.sh
+++ b/t/t0055-beyond-symlinks.sh
@@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup '
 
 test_expect_success SYMLINKS 'update-index --add beyond symlinks' '
 	test_must_fail git update-index --add c/d &&
-	! ( git ls-files | grep c/d )
+	cat >expect <<-\EOF &&
+	a
+	b/d
+	EOF
+	git ls-files >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success SYMLINKS 'add beyond symlinks' '
 	test_must_fail git add c/d &&
-	! ( git ls-files | grep c/d )
+	cat >expect <<-\EOF &&
+	a
+	b/d
+	EOF
+	git ls-files >actual &&
+	test_cmp expect actual
 '
 
 test_done
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 51afbd7b24a..82dd768944f 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -106,24 +106,32 @@ test_expect_success '.gitignore test setup' '
 
 test_expect_success '.gitignore is honored' '
 	git add . &&
-	! (git ls-files | grep "\\.ig")
+	git ls-files >files &&
+	sed -n "/\\.ig/p" <files >actual &&
+	test_must_be_empty actual
 '
 
 test_expect_success 'error out when attempting to add ignored ones without -f' '
 	test_must_fail git add a.?? &&
-	! (git ls-files | grep "\\.ig")
+	git ls-files >files &&
+	sed -n "/\\.ig/p" <files >actual &&
+	test_must_be_empty actual
 '
 
 test_expect_success 'error out when attempting to add ignored ones without -f' '
 	test_must_fail git add d.?? &&
-	! (git ls-files | grep "\\.ig")
+	git ls-files >files &&
+	sed -n "/\\.ig/p" <files >actual &&
+	test_must_be_empty actual
 '
 
 test_expect_success 'error out when attempting to add ignored ones but add others' '
 	touch a.if &&
 	test_must_fail git add a.?? &&
-	! (git ls-files | grep "\\.ig") &&
-	(git ls-files | grep a.if)
+	git ls-files >files &&
+	sed -n "/\\.ig/p" <files >actual &&
+	test_must_be_empty actual &&
+	grep a.if files
 '
 
 test_expect_success 'add ignored ones with -f' '
-- 
2.39.1.1425.gac85d95d48c
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 80 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.