]>
Commit | Line | Data |
---|---|---|
af74128f RT |
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 | ||
63eae83f NTND |
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 && | |
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 | 37 | test_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 | ||
af74128f RT |
52 | test_expect_success "works for commands and guides by default" ' |
53 | configure_help && | |
54 | git help status && | |
55 | echo "test://html/git-status.html" >expect && | |
56 | test_cmp expect test-browser.log && | |
57 | git help revisions && | |
58 | echo "test://html/gitrevisions.html" >expect && | |
59 | test_cmp expect test-browser.log | |
60 | ' | |
61 | ||
62 | test_expect_success "--exclude-guides does not work for guides" ' | |
63 | >test-browser.log && | |
64 | test_must_fail git help --exclude-guides revisions && | |
65 | test_must_be_empty test-browser.log | |
66 | ' | |
67 | ||
2c6b6d9f RT |
68 | test_expect_success "--help does not work for guides" " |
69 | cat <<-EOF >expect && | |
70 | git: 'revisions' is not a git command. See 'git --help'. | |
71 | EOF | |
72 | test_must_fail git revisions --help 2>actual && | |
1108cea7 | 73 | test_cmp expect actual |
2c6b6d9f RT |
74 | " |
75 | ||
cfb22a02 NTND |
76 | test_expect_success 'git help' ' |
77 | git help >help.output && | |
78 | test_i18ngrep "^ clone " help.output && | |
79 | test_i18ngrep "^ add " help.output && | |
80 | test_i18ngrep "^ log " help.output && | |
81 | test_i18ngrep "^ commit " help.output && | |
82 | test_i18ngrep "^ fetch " help.output | |
83 | ' | |
1b81d8cb NTND |
84 | test_expect_success 'git help -g' ' |
85 | git help -g >help.output && | |
86 | test_i18ngrep "^ attributes " help.output && | |
87 | test_i18ngrep "^ everyday " help.output && | |
88 | test_i18ngrep "^ tutorial " help.output | |
89 | ' | |
cfb22a02 | 90 | |
a3952f8e MA |
91 | test_expect_success 'git help fails for non-existing html pages' ' |
92 | configure_help && | |
93 | mkdir html-empty && | |
94 | test_must_fail git -c help.htmlpath=html-empty help status && | |
95 | test_must_be_empty test-browser.log | |
96 | ' | |
97 | ||
98 | test_expect_success 'git help succeeds without git.html' ' | |
99 | configure_help && | |
100 | mkdir html-with-docs && | |
101 | touch html-with-docs/git-status.html && | |
102 | git -c help.htmlpath=html-with-docs help status && | |
103 | echo "html-with-docs/git-status.html" >expect && | |
104 | test_cmp expect test-browser.log | |
105 | ' | |
106 | ||
ff76fc84 ÆAB |
107 | test_expect_success 'git help -c' ' |
108 | git help -c >help.output && | |
109 | cat >expect <<-\EOF && | |
110 | ||
111 | '\''git help config'\'' for more information | |
112 | EOF | |
113 | grep -v -E \ | |
114 | -e "^[^.]+\.[^.]+$" \ | |
115 | -e "^[^.]+\.[^.]+\.[^.]+$" \ | |
116 | help.output >actual && | |
117 | test_cmp expect actual | |
118 | ' | |
119 | ||
5a5f04d8 ÆAB |
120 | test_expect_success 'git help --config-for-completion' ' |
121 | git help -c >human && | |
122 | grep -E \ | |
123 | -e "^[^.]+\.[^.]+$" \ | |
124 | -e "^[^.]+\.[^.]+\.[^.]+$" human | | |
125 | sed -e "s/\*.*//" -e "s/<.*//" | | |
126 | sort -u >human.munged && | |
127 | ||
128 | git help --config-for-completion >vars && | |
5a5f04d8 ÆAB |
129 | test_cmp human.munged vars |
130 | ' | |
131 | ||
a9baccca ÆAB |
132 | test_expect_success 'git help --config-sections-for-completion' ' |
133 | git help -c >human && | |
134 | grep -E \ | |
135 | -e "^[^.]+\.[^.]+$" \ | |
136 | -e "^[^.]+\.[^.]+\.[^.]+$" human | | |
137 | sed -e "s/\..*//" | | |
138 | sort -u >human.munged && | |
139 | ||
140 | git help --config-sections-for-completion >sections && | |
141 | test_cmp human.munged sections | |
142 | ' | |
143 | ||
bf7eed75 ÆAB |
144 | test_section_spacing () { |
145 | cat >expect && | |
146 | "$@" >out && | |
147 | grep -E "(^[^ ]|^$)" out >actual | |
148 | } | |
149 | ||
150 | test_section_spacing_trailer () { | |
151 | test_section_spacing "$@" && | |
152 | test_expect_code 1 git >out && | |
153 | sed -n '/list available subcommands/,$p' <out >>expect | |
154 | } | |
155 | ||
156 | ||
157 | for cmd in git "git help" | |
158 | do | |
159 | test_expect_success "'$cmd' section spacing" ' | |
160 | test_section_spacing_trailer git help <<-\EOF && | |
161 | usage: git [--version] [--help] [-C <path>] [-c <name>=<value>] | |
162 | ||
163 | These are common Git commands used in various situations: | |
164 | ||
165 | start a working area (see also: git help tutorial) | |
166 | ||
167 | work on the current change (see also: git help everyday) | |
168 | ||
169 | examine the history and state (see also: git help revisions) | |
170 | ||
171 | grow, mark and tweak your common history | |
172 | ||
173 | collaborate (see also: git help workflows) | |
174 | ||
175 | EOF | |
176 | test_cmp expect actual | |
177 | ' | |
178 | done | |
179 | ||
180 | test_expect_success "'git help -g' section spacing" ' | |
181 | test_section_spacing_trailer git help -g <<-\EOF && | |
182 | ||
183 | The Git concept guides are: | |
184 | ||
185 | EOF | |
186 | test_cmp expect actual | |
187 | ' | |
188 | ||
d6915511 | 189 | test_expect_success 'generate builtin list' ' |
87ad07d7 | 190 | mkdir -p sub && |
0089521c | 191 | git --list-cmds=builtins >builtins |
d6915511 JK |
192 | ' |
193 | ||
194 | while read builtin | |
195 | do | |
196 | test_expect_success "$builtin can handle -h" ' | |
87ad07d7 JS |
197 | ( |
198 | GIT_CEILING_DIRECTORIES=$(pwd) && | |
199 | export GIT_CEILING_DIRECTORIES && | |
200 | test_expect_code 129 git -C sub $builtin -h >output 2>&1 | |
201 | ) && | |
d6915511 JK |
202 | test_i18ngrep usage output |
203 | ' | |
204 | done <builtins | |
205 | ||
af74128f | 206 | test_done |