t/t6300: cleanup test_atom
Previously, when the executable part of "test_expect_{success,failure}" (inside "test_atom") got "eval"ed, it would have been syntactically incorrect if the second argument ($2, which is the format) to "test_atom" were enclosed in single quotes because the $variables would get interpolated even before the arguments to "test_expect_{success,failure}" are formed. So fix this and also some style issues along the way. Helped-by: Junio C Hamano <gitster@pobox.com> 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
04830eb762c83609a63805716daedb36014f6b6c
1 file changed
+10
-6
t/t6300-for-each-ref.sh
+10
-6
@@ -41,25 +41,29 @@ test_expect_success setup '
41
git config push.default current
42
'
43
44
-test_atom() {
44
+test_atom () {
45
case "$1" in
46
head) ref=refs/heads/main ;;
47
tag) ref=refs/tags/testtag ;;
48
sym) ref=refs/heads/sym ;;
49
*) ref=$1 ;;
50
esac
51
+ format=$2
52
+ test_do=test_expect_${4:-success}
53
+
54
printf '%s\n' "$3" >expected
52
- test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
53
- git for-each-ref --format='%($2)' $ref >actual &&
55
+ $test_do $PREREQ "basic atom: $ref $format" '
56
+ git for-each-ref --format="%($format)" "$ref" >actual &&
57
sanitize_pgp <actual >actual.clean &&
58
test_cmp expected actual.clean
56
- "
59
+ '
60
+
61
# Automatically test "contents:size" atom after testing "contents"
58
- if test "$2" = "contents"
62
+ if test "$format" = "contents"
63
then
64
# for commit leg, $3 is changed there
65
expect=$(printf '%s' "$3" | wc -c)
62
- test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" '
66
+ $test_do $PREREQ "basic atom: $ref contents:size" '
67
type=$(git cat-file -t "$ref") &&
68
case $type in
69
tag)