comparison tests/test-commandserver.t @ 33922:1a6707b43d05

tests: update test-commandserver to pass our import checker
author Augie Fackler <raf@durin42.com>
date Tue, 22 Aug 2017 14:26:25 -0400
parents a4c1333b2eda
children 989e884d1be9
comparison
equal deleted inserted replaced
33921:a4c1333b2eda 33922:1a6707b43d05
11 $ mv $HGRCPATH.new $HGRCPATH 11 $ mv $HGRCPATH.new $HGRCPATH
12 12
13 $ hg init repo 13 $ hg init repo
14 $ cd repo 14 $ cd repo
15 15
16 >>> from __future__ import print_function 16 >>> from __future__ import absolute_import, print_function
17 >>> from hgclient import readchannel, runcommand, check 17 >>> import os
18 >>> import sys
19 >>> from hgclient import check, readchannel, runcommand
18 >>> @check 20 >>> @check
19 ... def hellomessage(server): 21 ... def hellomessage(server):
20 ... ch, data = readchannel(server) 22 ... ch, data = readchannel(server)
21 ... print('%c, %r' % (ch, data)) 23 ... print('%c, %r' % (ch, data))
22 ... # run an arbitrary command to make sure the next thing the server 24 ... # run an arbitrary command to make sure the next thing the server
30 >>> @check 32 >>> @check
31 ... def unknowncommand(server): 33 ... def unknowncommand(server):
32 ... server.stdin.write('unknowncommand\n') 34 ... server.stdin.write('unknowncommand\n')
33 abort: unknown command unknowncommand 35 abort: unknown command unknowncommand
34 36
35 >>> from hgclient import readchannel, runcommand, check 37 >>> from hgclient import check, readchannel, runcommand
36 >>> @check 38 >>> @check
37 ... def checkruncommand(server): 39 ... def checkruncommand(server):
38 ... # hello block 40 ... # hello block
39 ... readchannel(server) 41 ... readchannel(server)
40 ... 42 ...
89 000000000000 tip 91 000000000000 tip
90 *** runcommand id -runknown 92 *** runcommand id -runknown
91 abort: unknown revision 'unknown'! 93 abort: unknown revision 'unknown'!
92 [255] 94 [255]
93 95
94 >>> from hgclient import readchannel, check 96 >>> from hgclient import check, readchannel
95 >>> @check 97 >>> @check
96 ... def inputeof(server): 98 ... def inputeof(server):
97 ... readchannel(server) 99 ... readchannel(server)
98 ... server.stdin.write('runcommand\n') 100 ... server.stdin.write('runcommand\n')
99 ... # close stdin while server is waiting for input 101 ... # close stdin while server is waiting for input
101 ... 103 ...
102 ... # server exits with 1 if the pipe closed while reading the command 104 ... # server exits with 1 if the pipe closed while reading the command
103 ... print('server exit code =', server.wait()) 105 ... print('server exit code =', server.wait())
104 server exit code = 1 106 server exit code = 1
105 107
106 >>> from hgclient import readchannel, runcommand, check, stringio 108 >>> from hgclient import check, readchannel, runcommand, stringio
107 >>> @check 109 >>> @check
108 ... def serverinput(server): 110 ... def serverinput(server):
109 ... readchannel(server) 111 ... readchannel(server)
110 ... 112 ...
111 ... patch = """ 113 ... patch = """
136 138
137 139
138 check that "histedit --commands=-" can read rules from the input channel: 140 check that "histedit --commands=-" can read rules from the input channel:
139 141
140 >>> import cStringIO 142 >>> import cStringIO
141 >>> from hgclient import readchannel, runcommand, check 143 >>> from hgclient import check, readchannel, runcommand
142 >>> @check 144 >>> @check
143 ... def serverinput(server): 145 ... def serverinput(server):
144 ... readchannel(server) 146 ... readchannel(server)
145 ... rules = 'pick eff892de26ec\n' 147 ... rules = 'pick eff892de26ec\n'
146 ... runcommand(server, ['histedit', '0', '--commands=-', 148 ... runcommand(server, ['histedit', '0', '--commands=-',
150 152
151 check that --cwd doesn't persist between requests: 153 check that --cwd doesn't persist between requests:
152 154
153 $ mkdir foo 155 $ mkdir foo
154 $ touch foo/bar 156 $ touch foo/bar
155 >>> from hgclient import readchannel, runcommand, check 157 >>> from hgclient import check, readchannel, runcommand
156 >>> @check 158 >>> @check
157 ... def cwd(server): 159 ... def cwd(server):
158 ... readchannel(server) 160 ... readchannel(server)
159 ... runcommand(server, ['--cwd', 'foo', 'st', 'bar']) 161 ... runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
160 ... runcommand(server, ['st', 'foo/bar']) 162 ... runcommand(server, ['st', 'foo/bar'])
171 $ cat <<EOF >> .hg/hgrc 173 $ cat <<EOF >> .hg/hgrc
172 > [ui] 174 > [ui]
173 > foo = bar 175 > foo = bar
174 > EOF 176 > EOF
175 177
176 >>> from hgclient import readchannel, sep, runcommand, check 178 >>> from hgclient import check, readchannel, runcommand, sep
177 >>> @check 179 >>> @check
178 ... def localhgrc(server): 180 ... def localhgrc(server):
179 ... readchannel(server) 181 ... readchannel(server)
180 ... 182 ...
181 ... # the cached repo local hgrc contains ui.foo=bar, so showconfig should 183 ... # the cached repo local hgrc contains ui.foo=bar, so showconfig should
221 > def hook(**args): 223 > def hook(**args):
222 > print('hook talking') 224 > print('hook talking')
223 > print('now try to read something: %r' % sys.stdin.read()) 225 > print('now try to read something: %r' % sys.stdin.read())
224 > EOF 226 > EOF
225 227
226 >>> from hgclient import readchannel, runcommand, check, stringio 228 >>> from hgclient import check, readchannel, runcommand, stringio
227 >>> @check 229 >>> @check
228 ... def hookoutput(server): 230 ... def hookoutput(server):
229 ... readchannel(server) 231 ... readchannel(server)
230 ... runcommand(server, ['--config', 232 ... runcommand(server, ['--config',
231 ... 'hooks.pre-identify=python:hook.hook', 233 ... 'hooks.pre-identify=python:hook.hook',
238 $ rm hook.py* 240 $ rm hook.py*
239 $ rm -Rf __pycache__ 241 $ rm -Rf __pycache__
240 242
241 $ echo a >> a 243 $ echo a >> a
242 >>> import os 244 >>> import os
243 >>> from hgclient import readchannel, runcommand, check 245 >>> from hgclient import check, readchannel, runcommand
244 >>> @check 246 >>> @check
245 ... def outsidechanges(server): 247 ... def outsidechanges(server):
246 ... readchannel(server) 248 ... readchannel(server)
247 ... runcommand(server, ['status']) 249 ... runcommand(server, ['status'])
248 ... os.system('hg ci -Am2') 250 ... os.system('hg ci -Am2')
258 summary: 2 260 summary: 2
259 261
260 *** runcommand status 262 *** runcommand status
261 263
262 >>> import os 264 >>> import os
263 >>> from hgclient import readchannel, runcommand, check 265 >>> from hgclient import check, readchannel, runcommand
264 >>> @check 266 >>> @check
265 ... def bookmarks(server): 267 ... def bookmarks(server):
266 ... readchannel(server) 268 ... readchannel(server)
267 ... runcommand(server, ['bookmarks']) 269 ... runcommand(server, ['bookmarks'])
268 ... 270 ...
297 bm2 1:d3a0a68be6de 299 bm2 1:d3a0a68be6de
298 * bm3 2:aef17e88f5f0 300 * bm3 2:aef17e88f5f0
299 301
300 302
301 >>> import os 303 >>> import os
302 >>> from hgclient import readchannel, runcommand, check 304 >>> from hgclient import check, readchannel, runcommand
303 >>> @check 305 >>> @check
304 ... def tagscache(server): 306 ... def tagscache(server):
305 ... readchannel(server) 307 ... readchannel(server)
306 ... runcommand(server, ['id', '-t', '-r', '0']) 308 ... runcommand(server, ['id', '-t', '-r', '0'])
307 ... os.system('hg tag -r 0 foo') 309 ... os.system('hg tag -r 0 foo')
310 312
311 *** runcommand id -t -r 0 313 *** runcommand id -t -r 0
312 foo 314 foo
313 315
314 >>> import os 316 >>> import os
315 >>> from hgclient import readchannel, runcommand, check 317 >>> from hgclient import check, readchannel, runcommand
316 >>> @check 318 >>> @check
317 ... def setphase(server): 319 ... def setphase(server):
318 ... readchannel(server) 320 ... readchannel(server)
319 ... runcommand(server, ['phase', '-r', '.']) 321 ... runcommand(server, ['phase', '-r', '.'])
320 ... os.system('hg phase -r . -p') 322 ... os.system('hg phase -r . -p')
323 3: draft 325 3: draft
324 *** runcommand phase -r . 326 *** runcommand phase -r .
325 3: public 327 3: public
326 328
327 $ echo a >> a 329 $ echo a >> a
328 >>> from hgclient import readchannel, runcommand, check 330 >>> from hgclient import check, readchannel, runcommand
329 >>> @check 331 >>> @check
330 ... def rollback(server): 332 ... def rollback(server):
331 ... readchannel(server) 333 ... readchannel(server)
332 ... runcommand(server, ['phase', '-r', '.', '-p']) 334 ... runcommand(server, ['phase', '-r', '.', '-p'])
333 ... runcommand(server, ['commit', '-Am.']) 335 ... runcommand(server, ['commit', '-Am.'])
343 *** runcommand phase -r . 345 *** runcommand phase -r .
344 3: public 346 3: public
345 347
346 348
347 >>> import os 349 >>> import os
348 >>> from hgclient import readchannel, runcommand, check 350 >>> from hgclient import check, readchannel, runcommand
349 >>> @check 351 >>> @check
350 ... def branch(server): 352 ... def branch(server):
351 ... readchannel(server) 353 ... readchannel(server)
352 ... runcommand(server, ['branch']) 354 ... runcommand(server, ['branch'])
353 ... os.system('hg branch foo') 355 ... os.system('hg branch foo')
362 marked working directory as branch default 364 marked working directory as branch default
363 (branches are permanent and global, did you want a bookmark?) 365 (branches are permanent and global, did you want a bookmark?)
364 366
365 $ touch .hgignore 367 $ touch .hgignore
366 >>> import os 368 >>> import os
367 >>> from hgclient import readchannel, runcommand, check 369 >>> from hgclient import check, readchannel, runcommand
368 >>> @check 370 >>> @check
369 ... def hgignore(server): 371 ... def hgignore(server):
370 ... readchannel(server) 372 ... readchannel(server)
371 ... runcommand(server, ['commit', '-Am.']) 373 ... runcommand(server, ['commit', '-Am.'])
372 ... f = open('ignored-file', 'ab') 374 ... f = open('ignored-file', 'ab')
385 387
386 cache of non-public revisions should be invalidated on repository change 388 cache of non-public revisions should be invalidated on repository change
387 (issue4855): 389 (issue4855):
388 390
389 >>> import os 391 >>> import os
390 >>> from hgclient import readchannel, runcommand, check 392 >>> from hgclient import check, readchannel, runcommand
391 >>> @check 393 >>> @check
392 ... def phasesetscacheaftercommit(server): 394 ... def phasesetscacheaftercommit(server):
393 ... readchannel(server) 395 ... readchannel(server)
394 ... # load _phasecache._phaserevs and _phasesets 396 ... # load _phasecache._phaserevs and _phasesets
395 ... runcommand(server, ['log', '-qr', 'draft()']) 397 ... runcommand(server, ['log', '-qr', 'draft()'])
410 5:41f6602d1c4f 412 5:41f6602d1c4f
411 6:10501e202c35 413 6:10501e202c35
412 414
413 415
414 >>> import os 416 >>> import os
415 >>> from hgclient import readchannel, runcommand, check 417 >>> from hgclient import check, readchannel, runcommand
416 >>> @check 418 >>> @check
417 ... def phasesetscacheafterstrip(server): 419 ... def phasesetscacheafterstrip(server):
418 ... readchannel(server) 420 ... readchannel(server)
419 ... # load _phasecache._phaserevs and _phasesets 421 ... # load _phasecache._phaserevs and _phasesets
420 ... runcommand(server, ['log', '-qr', 'draft()']) 422 ... runcommand(server, ['log', '-qr', 'draft()'])
432 434
433 435
434 cache of phase roots should be invalidated on strip (issue3827): 436 cache of phase roots should be invalidated on strip (issue3827):
435 437
436 >>> import os 438 >>> import os
437 >>> from hgclient import readchannel, sep, runcommand, check 439 >>> from hgclient import check, readchannel, runcommand, sep
438 >>> @check 440 >>> @check
439 ... def phasecacheafterstrip(server): 441 ... def phasecacheafterstrip(server):
440 ... readchannel(server) 442 ... readchannel(server)
441 ... 443 ...
442 ... # create new head, 5:731265503d86 444 ... # create new head, 5:731265503d86
483 485
484 in-memory cache must be reloaded if transaction is aborted. otherwise 486 in-memory cache must be reloaded if transaction is aborted. otherwise
485 changelog and manifest would have invalid node: 487 changelog and manifest would have invalid node:
486 488
487 $ echo a >> a 489 $ echo a >> a
488 >>> from hgclient import readchannel, runcommand, check 490 >>> from hgclient import check, readchannel, runcommand
489 >>> @check 491 >>> @check
490 ... def txabort(server): 492 ... def txabort(server):
491 ... readchannel(server) 493 ... readchannel(server)
492 ... runcommand(server, ['commit', '--config', 'hooks.pretxncommit=false', 494 ... runcommand(server, ['commit', '--config', 'hooks.pretxncommit=false',
493 ... '-mfoo']) 495 ... '-mfoo'])
509 > [experimental] 511 > [experimental]
510 > stabilization=createmarkers 512 > stabilization=createmarkers
511 > EOF 513 > EOF
512 514
513 >>> import os 515 >>> import os
514 >>> from hgclient import readchannel, runcommand, check 516 >>> from hgclient import check, readchannel, runcommand
515 >>> @check 517 >>> @check
516 ... def obsolete(server): 518 ... def obsolete(server):
517 ... readchannel(server) 519 ... readchannel(server)
518 ... 520 ...
519 ... runcommand(server, ['up', 'null']) 521 ... runcommand(server, ['up', 'null'])
558 > [extensions] 560 > [extensions]
559 > mq = 561 > mq =
560 > EOF 562 > EOF
561 563
562 >>> import os 564 >>> import os
563 >>> from hgclient import readchannel, runcommand, check 565 >>> from hgclient import check, readchannel, runcommand
564 >>> @check 566 >>> @check
565 ... def mqoutsidechanges(server): 567 ... def mqoutsidechanges(server):
566 ... readchannel(server) 568 ... readchannel(server)
567 ... 569 ...
568 ... # load repo.mq 570 ... # load repo.mq
583 patch queue now empty 585 patch queue now empty
584 *** runcommand qqueue --active 586 *** runcommand qqueue --active
585 foo 587 foo
586 588
587 $ cat <<EOF > dbgui.py 589 $ cat <<EOF > dbgui.py
588 > import os, sys 590 > import os
591 > import sys
589 > from mercurial import commands, registrar 592 > from mercurial import commands, registrar
590 > cmdtable = {} 593 > cmdtable = {}
591 > command = registrar.command(cmdtable) 594 > command = registrar.command(cmdtable)
592 > @command(b"debuggetpass", norepo=True) 595 > @command(b"debuggetpass", norepo=True)
593 > def debuggetpass(ui): 596 > def debuggetpass(ui):
607 $ cat <<EOF >> .hg/hgrc 610 $ cat <<EOF >> .hg/hgrc
608 > [extensions] 611 > [extensions]
609 > dbgui = dbgui.py 612 > dbgui = dbgui.py
610 > EOF 613 > EOF
611 614
612 >>> from hgclient import readchannel, runcommand, check, stringio 615 >>> from hgclient import check, readchannel, runcommand, stringio
613 >>> @check 616 >>> @check
614 ... def getpass(server): 617 ... def getpass(server):
615 ... readchannel(server) 618 ... readchannel(server)
616 ... runcommand(server, ['debuggetpass', '--config', 619 ... runcommand(server, ['debuggetpass', '--config',
617 ... 'ui.interactive=True'], 620 ... 'ui.interactive=True'],
642 645
643 646
644 run commandserver in commandserver, which is silly but should work: 647 run commandserver in commandserver, which is silly but should work:
645 648
646 >>> from __future__ import print_function 649 >>> from __future__ import print_function
647 >>> from hgclient import readchannel, runcommand, check, stringio 650 >>> from hgclient import check, readchannel, runcommand, stringio
648 >>> @check 651 >>> @check
649 ... def nested(server): 652 ... def nested(server):
650 ... print('%c, %r' % readchannel(server)) 653 ... print('%c, %r' % readchannel(server))
651 ... class nestedserver(object): 654 ... class nestedserver(object):
652 ... stdin = stringio('getencoding\n') 655 ... stdin = stringio('getencoding\n')
665 start without repository: 668 start without repository:
666 669
667 $ cd .. 670 $ cd ..
668 671
669 >>> from __future__ import print_function 672 >>> from __future__ import print_function
670 >>> from hgclient import readchannel, runcommand, check 673 >>> from hgclient import check, readchannel, runcommand
671 >>> @check 674 >>> @check
672 ... def hellomessage(server): 675 ... def hellomessage(server):
673 ... ch, data = readchannel(server) 676 ... ch, data = readchannel(server)
674 ... print('%c, %r' % (ch, data)) 677 ... print('%c, %r' % (ch, data))
675 ... # run an arbitrary command to make sure the next thing the server 678 ... # run an arbitrary command to make sure the next thing the server
678 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob) 681 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
679 *** runcommand id 682 *** runcommand id
680 abort: there is no Mercurial repository here (.hg not found) 683 abort: there is no Mercurial repository here (.hg not found)
681 [255] 684 [255]
682 685
683 >>> from hgclient import readchannel, runcommand, check 686 >>> from hgclient import check, readchannel, runcommand
684 >>> @check 687 >>> @check
685 ... def startwithoutrepo(server): 688 ... def startwithoutrepo(server):
686 ... readchannel(server) 689 ... readchannel(server)
687 ... runcommand(server, ['init', 'repo2']) 690 ... runcommand(server, ['init', 'repo2'])
688 ... runcommand(server, ['id', '-R', 'repo2']) 691 ... runcommand(server, ['id', '-R', 'repo2'])
706 $ hg update -q 709 $ hg update -q
707 710
708 #if unix-socket unix-permissions 711 #if unix-socket unix-permissions
709 712
710 >>> from __future__ import print_function 713 >>> from __future__ import print_function
711 >>> from hgclient import unixserver, readchannel, runcommand, check, stringio 714 >>> from hgclient import check, readchannel, runcommand, stringio, unixserver
712 >>> server = unixserver('.hg/server.sock', '.hg/server.log') 715 >>> server = unixserver('.hg/server.sock', '.hg/server.log')
713 >>> def hellomessage(conn): 716 >>> def hellomessage(conn):
714 ... ch, data = readchannel(conn) 717 ... ch, data = readchannel(conn)
715 ... print('%c, %r' % (ch, data)) 718 ... print('%c, %r' % (ch, data))
716 ... runcommand(conn, ['id']) 719 ... runcommand(conn, ['id'])
758 $ cat <<EOF >> .hg/hgrc 761 $ cat <<EOF >> .hg/hgrc
759 > [cmdserver] 762 > [cmdserver]
760 > log = inexistent/path.log 763 > log = inexistent/path.log
761 > EOF 764 > EOF
762 >>> from __future__ import print_function 765 >>> from __future__ import print_function
763 >>> from hgclient import unixserver, readchannel, check 766 >>> from hgclient import check, readchannel, unixserver
764 >>> server = unixserver('.hg/server.sock', '.hg/server.log') 767 >>> server = unixserver('.hg/server.sock', '.hg/server.log')
765 >>> def earlycrash(conn): 768 >>> def earlycrash(conn):
766 ... while True: 769 ... while True:
767 ... try: 770 ... try:
768 ... ch, data = readchannel(conn) 771 ... ch, data = readchannel(conn)
835 $ echo foo > foo 838 $ echo foo > foo
836 $ hg add foo 839 $ hg add foo
837 840
838 (failure before finalization) 841 (failure before finalization)
839 842
840 >>> from hgclient import readchannel, runcommand, check 843 >>> from hgclient import check, readchannel, runcommand
841 >>> @check 844 >>> @check
842 ... def abort(server): 845 ... def abort(server):
843 ... readchannel(server) 846 ... readchannel(server)
844 ... runcommand(server, ['commit', 847 ... runcommand(server, ['commit',
845 ... '--config', 'hooks.pretxncommit=false', 848 ... '--config', 'hooks.pretxncommit=false',
854 *** runcommand log 857 *** runcommand log
855 *** runcommand verify -q 858 *** runcommand verify -q
856 859
857 (failure after finalization) 860 (failure after finalization)
858 861
859 >>> from hgclient import readchannel, runcommand, check 862 >>> from hgclient import check, readchannel, runcommand
860 >>> @check 863 >>> @check
861 ... def abort(server): 864 ... def abort(server):
862 ... readchannel(server) 865 ... readchannel(server)
863 ... runcommand(server, ['commit', 866 ... runcommand(server, ['commit',
864 ... '--config', 'failafterfinalize.fail=true', 867 ... '--config', 'failafterfinalize.fail=true',
879 $ hg add bar 882 $ hg add bar
880 $ hg commit -mbar bar 883 $ hg commit -mbar bar
881 884
882 (failure before finalization) 885 (failure before finalization)
883 886
884 >>> from hgclient import readchannel, runcommand, check 887 >>> from hgclient import check, readchannel, runcommand
885 >>> @check 888 >>> @check
886 ... def abort(server): 889 ... def abort(server):
887 ... readchannel(server) 890 ... readchannel(server)
888 ... runcommand(server, ['commit', 891 ... runcommand(server, ['commit',
889 ... '--config', 'hooks.pretxncommit=false', 892 ... '--config', 'hooks.pretxncommit=false',
899 0 bar (bar) 902 0 bar (bar)
900 *** runcommand verify -q 903 *** runcommand verify -q
901 904
902 (failure after finalization) 905 (failure after finalization)
903 906
904 >>> from hgclient import readchannel, runcommand, check 907 >>> from hgclient import check, readchannel, runcommand
905 >>> @check 908 >>> @check
906 ... def abort(server): 909 ... def abort(server):
907 ... readchannel(server) 910 ... readchannel(server)
908 ... runcommand(server, ['commit', 911 ... runcommand(server, ['commit',
909 ... '--config', 'failafterfinalize.fail=true', 912 ... '--config', 'failafterfinalize.fail=true',
949 952
950 try trivial merge after update: cache of audited paths should be discarded, 953 try trivial merge after update: cache of audited paths should be discarded,
951 and the merge should fail (issue5628) 954 and the merge should fail (issue5628)
952 955
953 $ hg up -q null 956 $ hg up -q null
954 >>> from hgclient import readchannel, runcommand, check 957 >>> from hgclient import check, readchannel, runcommand
955 >>> @check 958 >>> @check
956 ... def merge(server): 959 ... def merge(server):
957 ... readchannel(server) 960 ... readchannel(server)
958 ... # audit a/poisoned as a good path 961 ... # audit a/poisoned as a good path
959 ... runcommand(server, ['up', '-qC', '2']) 962 ... runcommand(server, ['up', '-qC', '2'])
970 cache of repo.auditor should be discarded, so matcher would never traverse 973 cache of repo.auditor should be discarded, so matcher would never traverse
971 symlinks: 974 symlinks:
972 975
973 $ hg up -qC 0 976 $ hg up -qC 0
974 $ touch ../merge-symlink-out/poisoned 977 $ touch ../merge-symlink-out/poisoned
975 >>> from hgclient import readchannel, runcommand, check 978 >>> from hgclient import check, readchannel, runcommand
976 >>> @check 979 >>> @check
977 ... def files(server): 980 ... def files(server):
978 ... readchannel(server) 981 ... readchannel(server)
979 ... runcommand(server, ['up', '-qC', '2']) 982 ... runcommand(server, ['up', '-qC', '2'])
980 ... # audit a/poisoned as a good path 983 ... # audit a/poisoned as a good path