]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0012-help.sh
help: error if [-a|-g|-c] and [-i|-m|-w] are combined
[thirdparty/git.git] / t / t0012-help.sh
1 #!/bin/sh
2
3 test_description='help'
4
5 . ./test-lib.sh
6
7 configure_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
21 test_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
28 # make sure to exercise these code paths, the output is a bit tricky
29 # to verify
30 test_expect_success 'basic help commands' '
31 git help >/dev/null &&
32 git help -a --no-verbose >/dev/null &&
33 git help -g >/dev/null &&
34 git help -a >/dev/null
35 '
36
37 test_expect_success 'invalid usage' '
38 test_expect_code 129 git help -a add &&
39 test_expect_code 129 git help --all add &&
40
41 test_expect_code 129 git help -g add &&
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
47 test_expect_code 129 git help -g -c &&
48 test_expect_code 129 git help --config-for-completion add &&
49 test_expect_code 129 git help --config-sections-for-completion add
50 '
51
52 for opt in '-a' '-g' '-c' '--config-for-completion' '--config-sections-for-completion'
53 do
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 '
60 done
61
62 test_expect_success "works for commands and guides by default" '
63 configure_help &&
64 git help status &&
65 echo "test://html/git-status.html" >expect &&
66 test_cmp expect test-browser.log &&
67 git help revisions &&
68 echo "test://html/gitrevisions.html" >expect &&
69 test_cmp expect test-browser.log
70 '
71
72 test_expect_success "--exclude-guides does not work for guides" '
73 >test-browser.log &&
74 test_must_fail git help --exclude-guides revisions &&
75 test_must_be_empty test-browser.log
76 '
77
78 test_expect_success "--help does not work for guides" "
79 cat <<-EOF >expect &&
80 git: 'revisions' is not a git command. See 'git --help'.
81 EOF
82 test_must_fail git revisions --help 2>actual &&
83 test_cmp expect actual
84 "
85
86 test_expect_success 'git help' '
87 git help >help.output &&
88 test_i18ngrep "^ clone " help.output &&
89 test_i18ngrep "^ add " help.output &&
90 test_i18ngrep "^ log " help.output &&
91 test_i18ngrep "^ commit " help.output &&
92 test_i18ngrep "^ fetch " help.output
93 '
94 test_expect_success 'git help -g' '
95 git help -g >help.output &&
96 test_i18ngrep "^ attributes " help.output &&
97 test_i18ngrep "^ everyday " help.output &&
98 test_i18ngrep "^ tutorial " help.output
99 '
100
101 test_expect_success 'git help fails for non-existing html pages' '
102 configure_help &&
103 mkdir html-empty &&
104 test_must_fail git -c help.htmlpath=html-empty help status &&
105 test_must_be_empty test-browser.log
106 '
107
108 test_expect_success 'git help succeeds without git.html' '
109 configure_help &&
110 mkdir html-with-docs &&
111 touch html-with-docs/git-status.html &&
112 git -c help.htmlpath=html-with-docs help status &&
113 echo "html-with-docs/git-status.html" >expect &&
114 test_cmp expect test-browser.log
115 '
116
117 test_expect_success 'git help -c' '
118 git help -c >help.output &&
119 cat >expect <<-\EOF &&
120
121 '\''git help config'\'' for more information
122 EOF
123 grep -v -E \
124 -e "^[^.]+\.[^.]+$" \
125 -e "^[^.]+\.[^.]+\.[^.]+$" \
126 help.output >actual &&
127 test_cmp expect actual
128 '
129
130 test_expect_success 'git help --config-for-completion' '
131 git help -c >human &&
132 grep -E \
133 -e "^[^.]+\.[^.]+$" \
134 -e "^[^.]+\.[^.]+\.[^.]+$" human |
135 sed -e "s/\*.*//" -e "s/<.*//" |
136 sort -u >human.munged &&
137
138 git help --config-for-completion >vars &&
139 test_cmp human.munged vars
140 '
141
142 test_expect_success 'git help --config-sections-for-completion' '
143 git help -c >human &&
144 grep -E \
145 -e "^[^.]+\.[^.]+$" \
146 -e "^[^.]+\.[^.]+\.[^.]+$" human |
147 sed -e "s/\..*//" |
148 sort -u >human.munged &&
149
150 git help --config-sections-for-completion >sections &&
151 test_cmp human.munged sections
152 '
153
154 test_section_spacing () {
155 cat >expect &&
156 "$@" >out &&
157 grep -E "(^[^ ]|^$)" out >actual
158 }
159
160 test_section_spacing_trailer () {
161 test_section_spacing "$@" &&
162 test_expect_code 1 git >out &&
163 sed -n '/list available subcommands/,$p' <out >>expect
164 }
165
166
167 for cmd in git "git help"
168 do
169 test_expect_success "'$cmd' section spacing" '
170 test_section_spacing_trailer git help <<-\EOF &&
171 usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
172
173 These are common Git commands used in various situations:
174
175 start a working area (see also: git help tutorial)
176
177 work on the current change (see also: git help everyday)
178
179 examine the history and state (see also: git help revisions)
180
181 grow, mark and tweak your common history
182
183 collaborate (see also: git help workflows)
184
185 EOF
186 test_cmp expect actual
187 '
188 done
189
190 test_expect_success "'git help -g' section spacing" '
191 test_section_spacing_trailer git help -g <<-\EOF &&
192
193 The Git concept guides are:
194
195 EOF
196 test_cmp expect actual
197 '
198
199 test_expect_success 'generate builtin list' '
200 mkdir -p sub &&
201 git --list-cmds=builtins >builtins
202 '
203
204 while read builtin
205 do
206 test_expect_success "$builtin can handle -h" '
207 (
208 GIT_CEILING_DIRECTORIES=$(pwd) &&
209 export GIT_CEILING_DIRECTORIES &&
210 test_expect_code 129 git -C sub $builtin -h >output 2>&1
211 ) &&
212 test_i18ngrep usage output
213 '
214 done <builtins
215
216 test_done