Raw
1 #!/bin/sh
2
3 test_description='assert (unbuilt) Documentation/*.adoc and -h output
4
5 Run this with --debug to see a summary of where we still fail to make
6 the two versions consistent with one another.'
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup: list of builtins' '
11 git --list-cmds=builtins >builtins
12 '
13
14 test_expect_success 'list of adoc and help mismatches is sorted' '
15 sort -u "$TEST_DIRECTORY"/t0450/adoc-help-mismatches >expect &&
16 if ! test_cmp expect "$TEST_DIRECTORY"/t0450/adoc-help-mismatches
17 then
18 BUG "please keep the list of adoc and help mismatches sorted"
19 fi
20 '
21
22 help_to_synopsis () {
23 builtin="$1" &&
24 out_dir="out/$builtin" &&
25 out="$out_dir/help.synopsis" &&
26 if test -f "$out"
27 then
28 echo "$out" &&
29 return 0
30 fi &&
31 mkdir -p "$out_dir" &&
32 test_might_fail git $builtin -h >"$out.raw" 2>&1 &&
33 sed -n \
34 -e '1,/^$/ {
35 /^$/d;
36 s/^usage: //;
37 s/^ *or: //;
38 p;
39 }' <"$out.raw" >"$out" &&
40 echo "$out"
41 }
42
43 builtin_to_adoc () {
44 echo "$GIT_SOURCE_DIR/Documentation/git-$1.adoc"
45 }
46
47 adoc_to_synopsis () {
48 builtin="$1" &&
49 out_dir="out/$builtin" &&
50 out="$out_dir/adoc.synopsis" &&
51 if test -f "$out"
52 then
53 echo "$out" &&
54 return 0
55 fi &&
56 b2t="$(builtin_to_adoc "$builtin")" &&
57 sed -n \
58 -E '/^\[(verse|synopsis)\]$/,/^$/ {
59 /^$/q;
60 /^\[(verse|synopsis)\]$/d;
61 s/\{litdd\}/--/g;
62 s/'\''(git[ a-z-]*)'\''/\1/g;
63
64 p;
65 }' \
66 <"$b2t" >"$out" &&
67 echo "$out"
68 }
69
70 check_dashed_labels () {
71 ! grep -E "<[^>_-]+_" "$1"
72 }
73
74 HT=" "
75
76 align_after_nl () {
77 builtin="$1" &&
78 len=$(printf "git %s " "$builtin" | wc -c) &&
79 pad=$(printf "%${len}s" "") &&
80
81 sed "s/^[ $HT][ $HT]*/$pad/"
82 }
83
84 test_debug '>failing'
85 while read builtin
86 do
87 # -h output assertions
88 test_expect_success "$builtin -h output has no \t" '
89 h2s="$(help_to_synopsis "$builtin")" &&
90 test_grep ! "$HT" "$h2s"
91 '
92
93 test_expect_success "$builtin -h output has dashed labels" '
94 check_dashed_labels "$(help_to_synopsis "$builtin")"
95 '
96
97 test_expect_success "$builtin -h output has consistent spacing" '
98 h2s="$(help_to_synopsis "$builtin")" &&
99 sed -n \
100 -e "/^ / {
101 s/[^ ].*//;
102 p;
103 }" \
104 <"$h2s" >help &&
105 sort -u help >help.ws &&
106 if test -s help.ws
107 then
108 test_line_count = 1 help.ws
109 fi
110 '
111
112 adoc="$(builtin_to_adoc "$builtin")" &&
113 preq="$(echo BUILTIN_ADOC_$builtin | tr '[:lower:]-' '[:upper:]_')" &&
114
115 # If and only if *.adoc is missing, builtin shall be listed in t0450/adoc-missing.
116 if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/adoc-missing
117 then
118 test_expect_success "$builtin appropriately marked as not having .adoc" '
119 ! test -f "$adoc"
120 '
121 else
122 test_set_prereq "$preq"
123
124 test_expect_success "$builtin appropriately marked as having .adoc" '
125 test -f "$adoc"
126 '
127 fi
128
129 # *.adoc output assertions
130 test_expect_success "$preq" "$builtin *.adoc SYNOPSIS has dashed labels" '
131 check_dashed_labels "$(adoc_to_synopsis "$builtin")"
132 '
133
134 # *.adoc output consistency assertions
135 result=
136 if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/adoc-help-mismatches
137 then
138 result=failure
139 else
140 result=success
141 fi &&
142 test_expect_$result "$preq" "$builtin -h output and SYNOPSIS agree" '
143 t2s="$(adoc_to_synopsis "$builtin")" &&
144 if test "$builtin" = "merge-tree"
145 then
146 test_when_finished "rm -f t2s.new" &&
147 sed -e '\''s/ (deprecated)$//g'\'' <"$t2s" >t2s.new
148 t2s=t2s.new
149 fi &&
150 h2s="$(help_to_synopsis "$builtin")" &&
151
152 # The *.adoc and -h use different spacing for the
153 # alignment of continued usage output, normalize it.
154 align_after_nl "$builtin" <"$t2s" >adoc &&
155 align_after_nl "$builtin" <"$h2s" >help &&
156 test_cmp adoc help
157 '
158
159 if test_have_prereq "$preq" && test -e adoc && test -e help
160 then
161 test_debug '
162 if test_cmp adoc help >cmp 2>/dev/null
163 then
164 echo "=== DONE: $builtin ==="
165 else
166 echo "=== TODO: $builtin ===" &&
167 cat cmp
168 fi >>failing
169 '
170
171 # Not in test_expect_success in case --run is being
172 # used with --debug
173 rm -f adoc help tmp 2>/dev/null
174 fi
175 done <builtins
176
177 test_debug 'say "$(cat failing)"'
178
179 test_done