##// END OF EJS Templates
test-commandserver: port test functions from .py to .t...
Yuya Nishihara -
r22568:78b99149 default
parent child Browse files
Show More
@@ -1,14 +1,64 b''
1 #require false
1 #if windows
2 $ PYTHONPATH="$TESTDIR/../contrib;$PYTHONPATH"
3 #else
4 $ PYTHONPATH="$TESTDIR/../contrib:$PYTHONPATH"
5 #endif
6 $ export PYTHONPATH
7
8 $ hg init repo
9 $ cd repo
10
11 >>> import re
12 >>> from hgclient import readchannel, runcommand, check
13 >>> @check
14 ... def hellomessage(server):
15 ... ch, data = readchannel(server)
16 ... # escaping python tests output not supported
17 ... print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+',
18 ... 'encoding: ***', data))
19 ...
20 ... # run an arbitrary command to make sure the next thing the server
21 ... # sends isn't part of the hello message
22 ... runcommand(server, ['id'])
2 23
3 24 testing hellomessage:
4 25
5 26 o, 'capabilities: getencoding runcommand\nencoding: ***'
6 27 runcommand id
7 28 000000000000 tip
29
30 >>> from hgclient import check
31 >>> @check
32 ... def unknowncommand(server):
33 ... server.stdin.write('unknowncommand\n')
8 34
9 35 testing unknowncommand:
10 36
11 37 abort: unknown command unknowncommand
38
39 >>> from hgclient import readchannel, runcommand, check
40 >>> @check
41 ... def checkruncommand(server):
42 ... # hello block
43 ... readchannel(server)
44 ...
45 ... # no args
46 ... runcommand(server, [])
47 ...
48 ... # global options
49 ... runcommand(server, ['id', '--quiet'])
50 ...
51 ... # make sure global options don't stick through requests
52 ... runcommand(server, ['id'])
53 ...
54 ... # --config
55 ... runcommand(server, ['id', '--config', 'ui.quiet=True'])
56 ...
57 ... # make sure --config doesn't stick
58 ... runcommand(server, ['id'])
59 ...
60 ... # negative return code should be masked
61 ... runcommand(server, ['id', '-runknown'])
12 62
13 63 testing checkruncommand:
14 64
@@ -47,10 +97,45 b''
47 97 runcommand id -runknown
48 98 abort: unknown revision 'unknown'!
49 99 [255]
100
101 >>> from hgclient import readchannel, check
102 >>> @check
103 ... def inputeof(server):
104 ... readchannel(server)
105 ... server.stdin.write('runcommand\n')
106 ... # close stdin while server is waiting for input
107 ... server.stdin.close()
108 ...
109 ... # server exits with 1 if the pipe closed while reading the command
110 ... print 'server exit code =', server.wait()
50 111
51 112 testing inputeof:
52 113
53 114 server exit code = 1
115
116 >>> import cStringIO
117 >>> from hgclient import readchannel, runcommand, check
118 >>> @check
119 ... def serverinput(server):
120 ... readchannel(server)
121 ...
122 ... patch = """
123 ... # HG changeset patch
124 ... # User test
125 ... # Date 0 0
126 ... # Node ID c103a3dec114d882c98382d684d8af798d09d857
127 ... # Parent 0000000000000000000000000000000000000000
128 ... 1
129 ...
130 ... diff -r 000000000000 -r c103a3dec114 a
131 ... --- /dev/null Thu Jan 01 00:00:00 1970 +0000
132 ... +++ b/a Thu Jan 01 00:00:00 1970 +0000
133 ... @@ -0,0 +1,1 @@
134 ... +1
135 ... """
136 ...
137 ... runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
138 ... runcommand(server, ['log'])
54 139
55 140 testing serverinput:
56 141
@@ -63,6 +148,17 b''
63 148 date: Thu Jan 01 00:00:00 1970 +0000
64 149 summary: 1
65 150
151
152 check that --cwd doesn't persist between requests:
153
154 $ mkdir foo
155 $ touch foo/bar
156 >>> from hgclient import readchannel, runcommand, check
157 >>> @check
158 ... def cwd(server):
159 ... readchannel(server)
160 ... runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
161 ... runcommand(server, ['st', 'foo/bar'])
66 162
67 163 testing cwd:
68 164
@@ -70,6 +166,29 b''
70 166 ? bar
71 167 runcommand st foo/bar
72 168 ? foo/bar
169
170 $ rm foo/bar
171
172
173 check that local configs for the cached repo aren't inherited when -R is used:
174
175 $ cat <<EOF >> .hg/hgrc
176 > [ui]
177 > foo = bar
178 > EOF
179
180 >>> from hgclient import readchannel, sep, runcommand, check
181 >>> @check
182 ... def localhgrc(server):
183 ... readchannel(server)
184 ...
185 ... # the cached repo local hgrc contains ui.foo=bar, so showconfig should
186 ... # show it
187 ... runcommand(server, ['showconfig'], outfilter=sep)
188 ...
189 ... # but not for this repo
190 ... runcommand(server, ['init', 'foo'])
191 ... runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
73 192
74 193 testing localhgrc:
75 194
@@ -94,13 +213,51 b''
94 213 ui.interactive=False
95 214 ui.mergemarkers=detailed
96 215 ui.nontty=true
216
217 $ rm -R foo
218
219 #if windows
220 $ PYTHONPATH="$TESTTMP/repo;$PYTHONPATH"
221 #else
222 $ PYTHONPATH="$TESTTMP/repo:$PYTHONPATH"
223 #endif
224
225 $ cat <<EOF > hook.py
226 > import sys
227 > def hook(**args):
228 > print 'hook talking'
229 > print 'now try to read something: %r' % sys.stdin.read()
230 > EOF
231
232 >>> import cStringIO
233 >>> from hgclient import readchannel, runcommand, check
234 >>> @check
235 ... def hookoutput(server):
236 ... readchannel(server)
237 ... runcommand(server, ['--config',
238 ... 'hooks.pre-identify=python:hook.hook',
239 ... 'id'],
240 ... input=cStringIO.StringIO('some input'))
97 241
98 242 testing hookoutput:
99 243
100 runcommand --config hooks.pre-identify=python:test-commandserver.hook id
244 runcommand --config hooks.pre-identify=python:hook.hook id
101 245 hook talking
102 246 now try to read something: 'some input'
103 247 eff892de26ec tip
248
249 $ rm hook.py*
250
251 $ echo a >> a
252 >>> import os
253 >>> from hgclient import readchannel, runcommand, check
254 >>> @check
255 ... def outsidechanges(server):
256 ... readchannel(server)
257 ... runcommand(server, ['status'])
258 ... os.system('hg ci -Am2')
259 ... runcommand(server, ['tip'])
260 ... runcommand(server, ['status'])
104 261
105 262 testing outsidechanges:
106 263
@@ -114,6 +271,29 b''
114 271 summary: 2
115 272
116 273 runcommand status
274
275 >>> import os
276 >>> from hgclient import readchannel, runcommand, check
277 >>> @check
278 ... def bookmarks(server):
279 ... readchannel(server)
280 ... runcommand(server, ['bookmarks'])
281 ...
282 ... # changes .hg/bookmarks
283 ... os.system('hg bookmark -i bm1')
284 ... os.system('hg bookmark -i bm2')
285 ... runcommand(server, ['bookmarks'])
286 ...
287 ... # changes .hg/bookmarks.current
288 ... os.system('hg upd bm1 -q')
289 ... runcommand(server, ['bookmarks'])
290 ...
291 ... runcommand(server, ['bookmarks', 'bm3'])
292 ... f = open('a', 'ab')
293 ... f.write('a\n')
294 ... f.close()
295 ... runcommand(server, ['commit', '-Amm'])
296 ... runcommand(server, ['bookmarks'])
117 297
118 298 testing bookmarks:
119 299
@@ -131,6 +311,15 b''
131 311 bm1 1:d3a0a68be6de
132 312 bm2 1:d3a0a68be6de
133 313 * bm3 2:aef17e88f5f0
314
315 >>> import os
316 >>> from hgclient import readchannel, runcommand, check
317 >>> @check
318 ... def tagscache(server):
319 ... readchannel(server)
320 ... runcommand(server, ['id', '-t', '-r', '0'])
321 ... os.system('hg tag -r 0 foo')
322 ... runcommand(server, ['id', '-t', '-r', '0'])
134 323
135 324 testing tagscache:
136 325
@@ -138,6 +327,15 b''
138 327
139 328 runcommand id -t -r 0
140 329 foo
330
331 >>> import os
332 >>> from hgclient import readchannel, runcommand, check
333 >>> @check
334 ... def setphase(server):
335 ... readchannel(server)
336 ... runcommand(server, ['phase', '-r', '.'])
337 ... os.system('hg phase -r . -p')
338 ... runcommand(server, ['phase', '-r', '.'])
141 339
142 340 testing setphase:
143 341
@@ -145,6 +343,16 b''
145 343 3: draft
146 344 runcommand phase -r .
147 345 3: public
346
347 $ echo a >> a
348 >>> from hgclient import readchannel, runcommand, check
349 >>> @check
350 ... def rollback(server):
351 ... readchannel(server)
352 ... runcommand(server, ['phase', '-r', '.', '-p'])
353 ... runcommand(server, ['commit', '-Am.'])
354 ... runcommand(server, ['rollback'])
355 ... runcommand(server, ['phase', '-r', '.'])
148 356
149 357 testing rollback:
150 358
@@ -157,6 +365,16 b''
157 365 working directory now based on revision 3
158 366 runcommand phase -r .
159 367 3: public
368
369 >>> import os
370 >>> from hgclient import readchannel, runcommand, check
371 >>> @check
372 ... def branch(server):
373 ... readchannel(server)
374 ... runcommand(server, ['branch'])
375 ... os.system('hg branch foo')
376 ... runcommand(server, ['branch'])
377 ... os.system('hg branch default')
160 378
161 379 testing branch:
162 380
@@ -168,6 +386,21 b''
168 386 foo
169 387 marked working directory as branch default
170 388 (branches are permanent and global, did you want a bookmark?)
389
390 $ touch .hgignore
391 >>> import os
392 >>> from hgclient import readchannel, runcommand, check
393 >>> @check
394 ... def hgignore(server):
395 ... readchannel(server)
396 ... runcommand(server, ['commit', '-Am.'])
397 ... f = open('ignored-file', 'ab')
398 ... f.write('')
399 ... f.close()
400 ... f = open('.hgignore', 'ab')
401 ... f.write('ignored-file')
402 ... f.close()
403 ... runcommand(server, ['status', '-i', '-u'])
171 404
172 405 testing hgignore:
173 406
@@ -175,6 +408,31 b''
175 408 adding .hgignore
176 409 runcommand status -i -u
177 410 I ignored-file
411
412 >>> import os
413 >>> from hgclient import readchannel, sep, runcommand, check
414 >>> @check
415 ... def phasecacheafterstrip(server):
416 ... readchannel(server)
417 ...
418 ... # create new head, 5:731265503d86
419 ... runcommand(server, ['update', '-C', '0'])
420 ... f = open('a', 'ab')
421 ... f.write('a\n')
422 ... f.close()
423 ... runcommand(server, ['commit', '-Am.', 'a'])
424 ... runcommand(server, ['log', '-Gq'])
425 ...
426 ... # make it public; draft marker moves to 4:7966c8e3734d
427 ... runcommand(server, ['phase', '-p', '.'])
428 ... # load _phasecache.phaseroots
429 ... runcommand(server, ['phase', '.'], outfilter=sep)
430 ...
431 ... # strip 1::4 outside server
432 ... os.system('hg -q --config extensions.mq= strip 1')
433 ...
434 ... # shouldn't raise "7966c8e3734d: no node!"
435 ... runcommand(server, ['branches'])
178 436
179 437 testing phasecacheafterstrip:
180 438
@@ -201,6 +459,30 b''
201 459 5: public
202 460 runcommand branches
203 461 default 1:731265503d86
462
463 $ cat <<EOF > obs.py
464 > import mercurial.obsolete
465 > mercurial.obsolete._enabled = True
466 > EOF
467 $ cat <<EOF >> .hg/hgrc
468 > [extensions]
469 > obs = obs.py
470 > EOF
471
472 >>> import os
473 >>> from hgclient import readchannel, runcommand, check
474 >>> @check
475 ... def obsolete(server):
476 ... readchannel(server)
477 ...
478 ... runcommand(server, ['up', 'null'])
479 ... runcommand(server, ['phase', '-df', 'tip'])
480 ... cmd = 'hg debugobsolete `hg log -r tip --template {node}`'
481 ... if os.name == 'nt':
482 ... cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
483 ... os.system(cmd)
484 ... runcommand(server, ['log', '--hidden'])
485 ... runcommand(server, ['log'])
204 486
205 487 testing obsolete:
206 488
@@ -232,6 +514,28 b''
232 514 date: Thu Jan 01 00:00:00 1970 +0000
233 515 summary: 1
234 516
517
518 $ cat <<EOF >> .hg/hgrc
519 > [extensions]
520 > mq =
521 > EOF
522
523 >>> import os
524 >>> from hgclient import readchannel, runcommand, check
525 >>> @check
526 ... def mqoutsidechanges(server):
527 ... readchannel(server)
528 ...
529 ... # load repo.mq
530 ... runcommand(server, ['qapplied'])
531 ... os.system('hg qnew 0.diff')
532 ... # repo.mq should be invalidated
533 ... runcommand(server, ['qapplied'])
534 ...
535 ... runcommand(server, ['qpop', '--all'])
536 ... os.system('hg qqueue --create foo')
537 ... # repo.mq should be recreated to point to new queue
538 ... runcommand(server, ['qqueue', '--active'])
235 539
236 540 testing mqoutsidechanges:
237 541
@@ -243,11 +547,51 b''
243 547 patch queue now empty
244 548 runcommand qqueue --active
245 549 foo
550
551 $ cat <<EOF > dbgui.py
552 > from mercurial import cmdutil, commands
553 > cmdtable = {}
554 > command = cmdutil.command(cmdtable)
555 > @command("debuggetpass", norepo=True)
556 > def debuggetpass(ui):
557 > ui.write("%s\\n" % ui.getpass())
558 > EOF
559 $ cat <<EOF >> .hg/hgrc
560 > [extensions]
561 > dbgui = dbgui.py
562 > EOF
563
564 >>> import cStringIO
565 >>> from hgclient import readchannel, runcommand, check
566 >>> @check
567 ... def getpass(server):
568 ... readchannel(server)
569 ... runcommand(server, ['debuggetpass', '--config',
570 ... 'ui.interactive=True'],
571 ... input=cStringIO.StringIO('1234\n'))
246 572
247 573 testing getpass:
248 574
249 575 runcommand debuggetpass --config ui.interactive=True
250 576 password: 1234
577
578
579 start without repository:
580
581 $ cd ..
582
583 >>> import re
584 >>> from hgclient import readchannel, runcommand, check
585 >>> @check
586 ... def hellomessage(server):
587 ... ch, data = readchannel(server)
588 ... # escaping python tests output not supported
589 ... print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+',
590 ... 'encoding: ***', data))
591 ...
592 ... # run an arbitrary command to make sure the next thing the server
593 ... # sends isn't part of the hello message
594 ... runcommand(server, ['id'])
251 595
252 596 testing hellomessage:
253 597
@@ -255,6 +599,13 b''
255 599 runcommand id
256 600 abort: there is no Mercurial repository here (.hg not found)
257 601 [255]
602
603 >>> from hgclient import readchannel, runcommand, check
604 >>> @check
605 ... def startwithoutrepo(server):
606 ... readchannel(server)
607 ... runcommand(server, ['init', 'repo2'])
608 ... runcommand(server, ['id', '-R', 'repo2'])
258 609
259 610 testing startwithoutrepo:
260 611
General Comments 0
You need to be logged in to leave comments. Login now