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