##// END OF EJS Templates
test-commandserver: remove redundant banner output...
Yuya Nishihara -
r22570:db497a1e default
parent child Browse files
Show More
@@ -1,75 +1,72 b''
1 1 # A minimal client for Mercurial's command server
2 2
3 3 import sys, struct, subprocess, cStringIO
4 4
5 5 def connect(path=None):
6 6 cmdline = ['hg', 'serve', '--cmdserver', 'pipe']
7 7 if path:
8 8 cmdline += ['-R', path]
9 9
10 10 server = subprocess.Popen(cmdline, stdin=subprocess.PIPE,
11 11 stdout=subprocess.PIPE)
12 12
13 13 return server
14 14
15 15 def writeblock(server, data):
16 16 server.stdin.write(struct.pack('>I', len(data)))
17 17 server.stdin.write(data)
18 18 server.stdin.flush()
19 19
20 20 def readchannel(server):
21 21 data = server.stdout.read(5)
22 22 if not data:
23 23 raise EOFError
24 24 channel, length = struct.unpack('>cI', data)
25 25 if channel in 'IL':
26 26 return channel, length
27 27 else:
28 28 return channel, server.stdout.read(length)
29 29
30 30 def sep(text):
31 31 return text.replace('\\', '/')
32 32
33 33 def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None,
34 34 outfilter=lambda x: x):
35 35 print ' runcommand', ' '.join(args)
36 36 sys.stdout.flush()
37 37 server.stdin.write('runcommand\n')
38 38 writeblock(server, '\0'.join(args))
39 39
40 40 if not input:
41 41 input = cStringIO.StringIO()
42 42
43 43 while True:
44 44 ch, data = readchannel(server)
45 45 if ch == 'o':
46 46 output.write(outfilter(data))
47 47 output.flush()
48 48 elif ch == 'e':
49 49 error.write(data)
50 50 error.flush()
51 51 elif ch == 'I':
52 52 writeblock(server, input.read(data))
53 53 elif ch == 'L':
54 54 writeblock(server, input.readline(data))
55 55 elif ch == 'r':
56 56 ret, = struct.unpack('>i', data)
57 57 if ret != 0:
58 58 print ' [%d]' % ret
59 59 return ret
60 60 else:
61 61 print "unexpected channel %c: %r" % (ch, data)
62 62 if ch.isupper():
63 63 return
64 64
65 65 def check(func, repopath=None):
66 print
67 print 'testing %s:' % func.__name__
68 print
69 66 sys.stdout.flush()
70 67 server = connect(repopath)
71 68 try:
72 69 return func(server)
73 70 finally:
74 71 server.stdin.close()
75 72 server.wait()
@@ -1,614 +1,551 b''
1 1 #if windows
2 2 $ PYTHONPATH="$TESTDIR/../contrib;$PYTHONPATH"
3 3 #else
4 4 $ PYTHONPATH="$TESTDIR/../contrib:$PYTHONPATH"
5 5 #endif
6 6 $ export PYTHONPATH
7 7
8 8 $ hg init repo
9 9 $ cd repo
10 10
11 11 >>> import re
12 12 >>> from hgclient import readchannel, runcommand, check
13 13 >>> @check
14 14 ... def hellomessage(server):
15 15 ... ch, data = readchannel(server)
16 16 ... # escaping python tests output not supported
17 17 ... print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+',
18 18 ... 'encoding: ***', data))
19 19 ...
20 20 ... # run an arbitrary command to make sure the next thing the server
21 21 ... # sends isn't part of the hello message
22 22 ... runcommand(server, ['id'])
23
24 testing hellomessage:
25
26 23 o, 'capabilities: getencoding runcommand\nencoding: ***'
27 24 runcommand id
28 25 000000000000 tip
29 26
30 27 >>> from hgclient import check
31 28 >>> @check
32 29 ... def unknowncommand(server):
33 30 ... server.stdin.write('unknowncommand\n')
34
35 testing unknowncommand:
36
37 31 abort: unknown command unknowncommand
38 32
39 33 >>> from hgclient import readchannel, runcommand, check
40 34 >>> @check
41 35 ... def checkruncommand(server):
42 36 ... # hello block
43 37 ... readchannel(server)
44 38 ...
45 39 ... # no args
46 40 ... runcommand(server, [])
47 41 ...
48 42 ... # global options
49 43 ... runcommand(server, ['id', '--quiet'])
50 44 ...
51 45 ... # make sure global options don't stick through requests
52 46 ... runcommand(server, ['id'])
53 47 ...
54 48 ... # --config
55 49 ... runcommand(server, ['id', '--config', 'ui.quiet=True'])
56 50 ...
57 51 ... # make sure --config doesn't stick
58 52 ... runcommand(server, ['id'])
59 53 ...
60 54 ... # negative return code should be masked
61 55 ... runcommand(server, ['id', '-runknown'])
62
63 testing checkruncommand:
64
65 56 runcommand
66 57 Mercurial Distributed SCM
67 58
68 59 basic commands:
69 60
70 61 add add the specified files on the next commit
71 62 annotate show changeset information by line for each file
72 63 clone make a copy of an existing repository
73 64 commit commit the specified files or all outstanding changes
74 65 diff diff repository (or selected files)
75 66 export dump the header and diffs for one or more changesets
76 67 forget forget the specified files on the next commit
77 68 init create a new repository in the given directory
78 69 log show revision history of entire repository or files
79 70 merge merge working directory with another revision
80 71 pull pull changes from the specified source
81 72 push push changes to the specified destination
82 73 remove remove the specified files on the next commit
83 74 serve start stand-alone webserver
84 75 status show changed files in the working directory
85 76 summary summarize working directory state
86 77 update update working directory (or switch revisions)
87 78
88 79 (use "hg help" for the full list of commands or "hg -v" for details)
89 80 runcommand id --quiet
90 81 000000000000
91 82 runcommand id
92 83 000000000000 tip
93 84 runcommand id --config ui.quiet=True
94 85 000000000000
95 86 runcommand id
96 87 000000000000 tip
97 88 runcommand id -runknown
98 89 abort: unknown revision 'unknown'!
99 90 [255]
100 91
101 92 >>> from hgclient import readchannel, check
102 93 >>> @check
103 94 ... def inputeof(server):
104 95 ... readchannel(server)
105 96 ... server.stdin.write('runcommand\n')
106 97 ... # close stdin while server is waiting for input
107 98 ... server.stdin.close()
108 99 ...
109 100 ... # server exits with 1 if the pipe closed while reading the command
110 101 ... print 'server exit code =', server.wait()
111
112 testing inputeof:
113
114 102 server exit code = 1
115 103
116 104 >>> import cStringIO
117 105 >>> from hgclient import readchannel, runcommand, check
118 106 >>> @check
119 107 ... def serverinput(server):
120 108 ... readchannel(server)
121 109 ...
122 110 ... patch = """
123 111 ... # HG changeset patch
124 112 ... # User test
125 113 ... # Date 0 0
126 114 ... # Node ID c103a3dec114d882c98382d684d8af798d09d857
127 115 ... # Parent 0000000000000000000000000000000000000000
128 116 ... 1
129 117 ...
130 118 ... diff -r 000000000000 -r c103a3dec114 a
131 119 ... --- /dev/null Thu Jan 01 00:00:00 1970 +0000
132 120 ... +++ b/a Thu Jan 01 00:00:00 1970 +0000
133 121 ... @@ -0,0 +1,1 @@
134 122 ... +1
135 123 ... """
136 124 ...
137 125 ... runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
138 126 ... runcommand(server, ['log'])
139
140 testing serverinput:
141
142 127 runcommand import -
143 128 applying patch from stdin
144 129 runcommand log
145 130 changeset: 0:eff892de26ec
146 131 tag: tip
147 132 user: test
148 133 date: Thu Jan 01 00:00:00 1970 +0000
149 134 summary: 1
150 135
151 136
152 137 check that --cwd doesn't persist between requests:
153 138
154 139 $ mkdir foo
155 140 $ touch foo/bar
156 141 >>> from hgclient import readchannel, runcommand, check
157 142 >>> @check
158 143 ... def cwd(server):
159 144 ... readchannel(server)
160 145 ... runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
161 146 ... runcommand(server, ['st', 'foo/bar'])
162
163 testing cwd:
164
165 147 runcommand --cwd foo st bar
166 148 ? bar
167 149 runcommand st foo/bar
168 150 ? foo/bar
169 151
170 152 $ rm foo/bar
171 153
172 154
173 155 check that local configs for the cached repo aren't inherited when -R is used:
174 156
175 157 $ cat <<EOF >> .hg/hgrc
176 158 > [ui]
177 159 > foo = bar
178 160 > EOF
179 161
180 162 >>> from hgclient import readchannel, sep, runcommand, check
181 163 >>> @check
182 164 ... def localhgrc(server):
183 165 ... readchannel(server)
184 166 ...
185 167 ... # the cached repo local hgrc contains ui.foo=bar, so showconfig should
186 168 ... # show it
187 169 ... runcommand(server, ['showconfig'], outfilter=sep)
188 170 ...
189 171 ... # but not for this repo
190 172 ... runcommand(server, ['init', 'foo'])
191 173 ... runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
192
193 testing localhgrc:
194
195 174 runcommand showconfig
196 175 bundle.mainreporoot=$TESTTMP/repo
197 176 defaults.backout=-d "0 0"
198 177 defaults.commit=-d "0 0"
199 178 defaults.shelve=--date "0 0"
200 179 defaults.tag=-d "0 0"
201 180 ui.slash=True
202 181 ui.interactive=False
203 182 ui.mergemarkers=detailed
204 183 ui.foo=bar
205 184 ui.nontty=true
206 185 runcommand init foo
207 186 runcommand -R foo showconfig ui defaults
208 187 defaults.backout=-d "0 0"
209 188 defaults.commit=-d "0 0"
210 189 defaults.shelve=--date "0 0"
211 190 defaults.tag=-d "0 0"
212 191 ui.slash=True
213 192 ui.interactive=False
214 193 ui.mergemarkers=detailed
215 194 ui.nontty=true
216 195
217 196 $ rm -R foo
218 197
219 198 #if windows
220 199 $ PYTHONPATH="$TESTTMP/repo;$PYTHONPATH"
221 200 #else
222 201 $ PYTHONPATH="$TESTTMP/repo:$PYTHONPATH"
223 202 #endif
224 203
225 204 $ cat <<EOF > hook.py
226 205 > import sys
227 206 > def hook(**args):
228 207 > print 'hook talking'
229 208 > print 'now try to read something: %r' % sys.stdin.read()
230 209 > EOF
231 210
232 211 >>> import cStringIO
233 212 >>> from hgclient import readchannel, runcommand, check
234 213 >>> @check
235 214 ... def hookoutput(server):
236 215 ... readchannel(server)
237 216 ... runcommand(server, ['--config',
238 217 ... 'hooks.pre-identify=python:hook.hook',
239 218 ... 'id'],
240 219 ... input=cStringIO.StringIO('some input'))
241
242 testing hookoutput:
243
244 220 runcommand --config hooks.pre-identify=python:hook.hook id
245 221 hook talking
246 222 now try to read something: 'some input'
247 223 eff892de26ec tip
248 224
249 225 $ rm hook.py*
250 226
251 227 $ echo a >> a
252 228 >>> import os
253 229 >>> from hgclient import readchannel, runcommand, check
254 230 >>> @check
255 231 ... def outsidechanges(server):
256 232 ... readchannel(server)
257 233 ... runcommand(server, ['status'])
258 234 ... os.system('hg ci -Am2')
259 235 ... runcommand(server, ['tip'])
260 236 ... runcommand(server, ['status'])
261
262 testing outsidechanges:
263
264 237 runcommand status
265 238 M a
266 239 runcommand tip
267 240 changeset: 1:d3a0a68be6de
268 241 tag: tip
269 242 user: test
270 243 date: Thu Jan 01 00:00:00 1970 +0000
271 244 summary: 2
272 245
273 246 runcommand status
274 247
275 248 >>> import os
276 249 >>> from hgclient import readchannel, runcommand, check
277 250 >>> @check
278 251 ... def bookmarks(server):
279 252 ... readchannel(server)
280 253 ... runcommand(server, ['bookmarks'])
281 254 ...
282 255 ... # changes .hg/bookmarks
283 256 ... os.system('hg bookmark -i bm1')
284 257 ... os.system('hg bookmark -i bm2')
285 258 ... runcommand(server, ['bookmarks'])
286 259 ...
287 260 ... # changes .hg/bookmarks.current
288 261 ... os.system('hg upd bm1 -q')
289 262 ... runcommand(server, ['bookmarks'])
290 263 ...
291 264 ... runcommand(server, ['bookmarks', 'bm3'])
292 265 ... f = open('a', 'ab')
293 266 ... f.write('a\n')
294 267 ... f.close()
295 268 ... runcommand(server, ['commit', '-Amm'])
296 269 ... runcommand(server, ['bookmarks'])
297
298 testing bookmarks:
299
300 270 runcommand bookmarks
301 271 no bookmarks set
302 272 runcommand bookmarks
303 273 bm1 1:d3a0a68be6de
304 274 bm2 1:d3a0a68be6de
305 275 runcommand bookmarks
306 276 * bm1 1:d3a0a68be6de
307 277 bm2 1:d3a0a68be6de
308 278 runcommand bookmarks bm3
309 279 runcommand commit -Amm
310 280 runcommand bookmarks
311 281 bm1 1:d3a0a68be6de
312 282 bm2 1:d3a0a68be6de
313 283 * bm3 2:aef17e88f5f0
314 284
315 285 >>> import os
316 286 >>> from hgclient import readchannel, runcommand, check
317 287 >>> @check
318 288 ... def tagscache(server):
319 289 ... readchannel(server)
320 290 ... runcommand(server, ['id', '-t', '-r', '0'])
321 291 ... os.system('hg tag -r 0 foo')
322 292 ... runcommand(server, ['id', '-t', '-r', '0'])
323
324 testing tagscache:
325
326 293 runcommand id -t -r 0
327 294
328 295 runcommand id -t -r 0
329 296 foo
330 297
331 298 >>> import os
332 299 >>> from hgclient import readchannel, runcommand, check
333 300 >>> @check
334 301 ... def setphase(server):
335 302 ... readchannel(server)
336 303 ... runcommand(server, ['phase', '-r', '.'])
337 304 ... os.system('hg phase -r . -p')
338 305 ... runcommand(server, ['phase', '-r', '.'])
339
340 testing setphase:
341
342 306 runcommand phase -r .
343 307 3: draft
344 308 runcommand phase -r .
345 309 3: public
346 310
347 311 $ echo a >> a
348 312 >>> from hgclient import readchannel, runcommand, check
349 313 >>> @check
350 314 ... def rollback(server):
351 315 ... readchannel(server)
352 316 ... runcommand(server, ['phase', '-r', '.', '-p'])
353 317 ... runcommand(server, ['commit', '-Am.'])
354 318 ... runcommand(server, ['rollback'])
355 319 ... runcommand(server, ['phase', '-r', '.'])
356
357 testing rollback:
358
359 320 runcommand phase -r . -p
360 321 no phases changed
361 322 [1]
362 323 runcommand commit -Am.
363 324 runcommand rollback
364 325 repository tip rolled back to revision 3 (undo commit)
365 326 working directory now based on revision 3
366 327 runcommand phase -r .
367 328 3: public
368 329
369 330 >>> import os
370 331 >>> from hgclient import readchannel, runcommand, check
371 332 >>> @check
372 333 ... def branch(server):
373 334 ... readchannel(server)
374 335 ... runcommand(server, ['branch'])
375 336 ... os.system('hg branch foo')
376 337 ... runcommand(server, ['branch'])
377 338 ... os.system('hg branch default')
378
379 testing branch:
380
381 339 runcommand branch
382 340 default
383 341 marked working directory as branch foo
384 342 (branches are permanent and global, did you want a bookmark?)
385 343 runcommand branch
386 344 foo
387 345 marked working directory as branch default
388 346 (branches are permanent and global, did you want a bookmark?)
389 347
390 348 $ touch .hgignore
391 349 >>> import os
392 350 >>> from hgclient import readchannel, runcommand, check
393 351 >>> @check
394 352 ... def hgignore(server):
395 353 ... readchannel(server)
396 354 ... runcommand(server, ['commit', '-Am.'])
397 355 ... f = open('ignored-file', 'ab')
398 356 ... f.write('')
399 357 ... f.close()
400 358 ... f = open('.hgignore', 'ab')
401 359 ... f.write('ignored-file')
402 360 ... f.close()
403 361 ... runcommand(server, ['status', '-i', '-u'])
404
405 testing hgignore:
406
407 362 runcommand commit -Am.
408 363 adding .hgignore
409 364 runcommand status -i -u
410 365 I ignored-file
411 366
412 367 >>> import os
413 368 >>> from hgclient import readchannel, sep, runcommand, check
414 369 >>> @check
415 370 ... def phasecacheafterstrip(server):
416 371 ... readchannel(server)
417 372 ...
418 373 ... # create new head, 5:731265503d86
419 374 ... runcommand(server, ['update', '-C', '0'])
420 375 ... f = open('a', 'ab')
421 376 ... f.write('a\n')
422 377 ... f.close()
423 378 ... runcommand(server, ['commit', '-Am.', 'a'])
424 379 ... runcommand(server, ['log', '-Gq'])
425 380 ...
426 381 ... # make it public; draft marker moves to 4:7966c8e3734d
427 382 ... runcommand(server, ['phase', '-p', '.'])
428 383 ... # load _phasecache.phaseroots
429 384 ... runcommand(server, ['phase', '.'], outfilter=sep)
430 385 ...
431 386 ... # strip 1::4 outside server
432 387 ... os.system('hg -q --config extensions.mq= strip 1')
433 388 ...
434 389 ... # shouldn't raise "7966c8e3734d: no node!"
435 390 ... runcommand(server, ['branches'])
436
437 testing phasecacheafterstrip:
438
439 391 runcommand update -C 0
440 392 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
441 393 (leaving bookmark bm3)
442 394 runcommand commit -Am. a
443 395 created new head
444 396 runcommand log -Gq
445 397 @ 5:731265503d86
446 398 |
447 399 | o 4:7966c8e3734d
448 400 | |
449 401 | o 3:b9b85890c400
450 402 | |
451 403 | o 2:aef17e88f5f0
452 404 | |
453 405 | o 1:d3a0a68be6de
454 406 |/
455 407 o 0:eff892de26ec
456 408
457 409 runcommand phase -p .
458 410 runcommand phase .
459 411 5: public
460 412 runcommand branches
461 413 default 1:731265503d86
462 414
463 415 $ cat <<EOF > obs.py
464 416 > import mercurial.obsolete
465 417 > mercurial.obsolete._enabled = True
466 418 > EOF
467 419 $ cat <<EOF >> .hg/hgrc
468 420 > [extensions]
469 421 > obs = obs.py
470 422 > EOF
471 423
472 424 >>> import os
473 425 >>> from hgclient import readchannel, runcommand, check
474 426 >>> @check
475 427 ... def obsolete(server):
476 428 ... readchannel(server)
477 429 ...
478 430 ... runcommand(server, ['up', 'null'])
479 431 ... runcommand(server, ['phase', '-df', 'tip'])
480 432 ... cmd = 'hg debugobsolete `hg log -r tip --template {node}`'
481 433 ... if os.name == 'nt':
482 434 ... cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
483 435 ... os.system(cmd)
484 436 ... runcommand(server, ['log', '--hidden'])
485 437 ... runcommand(server, ['log'])
486
487 testing obsolete:
488
489 438 runcommand up null
490 439 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
491 440 runcommand phase -df tip
492 441 runcommand log --hidden
493 442 changeset: 1:731265503d86
494 443 tag: tip
495 444 user: test
496 445 date: Thu Jan 01 00:00:00 1970 +0000
497 446 summary: .
498 447
499 448 changeset: 0:eff892de26ec
500 449 bookmark: bm1
501 450 bookmark: bm2
502 451 bookmark: bm3
503 452 user: test
504 453 date: Thu Jan 01 00:00:00 1970 +0000
505 454 summary: 1
506 455
507 456 runcommand log
508 457 changeset: 0:eff892de26ec
509 458 bookmark: bm1
510 459 bookmark: bm2
511 460 bookmark: bm3
512 461 tag: tip
513 462 user: test
514 463 date: Thu Jan 01 00:00:00 1970 +0000
515 464 summary: 1
516 465
517 466
518 467 $ cat <<EOF >> .hg/hgrc
519 468 > [extensions]
520 469 > mq =
521 470 > EOF
522 471
523 472 >>> import os
524 473 >>> from hgclient import readchannel, runcommand, check
525 474 >>> @check
526 475 ... def mqoutsidechanges(server):
527 476 ... readchannel(server)
528 477 ...
529 478 ... # load repo.mq
530 479 ... runcommand(server, ['qapplied'])
531 480 ... os.system('hg qnew 0.diff')
532 481 ... # repo.mq should be invalidated
533 482 ... runcommand(server, ['qapplied'])
534 483 ...
535 484 ... runcommand(server, ['qpop', '--all'])
536 485 ... os.system('hg qqueue --create foo')
537 486 ... # repo.mq should be recreated to point to new queue
538 487 ... runcommand(server, ['qqueue', '--active'])
539
540 testing mqoutsidechanges:
541
542 488 runcommand qapplied
543 489 runcommand qapplied
544 490 0.diff
545 491 runcommand qpop --all
546 492 popping 0.diff
547 493 patch queue now empty
548 494 runcommand qqueue --active
549 495 foo
550 496
551 497 $ cat <<EOF > dbgui.py
552 498 > from mercurial import cmdutil, commands
553 499 > cmdtable = {}
554 500 > command = cmdutil.command(cmdtable)
555 501 > @command("debuggetpass", norepo=True)
556 502 > def debuggetpass(ui):
557 503 > ui.write("%s\\n" % ui.getpass())
558 504 > EOF
559 505 $ cat <<EOF >> .hg/hgrc
560 506 > [extensions]
561 507 > dbgui = dbgui.py
562 508 > EOF
563 509
564 510 >>> import cStringIO
565 511 >>> from hgclient import readchannel, runcommand, check
566 512 >>> @check
567 513 ... def getpass(server):
568 514 ... readchannel(server)
569 515 ... runcommand(server, ['debuggetpass', '--config',
570 516 ... 'ui.interactive=True'],
571 517 ... input=cStringIO.StringIO('1234\n'))
572
573 testing getpass:
574
575 518 runcommand debuggetpass --config ui.interactive=True
576 519 password: 1234
577 520
578 521
579 522 start without repository:
580 523
581 524 $ cd ..
582 525
583 526 >>> import re
584 527 >>> from hgclient import readchannel, runcommand, check
585 528 >>> @check
586 529 ... def hellomessage(server):
587 530 ... ch, data = readchannel(server)
588 531 ... # escaping python tests output not supported
589 532 ... print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+',
590 533 ... 'encoding: ***', data))
591 534 ...
592 535 ... # run an arbitrary command to make sure the next thing the server
593 536 ... # sends isn't part of the hello message
594 537 ... runcommand(server, ['id'])
595
596 testing hellomessage:
597
598 538 o, 'capabilities: getencoding runcommand\nencoding: ***'
599 539 runcommand id
600 540 abort: there is no Mercurial repository here (.hg not found)
601 541 [255]
602 542
603 543 >>> from hgclient import readchannel, runcommand, check
604 544 >>> @check
605 545 ... def startwithoutrepo(server):
606 546 ... readchannel(server)
607 547 ... runcommand(server, ['init', 'repo2'])
608 548 ... runcommand(server, ['id', '-R', 'repo2'])
609
610 testing startwithoutrepo:
611
612 549 runcommand init repo2
613 550 runcommand id -R repo2
614 551 000000000000 tip
General Comments 0
You need to be logged in to leave comments. Login now