Skip to content

Commit c39fffc

Browse files
avargitster
authored andcommitted
tests: start asserting that *.txt SYNOPSIS matches -h output
There's been a lot of incremental effort to make the SYNOPSIS output in our documentation consistent with the -h output, e.g. cbe4852 (git reflog [expire|delete]: make -h output consistent with SYNOPSIS, 2022-03-17) is one recent example, but that effort has been an uphill battle due to the lack of regression testing. This adds such regression testing, we can parse out the SYNOPSIS output with "sed", and it turns out it's relatively easy to normalize it and the "-h" output to match on another. We now ensure that we won't have regressions when it comes to the list of commands in "expect_help_to_match_txt" below, and in subsequent commits we'll make more of them consistent. The naïve parser here gets quite a few things wrong, but it doesn't need to be perfect, just good enough that we can compare /some/ of this help output. There's no cases where the output would match except for the parser's stupidity, it's all cases of e.g. comparing the *.txt to non-parse_options() output. Since that output is wildly different than the *.txt anyway let's leave this for now, we can fix the parser some other time, or it won't become necessary as we'll e.g. convert more things to using parse_options(). Having a special-case for "merge-tree"'s 1f0c3a2 (merge-tree: implement real merges, 2022-06-18) is a bit ugly, but preferred to blessing that " (deprecated)" pattern for other commands. We'd probably want to add some other way of marking deprecated commands in the SYNOPSIS syntax. Syntactically 1f0c3a2's way of doing it is indistinguishable from the command taking an optional literal "deprecated" string as an argument. Some of the issues that are left: * "git show -h", "git whatchanged -h" and "git reflog --oneline -h" all showing "git log" and "git show" usage output. I.e. the "builtin_log_usage" in builtin/log.c doesn't take into account what command we're running. * Commands which implement subcommands such as like "multi-pack-index", "notes", "remote" etc. having their subcommands in a very different order in the *.txt and *.c. Fixing it would require some verbose diffs, so it's been left alone for now. * Commands such as "format-patch" have a very long argument list in the *.txt, but just "[<options>]" in the *.c. What to do about these has been left out of this series, except to the extent that preceding commits changed "[<options>]" (or equivalent) to the list of options in cases where that list of options was tiny, or we clearly meant to exhaustively list the options in both *.txt and *.c. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 97f03a5 commit c39fffc

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

t/t0450-txt-doc-vs-help.sh

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/sh
22

3-
test_description='assert (unbuilt) Documentation/*.txt and -h output'
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.'
47

58
TEST_PASSES_SANITIZE_LEAK=true
69
. ./test-lib.sh
@@ -9,6 +12,14 @@ test_expect_success 'setup: list of builtins' '
912
git --list-cmds=builtins >builtins
1013
'
1114

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+
1223
help_to_synopsis () {
1324
builtin="$1" &&
1425
out_dir="out/$builtin" &&
@@ -49,6 +60,9 @@ txt_to_synopsis () {
4960
/^$/d;
5061
/^\[verse\]$/d;
5162
63+
s/{litdd}/--/g;
64+
s/'\''\(git[ a-z-]*\)'\''/\1/g;
65+
5266
p;
5367
}' \
5468
<"$b2t" >"$out" &&
@@ -61,6 +75,15 @@ check_dashed_labels () {
6175

6276
HT=" "
6377

78+
align_after_nl () {
79+
builtin="$1" &&
80+
len=$(printf "git %s " "$builtin" | wc -c) &&
81+
pad=$(printf "%${len}s" "") &&
82+
83+
sed "s/^[ $HT][ $HT]*/$pad/"
84+
}
85+
86+
test_debug '>failing'
6487
while read builtin
6588
do
6689
# -h output assertions
@@ -85,6 +108,50 @@ do
85108
test_expect_success "$preq" "$builtin *.txt SYNOPSIS has dashed labels" '
86109
check_dashed_labels "$(txt_to_synopsis "$builtin")"
87110
'
111+
112+
# *.txt output consistency assertions
113+
result=
114+
if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/txt-help-mismatches
115+
then
116+
result=failure
117+
else
118+
result=success
119+
fi &&
120+
test_expect_$result "$preq" "$builtin -h output and SYNOPSIS agree" '
121+
t2s="$(txt_to_synopsis "$builtin")" &&
122+
if test "$builtin" = "merge-tree"
123+
then
124+
test_when_finished "rm -f t2s.new" &&
125+
sed -e '\''s/ (deprecated)$//g'\'' <"$t2s" >t2s.new
126+
t2s=t2s.new
127+
fi &&
128+
h2s="$(help_to_synopsis "$builtin")" &&
129+
130+
# The *.txt and -h use different spacing for the
131+
# alignment of continued usage output, normalize it.
132+
align_after_nl "$builtin" <"$t2s" >txt &&
133+
align_after_nl "$builtin" <"$h2s" >help &&
134+
test_cmp txt help
135+
'
136+
137+
if test_have_prereq "$preq" && test -e txt && test -e help
138+
then
139+
test_debug '
140+
if test_cmp txt help >cmp 2>/dev/null
141+
then
142+
echo "=== DONE: $builtin ==="
143+
else
144+
echo "=== TODO: $builtin ===" &&
145+
cat cmp
146+
fi >>failing
147+
'
148+
149+
# Not in test_expect_success in case --run is being
150+
# used with --debug
151+
rm -f txt help tmp 2>/dev/null
152+
fi
88153
done <builtins
89154

155+
test_debug 'say "$(cat failing)"'
156+
90157
test_done

t/t0450/txt-help-mismatches

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
add
2+
am
3+
apply
4+
archive
5+
bisect
6+
blame
7+
branch
8+
check-ref-format
9+
checkout
10+
checkout-index
11+
clone
12+
column
13+
config
14+
credential
15+
credential-cache
16+
credential-store
17+
fast-export
18+
fast-import
19+
fetch-pack
20+
fmt-merge-msg
21+
for-each-ref
22+
format-patch
23+
fsck-objects
24+
fsmonitor--daemon
25+
gc
26+
grep
27+
index-pack
28+
init-db
29+
log
30+
ls-files
31+
ls-tree
32+
mailinfo
33+
mailsplit
34+
maintenance
35+
merge
36+
merge-file
37+
merge-index
38+
merge-one-file
39+
multi-pack-index
40+
name-rev
41+
notes
42+
pack-objects
43+
push
44+
range-diff
45+
rebase
46+
remote
47+
remote-ext
48+
remote-fd
49+
repack
50+
reset
51+
restore
52+
rev-parse
53+
show
54+
stage
55+
switch
56+
update-index
57+
update-ref
58+
whatchanged

0 commit comments

Comments
 (0)