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