tests: assert *.txt SYNOPSIS and -h output

Add a test to assert basic compliance with the CodingGuidelines in the SYNOPSIS and builtin -h output. For now we only assert that the "-h" output doesn't have "\t" characters, as a very basic syntax check. Subsequent commits will expand on the checks here as various issues are fixed, but let's first add the test scaffolding. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 13, 2022 at 17:38 UTC e5e6667b489badf6f2a3ae1d2bdc021c8060657c
1 file changed +44
t/t0450-txt-doc-vs-help.sh new
+44
@@ -0,0 +1,44 @@
1 +#!/bin/sh
2 +
3 +test_description='assert (unbuilt) Documentation/*.txt and -h output'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 +. ./test-lib.sh
7 +
8 +test_expect_success 'setup: list of builtins' '
9 + git --list-cmds=builtins >builtins
10 +'
11 +
12 +help_to_synopsis () {
13 + builtin="$1" &&
14 + out_dir="out/$builtin" &&
15 + out="$out_dir/help.synopsis" &&
16 + if test -f "$out"
17 + then
18 + echo "$out" &&
19 + return 0
20 + fi &&
21 + mkdir -p "$out_dir" &&
22 + test_expect_code 129 git $builtin -h >"$out.raw" 2>&1 &&
23 + sed -n \
24 + -e '1,/^$/ {
25 + /^$/d;
26 + s/^usage: //;
27 + s/^ *or: //;
28 + p;
29 + }' <"$out.raw" >"$out" &&
30 + echo "$out"
31 +}
32 +
33 +HT=" "
34 +
35 +while read builtin
36 +do
37 + # -h output assertions
38 + test_expect_success "$builtin -h output has no \t" '
39 + h2s="$(help_to_synopsis "$builtin")" &&
40 + ! grep "$HT" "$h2s"
41 + '
42 +done <builtins
43 +
44 +test_done