]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0012-help.sh
help / completion: make "git help" do the hard work
[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 -g add &&
39 test_expect_code 129 git help -a -c &&
40
41 test_expect_code 129 git help -g add &&
42 test_expect_code 129 git help -a -g &&
43
44 test_expect_code 129 git help -g -c &&
45 test_expect_code 129 git help --config-for-completion add &&
46 test_expect_code 129 git help --config-sections-for-completion add
47 '
48
49 test_expect_success "works for commands and guides by default" '
50 configure_help &&
51 git help status &&
52 echo "test://html/git-status.html" >expect &&
53 test_cmp expect test-browser.log &&
54 git help revisions &&
55 echo "test://html/gitrevisions.html" >expect &&
56 test_cmp expect test-browser.log
57 '
58
59 test_expect_success "--exclude-guides does not work for guides" '
60 >test-browser.log &&
61 test_must_fail git help --exclude-guides revisions &&
62 test_must_be_empty test-browser.log
63 '
64
65 test_expect_success "--help does not work for guides" "
66 cat <<-EOF >expect &&
67 git: 'revisions' is not a git command. See 'git --help'.
68 EOF
69 test_must_fail git revisions --help 2>actual &&
70 test_cmp expect actual
71 "
72
73 test_expect_success 'git help' '
74 git help >help.output &&
75 test_i18ngrep "^ clone " help.output &&
76 test_i18ngrep "^ add " help.output &&
77 test_i18ngrep "^ log " help.output &&
78 test_i18ngrep "^ commit " help.output &&
79 test_i18ngrep "^ fetch " help.output
80 '
81 test_expect_success 'git help -g' '
82 git help -g >help.output &&
83 test_i18ngrep "^ attributes " help.output &&
84 test_i18ngrep "^ everyday " help.output &&
85 test_i18ngrep "^ tutorial " help.output
86 '
87
88 test_expect_success 'git help -c' '
89 git help -c >help.output &&
90 cat >expect <<-\EOF &&
91
92 '\''git help config'\'' for more information
93 EOF
94 grep -v -E \
95 -e "^[^.]+\.[^.]+$" \
96 -e "^[^.]+\.[^.]+\.[^.]+$" \
97 help.output >actual &&
98 test_cmp expect actual
99 '
100
101 test_expect_success 'git help --config-for-completion' '
102 git help -c >human &&
103 grep -E \
104 -e "^[^.]+\.[^.]+$" \
105 -e "^[^.]+\.[^.]+\.[^.]+$" human |
106 sed -e "s/\*.*//" -e "s/<.*//" |
107 sort -u >human.munged &&
108
109 git help --config-for-completion >vars &&
110 test_cmp human.munged vars
111 '
112
113 test_expect_success 'git help --config-sections-for-completion' '
114 git help -c >human &&
115 grep -E \
116 -e "^[^.]+\.[^.]+$" \
117 -e "^[^.]+\.[^.]+\.[^.]+$" human |
118 sed -e "s/\..*//" |
119 sort -u >human.munged &&
120
121 git help --config-sections-for-completion >sections &&
122 test_cmp human.munged sections
123 '
124
125 test_expect_success 'generate builtin list' '
126 git --list-cmds=builtins >builtins
127 '
128
129 while read builtin
130 do
131 test_expect_success "$builtin can handle -h" '
132 test_expect_code 129 git $builtin -h >output 2>&1 &&
133 test_i18ngrep usage output
134 '
135 done <builtins
136
137 test_done