t/t6300: introduce test_bad_atom
Introduce a new function "test_bad_atom", which is similar to "test_atom()" but should be used to check whether the correct error message is shown on stderr. Like "test_atom", the new function takes three arguments. The three arguments specify the ref, the format and the expected error message respectively, with an optional fourth argument for tweaking "test_expect_*" (which is by default "success"). Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Hariom Verma <hariom18599@gmail.com> Signed-off-by: Kousik Sanagavarapu <five231003@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kousik Sanagavarapu committed
Sep 25, 2023 at 23:13 UTC
0144f0de77edc96c6cd72ab9d50a68fc4c9c092e
1 file changed
+24
t/t6300-for-each-ref.sh
+24
@@ -271,6 +271,30 @@ test_expect_success 'arguments to %(objectname:short=) must be positive integers
271
test_must_fail git for-each-ref --format="%(objectname:short=foo)"
272
'
273
274
+test_bad_atom () {
275
+ case "$1" in
276
+ head) ref=refs/heads/main ;;
277
+ tag) ref=refs/tags/testtag ;;
278
+ sym) ref=refs/heads/sym ;;
279
+ *) ref=$1 ;;
280
+ esac
281
+ format=$2
282
+ test_do=test_expect_${4:-success}
283
+
284
+ printf '%s\n' "$3" >expect
285
+ $test_do $PREREQ "err basic atom: $ref $format" '
286
+ test_must_fail git for-each-ref \
287
+ --format="%($format)" "$ref" 2>error &&
288
+ test_cmp expect error
289
+ '
290
+}
291
+
292
+test_bad_atom head 'authoremail:foo' \
293
+ 'fatal: unrecognized %(authoremail) argument: foo'
294
+
295
+test_bad_atom tag 'taggeremail:localpart trim' \
296
+ 'fatal: unrecognized %(taggeremail) argument: localpart trim'
297
+
298
test_date () {
299
f=$1 &&
300
committer_date=$2 &&