t4014: check for empty files from git format-patch --stdout
Most kinds of failure in 'git format-patch --stdout >output' will result in an empty 'output'. This slips past checks that only verify absence of output, such as the '! grep ...' that are quite prevalent in t4014. Introduce a helper check_patch() that checks that at least From, Date and Subject are present, thus making sure it looks vaguely like a patch (or cover letter) email. Then insert calls to it in all tests that do have positive checks for content. This makes two of the tests fail. Mark them as such; they'll be fixed in a moment. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Aug 29, 2011 at 22:10 UTC
cc663d141a2d900d097973a8fdcb939f697d46bd
1 file changed
+19
-2
t/t4014-format-patch.sh
+19
-2
@@ -179,12 +179,21 @@ test_expect_success 'configuration To: header' '
179
grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
180
'
181
182
+# check_patch <patch>: Verify that <patch> looks like a half-sane
183
+# patch email to avoid a false positive with !grep
184
+check_patch () {
185
+ grep -e "^From:" "$1" &&
186
+ grep -e "^Date:" "$1" &&
187
+ grep -e "^Subject:" "$1"
188
+}
189
+
190
test_expect_success '--no-to overrides config.to' '
191
192
git config --replace-all format.to \
193
"R. E. Cipient <rcipient@example.com>" &&
194
git format-patch --no-to --stdout master..side |
195
sed -e "/^\$/q" >patch10 &&
196
+ check_patch patch10 &&
197
! grep "^To: R. E. Cipient <rcipient@example.com>\$" patch10
198
'
199
@@ -195,6 +204,7 @@ test_expect_success '--no-to and --to replaces config.to' '
204
git format-patch --no-to --to="Someone Else <else@out.there>" \
205
--stdout master..side |
206
sed -e "/^\$/q" >patch11 &&
207
+ check_patch patch11 &&
208
! grep "^To: Someone <someone@out.there>\$" patch11 &&
209
grep "^To: Someone Else <else@out.there>\$" patch11
210
'
@@ -205,15 +215,17 @@ test_expect_success '--no-cc overrides config.cc' '
215
"C. E. Cipient <rcipient@example.com>" &&
216
git format-patch --no-cc --stdout master..side |
217
sed -e "/^\$/q" >patch12 &&
218
+ check_patch patch12 &&
219
! grep "^Cc: C. E. Cipient <rcipient@example.com>\$" patch12
220
'
221
211
-test_expect_success '--no-add-headers overrides config.headers' '
222
+test_expect_failure '--no-add-headers overrides config.headers' '
223
224
git config --replace-all format.headers \
225
"Header1: B. E. Cipient <rcipient@example.com>" &&
226
git format-patch --no-add-headers --stdout master..side |
227
sed -e "/^\$/q" >patch13 &&
228
+ check_patch patch13 &&
229
! grep "^Header1: B. E. Cipient <rcipient@example.com>\$" patch13
230
'
231
@@ -480,6 +492,7 @@ test_expect_success 'cover-letter inherits diff options' '
492
git mv file foo &&
493
git commit -m foo &&
494
git format-patch --cover-letter -1 &&
495
+ check_patch 0000-cover-letter.patch &&
496
! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
497
git format-patch --cover-letter -1 -M &&
498
grep "file => foo .* 0 *\$" 0000-cover-letter.patch
@@ -657,6 +670,7 @@ test_expect_success 'format-patch --no-signature ignores format.signature' '
670
git config format.signature "config sig" &&
671
git format-patch --stdout --signature="my sig" --no-signature \
672
-1 >output &&
673
+ check_patch output &&
674
! grep "config sig" output &&
675
! grep "my sig" output &&
676
! grep "^-- \$" output
@@ -673,17 +687,20 @@ test_expect_success 'format-patch --signature --cover-letter' '
687
test_expect_success 'format.signature="" supresses signatures' '
688
git config format.signature "" &&
689
git format-patch --stdout -1 >output &&
690
+ check_patch output &&
691
! grep "^-- \$" output
692
'
693
694
test_expect_success 'format-patch --no-signature supresses signatures' '
695
git config --unset-all format.signature &&
696
git format-patch --stdout --no-signature -1 >output &&
697
+ check_patch output &&
698
! grep "^-- \$" output
699
'
700
685
-test_expect_success 'format-patch --signature="" supresses signatures' '
701
+test_expect_failure 'format-patch --signature="" supresses signatures' '
702
git format-patch --signature="" -1 >output &&
703
+ check_patch output &&
704
! grep "^-- \$" output
705
'
706