Skip to content

Commit a0343f3

Browse files
avargitster
authored andcommitted
tests: assert consistent whitespace in -h output
Add a test for the *.txt and *.c output assertions which asserts that for "-h" lines that aren't the "usage: " or " or: " lines they start with the same amount of whitespace. This ensures that we won't have buggy output like: [...] or: git tag [-n[<num>]] [...] [--create-reflog] [...] Which should instead be like this, i.e. the options lines should be aligned: [...] or: git tag [-n[<num>]] [...] [--create-reflog] [...] It would be better to be able to use "test_cmp" here, i.e. to construct the output we expect, and compare it against the actual output. For most built-in commands this would be rather straightforward. In "t0450-txt-doc-vs-help.sh" we already compute the whitespace that a "git-$builtin" needs, and strip away "usage: " or " or: " from the start of lines. The problem is: * For commands that implement subcommands, such as "git bundle", we don't know whether e.g. "git bundle create" is the subcommand "create", or the argument "create" to "bundle" for the purposes of alignment. We *do* have that information from the *.txt version, since the part within the ''-quotes should be the command & subcommand, but that isn't consistent (e.g. see "git bundle" and "git commit-graph", only the latter is correct), and parsing that out would be non-trivial. * If we were to make this stricter we have various non-parse_options() users (e.g. "git diff-tree") that don't have the nicely aligned output which we've had since 4631cfc (parse-options: properly align continued usage output, 2021-09-21). So rather than make perfect the enemy of the good let's assert that for those lines that are indented they should all use the same indentation. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c39fffc commit a0343f3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ do
9696
check_dashed_labels "$(help_to_synopsis "$builtin")"
9797
'
9898

99+
test_expect_success "$builtin -h output has consistent spacing" '
100+
h2s="$(help_to_synopsis "$builtin")" &&
101+
sed -n \
102+
-e "/^ / {
103+
s/[^ ].*//;
104+
p;
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
111+
fi
112+
'
113+
99114
txt="$(builtin_to_txt "$builtin")" &&
100115
preq="$(echo BUILTIN_TXT_$builtin | tr '[:lower:]-' '[:upper:]_')" &&
101116

0 commit comments

Comments
 (0)