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