t6300: use function to test trailer options
Add a function to test trailer options. This will make tests look cleaner, as well as will make it easier to add new tests for trailers in the future. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Mentored-by: Heba Waly <heba.waly@gmail.com> Signed-off-by: Hariom Verma <hariom18599@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e6362826a0
commit
727331dce1
@ -814,53 +814,57 @@ test_expect_success 'set up trailers for next test' '
|
|||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '%(trailers:unfold) unfolds trailers' '
|
test_trailer_option () {
|
||||||
{
|
title=$1 option=$2
|
||||||
unfold <trailers
|
cat >expect
|
||||||
echo
|
test_expect_success "$title" '
|
||||||
} >expect &&
|
git for-each-ref --format="%($option)" refs/heads/main >actual &&
|
||||||
git for-each-ref --format="%(trailers:unfold)" refs/heads/main >actual &&
|
test_cmp expect actual &&
|
||||||
test_cmp expect actual &&
|
git for-each-ref --format="%(contents:$option)" refs/heads/main >actual &&
|
||||||
git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/main >actual &&
|
test_cmp expect actual
|
||||||
test_cmp expect actual
|
'
|
||||||
'
|
}
|
||||||
|
|
||||||
test_expect_success '%(trailers:only) shows only "key: value" trailers' '
|
test_trailer_option '%(trailers:unfold) unfolds trailers' \
|
||||||
{
|
'trailers:unfold' <<-EOF
|
||||||
grep -v patch.description <trailers &&
|
$(unfold <trailers)
|
||||||
echo
|
|
||||||
} >expect &&
|
|
||||||
git for-each-ref --format="%(trailers:only)" refs/heads/main >actual &&
|
|
||||||
test_cmp expect actual &&
|
|
||||||
git for-each-ref --format="%(contents:trailers:only)" refs/heads/main >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
|
EOF
|
||||||
{
|
|
||||||
grep -v patch.description <trailers | unfold &&
|
|
||||||
echo
|
|
||||||
} >expect &&
|
|
||||||
git for-each-ref --format="%(trailers:only,unfold)" refs/heads/main >actual &&
|
|
||||||
test_cmp expect actual &&
|
|
||||||
git for-each-ref --format="%(trailers:unfold,only)" refs/heads/main >actual &&
|
|
||||||
test_cmp actual actual &&
|
|
||||||
git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/main >actual &&
|
|
||||||
test_cmp expect actual &&
|
|
||||||
git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/main >actual &&
|
|
||||||
test_cmp actual actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success '%(trailers) rejects unknown trailers arguments' '
|
test_trailer_option '%(trailers:only) shows only "key: value" trailers' \
|
||||||
# error message cannot be checked under i18n
|
'trailers:only' <<-EOF
|
||||||
cat >expect <<-EOF &&
|
$(grep -v patch.description <trailers)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \
|
||||||
|
'trailers:only,unfold' <<-EOF
|
||||||
|
$(grep -v patch.description <trailers | unfold)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \
|
||||||
|
'trailers:unfold,only' <<-EOF
|
||||||
|
$(grep -v patch.description <trailers | unfold)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_failing_trailer_option () {
|
||||||
|
title=$1 option=$2
|
||||||
|
cat >expect
|
||||||
|
test_expect_success "$title" '
|
||||||
|
# error message cannot be checked under i18n
|
||||||
|
test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual &&
|
||||||
|
test_i18ncmp expect actual &&
|
||||||
|
test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual &&
|
||||||
|
test_i18ncmp expect actual
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \
|
||||||
|
'trailers:unsupported' <<-\EOF
|
||||||
fatal: unknown %(trailers) argument: unsupported
|
fatal: unknown %(trailers) argument: unsupported
|
||||||
EOF
|
EOF
|
||||||
test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
|
|
||||||
test_i18ncmp expect actual &&
|
|
||||||
test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
|
|
||||||
test_i18ncmp expect actual
|
|
||||||
'
|
|
||||||
|
|
||||||
test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
|
test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
|
||||||
cat >expect <<-EOF &&
|
cat >expect <<-EOF &&
|
||||||
|
Loading…
Reference in New Issue
Block a user