comparison tests/test-extension.t @ 12191:56c74b2df53d

tests: unify test-extension
author Adrian Buehlmann <adrian@cadifra.com>
date Fri, 03 Sep 2010 11:19:50 +0200
parents tests/test-extension@ba1ff2063edd
children 4134686b83e1
comparison
equal deleted inserted replaced
12190:9231c629ec10 12191:56c74b2df53d
1 Test basic extension support
2
3 $ "$TESTDIR/hghave" no-outer-repo || exit 80
4
5 $ cat > foobar.py <<EOF
6 > import os
7 > from mercurial import commands
8 >
9 > def uisetup(ui):
10 > ui.write("uisetup called\\n")
11 >
12 > def reposetup(ui, repo):
13 > ui.write("reposetup called for %s\\n" % os.path.basename(repo.root))
14 > ui.write("ui %s= repo.ui\\n" % (ui == repo.ui and "=" or "!"))
15 >
16 > def foo(ui, *args, **kwargs):
17 > ui.write("Foo\\n")
18 >
19 > def bar(ui, *args, **kwargs):
20 > ui.write("Bar\\n")
21 >
22 > cmdtable = {
23 > "foo": (foo, [], "hg foo"),
24 > "bar": (bar, [], "hg bar"),
25 > }
26 >
27 > commands.norepo += ' bar'
28 > EOF
29 $ abspath=`pwd`/foobar.py
30
31 $ mkdir barfoo
32 $ cp foobar.py barfoo/__init__.py
33 $ barfoopath=`pwd`/barfoo
34
35 $ hg init a
36 $ cd a
37 $ echo foo > file
38 $ hg add file
39 $ hg commit -m 'add file'
40
41 $ echo '[extensions]' >> $HGRCPATH
42 $ echo "foobar = $abspath" >> $HGRCPATH
43 $ hg foo
44 uisetup called
45 reposetup called for a
46 ui == repo.ui
47 Foo
48
49 $ cd ..
50 $ hg clone a b
51 uisetup called
52 reposetup called for a
53 ui == repo.ui
54 reposetup called for b
55 ui == repo.ui
56 updating to branch default
57 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
58
59 $ hg bar
60 uisetup called
61 Bar
62 $ echo 'foobar = !' >> $HGRCPATH
63
64 module/__init__.py-style
65
66 $ echo "barfoo = $barfoopath" >> $HGRCPATH
67 $ cd a
68 $ hg foo
69 uisetup called
70 reposetup called for a
71 ui == repo.ui
72 Foo
73 $ echo 'barfoo = !' >> $HGRCPATH
74
75 Check that extensions are loaded in phases:
76
77 $ cat > foo.py <<EOF
78 > import os
79 > name = os.path.basename(__file__).rsplit('.', 1)[0]
80 > print "1) %s imported" % name
81 > def uisetup(ui):
82 > print "2) %s uisetup" % name
83 > def extsetup():
84 > print "3) %s extsetup" % name
85 > def reposetup(ui, repo):
86 > print "4) %s reposetup" % name
87 > EOF
88
89 $ cp foo.py bar.py
90 $ echo 'foo = foo.py' >> $HGRCPATH
91 $ echo 'bar = bar.py' >> $HGRCPATH
92
93 Command with no output, we just want to see the extensions loaded:
94
95 $ hg paths
96 1) foo imported
97 1) bar imported
98 2) foo uisetup
99 2) bar uisetup
100 3) foo extsetup
101 3) bar extsetup
102 4) foo reposetup
103 4) bar reposetup
104
105 Check hgweb's load order:
106
107 $ cat > hgweb.cgi <<EOF
108 > #!/usr/bin/env python
109 > from mercurial import demandimport; demandimport.enable()
110 > from mercurial.hgweb import hgweb
111 > from mercurial.hgweb import wsgicgi
112 >
113 > application = hgweb('.', 'test repo')
114 > wsgicgi.launch(application)
115 > EOF
116
117 $ SCRIPT_NAME='/' SERVER_PORT='80' SERVER_NAME='localhost' python hgweb.cgi \
118 > | grep '^[0-9]) ' # ignores HTML output
119 1) foo imported
120 1) bar imported
121 2) foo uisetup
122 2) bar uisetup
123 3) foo extsetup
124 3) bar extsetup
125 4) foo reposetup
126 4) bar reposetup
127 4) foo reposetup
128 4) bar reposetup
129
130 $ echo 'foo = !' >> $HGRCPATH
131 $ echo 'bar = !' >> $HGRCPATH
132
133 $ cd ..
134
135 $ cat > empty.py <<EOF
136 > '''empty cmdtable
137 > '''
138 > cmdtable = {}
139 > EOF
140 $ emptypath=`pwd`/empty.py
141 $ echo "empty = $emptypath" >> $HGRCPATH
142 $ hg help empty
143 empty extension - empty cmdtable
144
145 no commands defined
146
147 $ echo 'empty = !' >> $HGRCPATH
148
149 $ cat > debugextension.py <<EOF
150 > '''only debugcommands
151 > '''
152 > def debugfoobar(ui, repo, *args, **opts):
153 > "yet another debug command"
154 > pass
155 >
156 > def foo(ui, repo, *args, **opts):
157 > """yet another foo command
158 >
159 > This command has been DEPRECATED since forever.
160 > """
161 > pass
162 >
163 > cmdtable = {
164 > "debugfoobar": (debugfoobar, (), "hg debugfoobar"),
165 > "foo": (foo, (), "hg foo")
166 > }
167 > EOF
168 $ debugpath=`pwd`/debugextension.py
169 $ echo "debugextension = $debugpath" >> $HGRCPATH
170
171 $ hg help debugextension
172 debugextension extension - only debugcommands
173
174 no commands defined
175
176 $ hg --verbose help debugextension
177 debugextension extension - only debugcommands
178
179 list of commands:
180
181 foo:
182 yet another foo command
183
184 global options:
185 -R --repository REPO repository root directory or name of overlay bundle
186 file
187 --cwd DIR change working directory
188 -y --noninteractive do not prompt, assume 'yes' for any required answers
189 -q --quiet suppress output
190 -v --verbose enable additional output
191 --config CONFIG [+] set/override config option (use 'section.name=value')
192 --debug enable debugging output
193 --debugger start debugger
194 --encoding ENCODE set the charset encoding (default: ascii)
195 --encodingmode MODE set the charset encoding mode (default: strict)
196 --traceback always print a traceback on exception
197 --time time how long the command takes
198 --profile print command execution profile
199 --version output version information and exit
200 -h --help display help and exit
201
202 [+] marked option can be specified multiple times
203
204 $ hg --debug help debugextension
205 debugextension extension - only debugcommands
206
207 list of commands:
208
209 debugfoobar:
210 yet another debug command
211 foo:
212 yet another foo command
213
214 global options:
215 -R --repository REPO repository root directory or name of overlay bundle
216 file
217 --cwd DIR change working directory
218 -y --noninteractive do not prompt, assume 'yes' for any required answers
219 -q --quiet suppress output
220 -v --verbose enable additional output
221 --config CONFIG [+] set/override config option (use 'section.name=value')
222 --debug enable debugging output
223 --debugger start debugger
224 --encoding ENCODE set the charset encoding (default: ascii)
225 --encodingmode MODE set the charset encoding mode (default: strict)
226 --traceback always print a traceback on exception
227 --time time how long the command takes
228 --profile print command execution profile
229 --version output version information and exit
230 -h --help display help and exit
231
232 [+] marked option can be specified multiple times
233 $ echo 'debugextension = !' >> $HGRCPATH
234
235 Issue811:
236
237 $ debugpath=`pwd`/debugissue811.py
238 $ cat > debugissue811.py <<EOF
239 > '''show all loaded extensions
240 > '''
241 > from mercurial import extensions, commands
242 >
243 > def debugextensions(ui):
244 > "yet another debug command"
245 > ui.write("%s\n" % '\n'.join([x for x, y in extensions.extensions()]))
246 >
247 > cmdtable = {"debugextensions": (debugextensions, (), "hg debugextensions")}
248 > commands.norepo += " debugextensions"
249 > EOF
250 $ echo "debugissue811 = $debugpath" >> $HGRCPATH
251 $ echo "mq=" >> $HGRCPATH
252 $ echo "hgext.mq=" >> $HGRCPATH
253 $ echo "hgext/mq=" >> $HGRCPATH
254
255 Show extensions:
256
257 $ hg debugextensions
258 debugissue811
259 mq
260
261 Disabled extension commands:
262
263 $ HGRCPATH=
264 $ export HGRCPATH
265 $ hg help email
266 'email' is provided by the following extension:
267
268 patchbomb command to send changesets as (a series of) patch emails
269
270 use "hg help extensions" for information on enabling extensions
271 $ hg qdel
272 hg: unknown command 'qdel'
273 'qdelete' is provided by the following extension:
274
275 mq manage a stack of patches
276
277 use "hg help extensions" for information on enabling extensions
278 $ hg churn
279 hg: unknown command 'churn'
280 'churn' is provided by the following extension:
281
282 churn command to display statistics about repository history
283
284 use "hg help extensions" for information on enabling extensions
285
286 Disabled extensions:
287
288 $ hg help churn
289 churn extension - command to display statistics about repository history
290
291 use "hg help extensions" for information on enabling extensions
292 $ hg help patchbomb
293 patchbomb extension - command to send changesets as (a series of) patch emails
294
295 use "hg help extensions" for information on enabling extensions
296
297 Broken disabled extension and command:
298
299 $ mkdir hgext
300 $ echo > hgext/__init__.py
301 $ cat > hgext/broken.py <<EOF
302 > "broken extension'
303 > EOF
304 $ cat > path.py <<EOF
305 > import os, sys
306 > sys.path.insert(0, os.environ['HGEXTPATH'])
307 > EOF
308 $ HGEXTPATH=`pwd`
309 $ export HGEXTPATH
310
311 $ hg --config extensions.path=./path.py help broken
312 broken extension - (no help text available)
313
314 use "hg help extensions" for information on enabling extensions
315
316 $ hg --config extensions.path=./path.py help foo > /dev/null
317 hg: unknown command 'foo'
318
319 $ exit 0
320