tests: don't lose "git" exit codes in "! ( git ... | grep )"

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 6, 2023 at 23:44 UTC c7e03b4e39d40b431764797d3a792169cd375705
2 files changed +25 -7
t/t0055-beyond-symlinks.sh
+12 -2
@@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup '
15
16 test_expect_success SYMLINKS 'update-index --add beyond symlinks' '
17 test_must_fail git update-index --add c/d &&
18 - ! ( git ls-files | grep c/d )
18 + cat >expect <<-\EOF &&
19 + a
20 + b/d
21 + EOF
22 + git ls-files >actual &&
23 + test_cmp expect actual
24 '
25
26 test_expect_success SYMLINKS 'add beyond symlinks' '
27 test_must_fail git add c/d &&
23 - ! ( git ls-files | grep c/d )
28 + cat >expect <<-\EOF &&
29 + a
30 + b/d
31 + EOF
32 + git ls-files >actual &&
33 + test_cmp expect actual
34 '
35
36 test_done
t/t3700-add.sh
+13 -5
@@ -106,24 +106,32 @@ test_expect_success '.gitignore test setup' '
106
107 test_expect_success '.gitignore is honored' '
108 git add . &&
109 - ! (git ls-files | grep "\\.ig")
109 + git ls-files >files &&
110 + sed -n "/\\.ig/p" <files >actual &&
111 + test_must_be_empty actual
112 '
113
114 test_expect_success 'error out when attempting to add ignored ones without -f' '
115 test_must_fail git add a.?? &&
114 - ! (git ls-files | grep "\\.ig")
116 + git ls-files >files &&
117 + sed -n "/\\.ig/p" <files >actual &&
118 + test_must_be_empty actual
119 '
120
121 test_expect_success 'error out when attempting to add ignored ones without -f' '
122 test_must_fail git add d.?? &&
119 - ! (git ls-files | grep "\\.ig")
123 + git ls-files >files &&
124 + sed -n "/\\.ig/p" <files >actual &&
125 + test_must_be_empty actual
126 '
127
128 test_expect_success 'error out when attempting to add ignored ones but add others' '
129 touch a.if &&
130 test_must_fail git add a.?? &&
125 - ! (git ls-files | grep "\\.ig") &&
126 - (git ls-files | grep a.if)
131 + git ls-files >files &&
132 + sed -n "/\\.ig/p" <files >actual &&
133 + test_must_be_empty actual &&
134 + grep a.if files
135 '
136
137 test_expect_success 'add ignored ones with -f' '