Merge branch 'bc/more-git-var'
[alt-git.git] / t / t0450-txt-doc-vs-help.sh
blobcd3969e852bb06fa3361cd9e8e13d71c5fb514c4
1 #!/bin/sh
3 test_description='assert (unbuilt) Documentation/*.txt and -h output
5 Run this with --debug to see a summary of where we still fail to make
6 the two versions consistent with one another.'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup: list of builtins' '
12 git --list-cmds=builtins >builtins
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"
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: //;
40 }' <"$out.raw" >"$out" &&
41 echo "$out"
44 builtin_to_txt () {
45 echo "$GIT_BUILD_DIR/Documentation/git-$1.txt"
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;
63 s/{litdd}/--/g;
64 s/'\''\(git[ a-z-]*\)'\''/\1/g;
67 }' \
68 <"$b2t" >"$out" &&
69 echo "$out"
72 check_dashed_labels () {
73 ! grep -E "<[^>_-]+_" "$1"
76 HT=" "
78 align_after_nl () {
79 builtin="$1" &&
80 len=$(printf "git %s " "$builtin" | wc -c) &&
81 pad=$(printf "%${len}s" "") &&
83 sed "s/^[ $HT][ $HT]*/$pad/"
86 test_debug '>failing'
87 while read builtin
89 # -h output assertions
90 test_expect_success "$builtin -h output has no \t" '
91 h2s="$(help_to_synopsis "$builtin")" &&
92 ! grep "$HT" "$h2s"
95 test_expect_success "$builtin -h output has dashed labels" '
96 check_dashed_labels "$(help_to_synopsis "$builtin")"
99 test_expect_success "$builtin -h output has consistent spacing" '
100 h2s="$(help_to_synopsis "$builtin")" &&
101 sed -n \
102 -e "/^ / {
103 s/[^ ].*//;
105 }" \
106 <"$h2s" >help &&
107 sort -u help >help.ws &&
108 if test -s help.ws
109 then
110 test_line_count = 1 help.ws
114 txt="$(builtin_to_txt "$builtin")" &&
115 preq="$(echo BUILTIN_TXT_$builtin | tr '[:lower:]-' '[:upper:]_')" &&
117 if test -f "$txt"
118 then
119 test_set_prereq "$preq"
120 fi &&
122 # *.txt output assertions
123 test_expect_success "$preq" "$builtin *.txt SYNOPSIS has dashed labels" '
124 check_dashed_labels "$(txt_to_synopsis "$builtin")"
127 # *.txt output consistency assertions
128 result=
129 if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/txt-help-mismatches
130 then
131 result=failure
132 else
133 result=success
134 fi &&
135 test_expect_$result "$preq" "$builtin -h output and SYNOPSIS agree" '
136 t2s="$(txt_to_synopsis "$builtin")" &&
137 if test "$builtin" = "merge-tree"
138 then
139 test_when_finished "rm -f t2s.new" &&
140 sed -e '\''s/ (deprecated)$//g'\'' <"$t2s" >t2s.new
141 t2s=t2s.new
142 fi &&
143 h2s="$(help_to_synopsis "$builtin")" &&
145 # The *.txt and -h use different spacing for the
146 # alignment of continued usage output, normalize it.
147 align_after_nl "$builtin" <"$t2s" >txt &&
148 align_after_nl "$builtin" <"$h2s" >help &&
149 test_cmp txt help
152 if test_have_prereq "$preq" && test -e txt && test -e help
153 then
154 test_debug '
155 if test_cmp txt help >cmp 2>/dev/null
156 then
157 echo "=== DONE: $builtin ==="
158 else
159 echo "=== TODO: $builtin ===" &&
160 cat cmp
161 fi >>failing
164 # Not in test_expect_success in case --run is being
165 # used with --debug
166 rm -f txt help tmp 2>/dev/null
168 done <builtins
170 test_debug 'say "$(cat failing)"'
172 test_done