]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0012-help.sh
help: don't print "\n" before single-section output
[thirdparty/git.git] / t / t0012-help.sh
CommitLineData
af74128f
RT
1#!/bin/sh
2
3test_description='help'
4
5. ./test-lib.sh
6
7configure_help () {
8 test_config help.format html &&
9
10 # Unless the path has "://" in it, Git tries to make sure
11 # the documentation directory locally exists. Avoid it as
12 # we are only interested in seeing an attempt to correctly
13 # invoke a help browser in this test.
14 test_config help.htmlpath test://html &&
15
16 # Name a custom browser
17 test_config browser.test.cmd ./test-browser &&
18 test_config help.browser test
19}
20
21test_expect_success "setup" '
22 # Just write out which page gets requested
23 write_script test-browser <<-\EOF
24 echo "$*" >test-browser.log
25 EOF
26'
27
63eae83f
NTND
28# make sure to exercise these code paths, the output is a bit tricky
29# to verify
30test_expect_success 'basic help commands' '
31 git help >/dev/null &&
26c7d067 32 git help -a --no-verbose >/dev/null &&
63eae83f 33 git help -g >/dev/null &&
26c7d067 34 git help -a >/dev/null
63eae83f
NTND
35'
36
9856ea67 37test_expect_success 'invalid usage' '
5e8068b7
ÆAB
38 test_expect_code 129 git help -a add &&
39 test_expect_code 129 git help --all add &&
40
1ed4bef6 41 test_expect_code 129 git help -g add &&
0a5940fb
ÆAB
42 test_expect_code 129 git help -a -c &&
43
44 test_expect_code 129 git help -g add &&
45 test_expect_code 129 git help -a -g &&
46
5a5f04d8 47 test_expect_code 129 git help -g -c &&
a9baccca
ÆAB
48 test_expect_code 129 git help --config-for-completion add &&
49 test_expect_code 129 git help --config-sections-for-completion add
9856ea67
ÆAB
50'
51
503cddac
ÆAB
52for opt in '-a' '-g' '-c' '--config-for-completion' '--config-sections-for-completion'
53do
54 test_expect_success "invalid usage of '$opt' with [-i|-m|-w]" '
55 git help $opt &&
56 test_expect_code 129 git help $opt -i &&
57 test_expect_code 129 git help $opt -m &&
58 test_expect_code 129 git help $opt -w
59 '
1ce59013
ÆAB
60
61 if test "$opt" = "-a"
62 then
63 continue
64 fi
65
66 test_expect_success "invalid usage of '$opt' with --no-external-commands" '
67 test_expect_code 129 git help $opt --no-external-commands
68 '
69
70 test_expect_success "invalid usage of '$opt' with --no-aliases" '
71 test_expect_code 129 git help $opt --no-external-commands
72 '
503cddac
ÆAB
73done
74
af74128f
RT
75test_expect_success "works for commands and guides by default" '
76 configure_help &&
77 git help status &&
78 echo "test://html/git-status.html" >expect &&
79 test_cmp expect test-browser.log &&
80 git help revisions &&
81 echo "test://html/gitrevisions.html" >expect &&
82 test_cmp expect test-browser.log
83'
84
85test_expect_success "--exclude-guides does not work for guides" '
86 >test-browser.log &&
87 test_must_fail git help --exclude-guides revisions &&
88 test_must_be_empty test-browser.log
89'
90
2c6b6d9f
RT
91test_expect_success "--help does not work for guides" "
92 cat <<-EOF >expect &&
93 git: 'revisions' is not a git command. See 'git --help'.
94 EOF
95 test_must_fail git revisions --help 2>actual &&
1108cea7 96 test_cmp expect actual
2c6b6d9f
RT
97"
98
cfb22a02
NTND
99test_expect_success 'git help' '
100 git help >help.output &&
101 test_i18ngrep "^ clone " help.output &&
102 test_i18ngrep "^ add " help.output &&
103 test_i18ngrep "^ log " help.output &&
104 test_i18ngrep "^ commit " help.output &&
105 test_i18ngrep "^ fetch " help.output
106'
1b81d8cb
NTND
107test_expect_success 'git help -g' '
108 git help -g >help.output &&
109 test_i18ngrep "^ attributes " help.output &&
110 test_i18ngrep "^ everyday " help.output &&
111 test_i18ngrep "^ tutorial " help.output
112'
cfb22a02 113
a3952f8e
MA
114test_expect_success 'git help fails for non-existing html pages' '
115 configure_help &&
116 mkdir html-empty &&
117 test_must_fail git -c help.htmlpath=html-empty help status &&
118 test_must_be_empty test-browser.log
119'
120
121test_expect_success 'git help succeeds without git.html' '
122 configure_help &&
123 mkdir html-with-docs &&
124 touch html-with-docs/git-status.html &&
125 git -c help.htmlpath=html-with-docs help status &&
126 echo "html-with-docs/git-status.html" >expect &&
127 test_cmp expect test-browser.log
128'
129
ff76fc84
ÆAB
130test_expect_success 'git help -c' '
131 git help -c >help.output &&
132 cat >expect <<-\EOF &&
133
134 '\''git help config'\'' for more information
135 EOF
136 grep -v -E \
137 -e "^[^.]+\.[^.]+$" \
138 -e "^[^.]+\.[^.]+\.[^.]+$" \
139 help.output >actual &&
140 test_cmp expect actual
141'
142
5a5f04d8
ÆAB
143test_expect_success 'git help --config-for-completion' '
144 git help -c >human &&
145 grep -E \
146 -e "^[^.]+\.[^.]+$" \
147 -e "^[^.]+\.[^.]+\.[^.]+$" human |
148 sed -e "s/\*.*//" -e "s/<.*//" |
149 sort -u >human.munged &&
150
151 git help --config-for-completion >vars &&
5a5f04d8
ÆAB
152 test_cmp human.munged vars
153'
154
a9baccca
ÆAB
155test_expect_success 'git help --config-sections-for-completion' '
156 git help -c >human &&
157 grep -E \
158 -e "^[^.]+\.[^.]+$" \
159 -e "^[^.]+\.[^.]+\.[^.]+$" human |
160 sed -e "s/\..*//" |
161 sort -u >human.munged &&
162
163 git help --config-sections-for-completion >sections &&
164 test_cmp human.munged sections
165'
166
bf7eed75
ÆAB
167test_section_spacing () {
168 cat >expect &&
169 "$@" >out &&
170 grep -E "(^[^ ]|^$)" out >actual
171}
172
173test_section_spacing_trailer () {
174 test_section_spacing "$@" &&
175 test_expect_code 1 git >out &&
176 sed -n '/list available subcommands/,$p' <out >>expect
177}
178
179
180for cmd in git "git help"
181do
182 test_expect_success "'$cmd' section spacing" '
183 test_section_spacing_trailer git help <<-\EOF &&
184 usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
185
186 These are common Git commands used in various situations:
187
188 start a working area (see also: git help tutorial)
189
190 work on the current change (see also: git help everyday)
191
192 examine the history and state (see also: git help revisions)
193
194 grow, mark and tweak your common history
195
196 collaborate (see also: git help workflows)
197
198 EOF
199 test_cmp expect actual
200 '
201done
202
1ce59013
ÆAB
203test_expect_success "'git help -a' section spacing" '
204 test_section_spacing \
205 git help -a --no-external-commands --no-aliases <<-\EOF &&
206 See '\''git help <command>'\'' to read about a specific subcommand
207
208 Main Porcelain Commands
209
210 Ancillary Commands / Manipulators
211
212 Ancillary Commands / Interrogators
213
214 Interacting with Others
215
216 Low-level Commands / Manipulators
217
218 Low-level Commands / Interrogators
219
220 Low-level Commands / Syncing Repositories
221
222 Low-level Commands / Internal Helpers
223 EOF
224 test_cmp expect actual
225'
226
bf7eed75
ÆAB
227test_expect_success "'git help -g' section spacing" '
228 test_section_spacing_trailer git help -g <<-\EOF &&
bf7eed75
ÆAB
229 The Git concept guides are:
230
231 EOF
232 test_cmp expect actual
233'
234
d6915511 235test_expect_success 'generate builtin list' '
87ad07d7 236 mkdir -p sub &&
0089521c 237 git --list-cmds=builtins >builtins
d6915511
JK
238'
239
240while read builtin
241do
242 test_expect_success "$builtin can handle -h" '
87ad07d7
JS
243 (
244 GIT_CEILING_DIRECTORIES=$(pwd) &&
245 export GIT_CEILING_DIRECTORIES &&
246 test_expect_code 129 git -C sub $builtin -h >output 2>&1
247 ) &&
d6915511
JK
248 test_i18ngrep usage output
249 '
250done <builtins
251
af74128f 252test_done