Skip to content

Commit c7e03b4

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0cd1a88 commit c7e03b4

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

t/t0055-beyond-symlinks.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup '
1515

1616
test_expect_success SYMLINKS 'update-index --add beyond symlinks' '
1717
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
1924
'
2025

2126
test_expect_success SYMLINKS 'add beyond symlinks' '
2227
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
2434
'
2535

2636
test_done

t/t3700-add.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,32 @@ test_expect_success '.gitignore test setup' '
106106

107107
test_expect_success '.gitignore is honored' '
108108
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
110112
'
111113

112114
test_expect_success 'error out when attempting to add ignored ones without -f' '
113115
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
115119
'
116120

117121
test_expect_success 'error out when attempting to add ignored ones without -f' '
118122
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
120126
'
121127

122128
test_expect_success 'error out when attempting to add ignored ones but add others' '
123129
touch a.if &&
124130
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
127135
'
128136

129137
test_expect_success 'add ignored ones with -f' '

0 commit comments

Comments
 (0)