tests/test-commandserver.t
changeset 22572 cc3d9f776632
parent 22571 a9ff1b350f62
child 22783 524b786bd54f
equal deleted inserted replaced
22571:a9ff1b350f62 22572:cc3d9f776632
    15   ...     print '%c, %r' % (ch, data)
    15   ...     print '%c, %r' % (ch, data)
    16   ...     # run an arbitrary command to make sure the next thing the server
    16   ...     # run an arbitrary command to make sure the next thing the server
    17   ...     # sends isn't part of the hello message
    17   ...     # sends isn't part of the hello message
    18   ...     runcommand(server, ['id'])
    18   ...     runcommand(server, ['id'])
    19   o, 'capabilities: getencoding runcommand\nencoding: *' (glob)
    19   o, 'capabilities: getencoding runcommand\nencoding: *' (glob)
    20    runcommand id
    20   *** runcommand id
    21   000000000000 tip
    21   000000000000 tip
    22 
    22 
    23   >>> from hgclient import check
    23   >>> from hgclient import check
    24   >>> @check
    24   >>> @check
    25   ... def unknowncommand(server):
    25   ... def unknowncommand(server):
    47   ...     # make sure --config doesn't stick
    47   ...     # make sure --config doesn't stick
    48   ...     runcommand(server, ['id'])
    48   ...     runcommand(server, ['id'])
    49   ... 
    49   ... 
    50   ...     # negative return code should be masked
    50   ...     # negative return code should be masked
    51   ...     runcommand(server, ['id', '-runknown'])
    51   ...     runcommand(server, ['id', '-runknown'])
    52    runcommand 
    52   *** runcommand 
    53   Mercurial Distributed SCM
    53   Mercurial Distributed SCM
    54   
    54   
    55   basic commands:
    55   basic commands:
    56   
    56   
    57    add           add the specified files on the next commit
    57    add           add the specified files on the next commit
    71    status        show changed files in the working directory
    71    status        show changed files in the working directory
    72    summary       summarize working directory state
    72    summary       summarize working directory state
    73    update        update working directory (or switch revisions)
    73    update        update working directory (or switch revisions)
    74   
    74   
    75   (use "hg help" for the full list of commands or "hg -v" for details)
    75   (use "hg help" for the full list of commands or "hg -v" for details)
    76    runcommand id --quiet
    76   *** runcommand id --quiet
    77   000000000000
    77   000000000000
    78    runcommand id
    78   *** runcommand id
    79   000000000000 tip
    79   000000000000 tip
    80    runcommand id --config ui.quiet=True
    80   *** runcommand id --config ui.quiet=True
    81   000000000000
    81   000000000000
    82    runcommand id
    82   *** runcommand id
    83   000000000000 tip
    83   000000000000 tip
    84    runcommand id -runknown
    84   *** runcommand id -runknown
    85   abort: unknown revision 'unknown'!
    85   abort: unknown revision 'unknown'!
    86    [255]
    86    [255]
    87 
    87 
    88   >>> from hgclient import readchannel, check
    88   >>> from hgclient import readchannel, check
    89   >>> @check
    89   >>> @check
   118   ... +1
   118   ... +1
   119   ... """
   119   ... """
   120   ... 
   120   ... 
   121   ...     runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
   121   ...     runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
   122   ...     runcommand(server, ['log'])
   122   ...     runcommand(server, ['log'])
   123    runcommand import -
   123   *** runcommand import -
   124   applying patch from stdin
   124   applying patch from stdin
   125    runcommand log
   125   *** runcommand log
   126   changeset:   0:eff892de26ec
   126   changeset:   0:eff892de26ec
   127   tag:         tip
   127   tag:         tip
   128   user:        test
   128   user:        test
   129   date:        Thu Jan 01 00:00:00 1970 +0000
   129   date:        Thu Jan 01 00:00:00 1970 +0000
   130   summary:     1
   130   summary:     1
   138   >>> @check
   138   >>> @check
   139   ... def cwd(server):
   139   ... def cwd(server):
   140   ...     readchannel(server)
   140   ...     readchannel(server)
   141   ...     runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
   141   ...     runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
   142   ...     runcommand(server, ['st', 'foo/bar'])
   142   ...     runcommand(server, ['st', 'foo/bar'])
   143    runcommand --cwd foo st bar
   143   *** runcommand --cwd foo st bar
   144   ? bar
   144   ? bar
   145    runcommand st foo/bar
   145   *** runcommand st foo/bar
   146   ? foo/bar
   146   ? foo/bar
   147 
   147 
   148   $ rm foo/bar
   148   $ rm foo/bar
   149 
   149 
   150 
   150 
   165   ...     runcommand(server, ['showconfig'], outfilter=sep)
   165   ...     runcommand(server, ['showconfig'], outfilter=sep)
   166   ... 
   166   ... 
   167   ...     # but not for this repo
   167   ...     # but not for this repo
   168   ...     runcommand(server, ['init', 'foo'])
   168   ...     runcommand(server, ['init', 'foo'])
   169   ...     runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
   169   ...     runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
   170    runcommand showconfig
   170   *** runcommand showconfig
   171   bundle.mainreporoot=$TESTTMP/repo
   171   bundle.mainreporoot=$TESTTMP/repo
   172   defaults.backout=-d "0 0"
   172   defaults.backout=-d "0 0"
   173   defaults.commit=-d "0 0"
   173   defaults.commit=-d "0 0"
   174   defaults.shelve=--date "0 0"
   174   defaults.shelve=--date "0 0"
   175   defaults.tag=-d "0 0"
   175   defaults.tag=-d "0 0"
   176   ui.slash=True
   176   ui.slash=True
   177   ui.interactive=False
   177   ui.interactive=False
   178   ui.mergemarkers=detailed
   178   ui.mergemarkers=detailed
   179   ui.foo=bar
   179   ui.foo=bar
   180   ui.nontty=true
   180   ui.nontty=true
   181    runcommand init foo
   181   *** runcommand init foo
   182    runcommand -R foo showconfig ui defaults
   182   *** runcommand -R foo showconfig ui defaults
   183   defaults.backout=-d "0 0"
   183   defaults.backout=-d "0 0"
   184   defaults.commit=-d "0 0"
   184   defaults.commit=-d "0 0"
   185   defaults.shelve=--date "0 0"
   185   defaults.shelve=--date "0 0"
   186   defaults.tag=-d "0 0"
   186   defaults.tag=-d "0 0"
   187   ui.slash=True
   187   ui.slash=True
   211   ...     readchannel(server)
   211   ...     readchannel(server)
   212   ...     runcommand(server, ['--config',
   212   ...     runcommand(server, ['--config',
   213   ...                         'hooks.pre-identify=python:hook.hook',
   213   ...                         'hooks.pre-identify=python:hook.hook',
   214   ...                         'id'],
   214   ...                         'id'],
   215   ...                input=cStringIO.StringIO('some input'))
   215   ...                input=cStringIO.StringIO('some input'))
   216    runcommand --config hooks.pre-identify=python:hook.hook id
   216   *** runcommand --config hooks.pre-identify=python:hook.hook id
   217   hook talking
   217   hook talking
   218   now try to read something: 'some input'
   218   now try to read something: 'some input'
   219   eff892de26ec tip
   219   eff892de26ec tip
   220 
   220 
   221   $ rm hook.py*
   221   $ rm hook.py*
   228   ...     readchannel(server)
   228   ...     readchannel(server)
   229   ...     runcommand(server, ['status'])
   229   ...     runcommand(server, ['status'])
   230   ...     os.system('hg ci -Am2')
   230   ...     os.system('hg ci -Am2')
   231   ...     runcommand(server, ['tip'])
   231   ...     runcommand(server, ['tip'])
   232   ...     runcommand(server, ['status'])
   232   ...     runcommand(server, ['status'])
   233    runcommand status
   233   *** runcommand status
   234   M a
   234   M a
   235    runcommand tip
   235   *** runcommand tip
   236   changeset:   1:d3a0a68be6de
   236   changeset:   1:d3a0a68be6de
   237   tag:         tip
   237   tag:         tip
   238   user:        test
   238   user:        test
   239   date:        Thu Jan 01 00:00:00 1970 +0000
   239   date:        Thu Jan 01 00:00:00 1970 +0000
   240   summary:     2
   240   summary:     2
   241   
   241   
   242    runcommand status
   242   *** runcommand status
   243 
   243 
   244   >>> import os
   244   >>> import os
   245   >>> from hgclient import readchannel, runcommand, check
   245   >>> from hgclient import readchannel, runcommand, check
   246   >>> @check
   246   >>> @check
   247   ... def bookmarks(server):
   247   ... def bookmarks(server):
   261   ...     f = open('a', 'ab')
   261   ...     f = open('a', 'ab')
   262   ...     f.write('a\n')
   262   ...     f.write('a\n')
   263   ...     f.close()
   263   ...     f.close()
   264   ...     runcommand(server, ['commit', '-Amm'])
   264   ...     runcommand(server, ['commit', '-Amm'])
   265   ...     runcommand(server, ['bookmarks'])
   265   ...     runcommand(server, ['bookmarks'])
   266    runcommand bookmarks
   266   *** runcommand bookmarks
   267   no bookmarks set
   267   no bookmarks set
   268    runcommand bookmarks
   268   *** runcommand bookmarks
   269      bm1                       1:d3a0a68be6de
   269      bm1                       1:d3a0a68be6de
   270      bm2                       1:d3a0a68be6de
   270      bm2                       1:d3a0a68be6de
   271    runcommand bookmarks
   271   *** runcommand bookmarks
   272    * bm1                       1:d3a0a68be6de
   272    * bm1                       1:d3a0a68be6de
   273      bm2                       1:d3a0a68be6de
   273      bm2                       1:d3a0a68be6de
   274    runcommand bookmarks bm3
   274   *** runcommand bookmarks bm3
   275    runcommand commit -Amm
   275   *** runcommand commit -Amm
   276    runcommand bookmarks
   276   *** runcommand bookmarks
   277      bm1                       1:d3a0a68be6de
   277      bm1                       1:d3a0a68be6de
   278      bm2                       1:d3a0a68be6de
   278      bm2                       1:d3a0a68be6de
   279    * bm3                       2:aef17e88f5f0
   279    * bm3                       2:aef17e88f5f0
   280 
   280 
   281   >>> import os
   281   >>> import os
   284   ... def tagscache(server):
   284   ... def tagscache(server):
   285   ...     readchannel(server)
   285   ...     readchannel(server)
   286   ...     runcommand(server, ['id', '-t', '-r', '0'])
   286   ...     runcommand(server, ['id', '-t', '-r', '0'])
   287   ...     os.system('hg tag -r 0 foo')
   287   ...     os.system('hg tag -r 0 foo')
   288   ...     runcommand(server, ['id', '-t', '-r', '0'])
   288   ...     runcommand(server, ['id', '-t', '-r', '0'])
   289    runcommand id -t -r 0
   289   *** runcommand id -t -r 0
   290   
   290   
   291    runcommand id -t -r 0
   291   *** runcommand id -t -r 0
   292   foo
   292   foo
   293 
   293 
   294   >>> import os
   294   >>> import os
   295   >>> from hgclient import readchannel, runcommand, check
   295   >>> from hgclient import readchannel, runcommand, check
   296   >>> @check
   296   >>> @check
   297   ... def setphase(server):
   297   ... def setphase(server):
   298   ...     readchannel(server)
   298   ...     readchannel(server)
   299   ...     runcommand(server, ['phase', '-r', '.'])
   299   ...     runcommand(server, ['phase', '-r', '.'])
   300   ...     os.system('hg phase -r . -p')
   300   ...     os.system('hg phase -r . -p')
   301   ...     runcommand(server, ['phase', '-r', '.'])
   301   ...     runcommand(server, ['phase', '-r', '.'])
   302    runcommand phase -r .
   302   *** runcommand phase -r .
   303   3: draft
   303   3: draft
   304    runcommand phase -r .
   304   *** runcommand phase -r .
   305   3: public
   305   3: public
   306 
   306 
   307   $ echo a >> a
   307   $ echo a >> a
   308   >>> from hgclient import readchannel, runcommand, check
   308   >>> from hgclient import readchannel, runcommand, check
   309   >>> @check
   309   >>> @check
   311   ...     readchannel(server)
   311   ...     readchannel(server)
   312   ...     runcommand(server, ['phase', '-r', '.', '-p'])
   312   ...     runcommand(server, ['phase', '-r', '.', '-p'])
   313   ...     runcommand(server, ['commit', '-Am.'])
   313   ...     runcommand(server, ['commit', '-Am.'])
   314   ...     runcommand(server, ['rollback'])
   314   ...     runcommand(server, ['rollback'])
   315   ...     runcommand(server, ['phase', '-r', '.'])
   315   ...     runcommand(server, ['phase', '-r', '.'])
   316    runcommand phase -r . -p
   316   *** runcommand phase -r . -p
   317   no phases changed
   317   no phases changed
   318    [1]
   318    [1]
   319    runcommand commit -Am.
   319   *** runcommand commit -Am.
   320    runcommand rollback
   320   *** runcommand rollback
   321   repository tip rolled back to revision 3 (undo commit)
   321   repository tip rolled back to revision 3 (undo commit)
   322   working directory now based on revision 3
   322   working directory now based on revision 3
   323    runcommand phase -r .
   323   *** runcommand phase -r .
   324   3: public
   324   3: public
   325 
   325 
   326   >>> import os
   326   >>> import os
   327   >>> from hgclient import readchannel, runcommand, check
   327   >>> from hgclient import readchannel, runcommand, check
   328   >>> @check
   328   >>> @check
   330   ...     readchannel(server)
   330   ...     readchannel(server)
   331   ...     runcommand(server, ['branch'])
   331   ...     runcommand(server, ['branch'])
   332   ...     os.system('hg branch foo')
   332   ...     os.system('hg branch foo')
   333   ...     runcommand(server, ['branch'])
   333   ...     runcommand(server, ['branch'])
   334   ...     os.system('hg branch default')
   334   ...     os.system('hg branch default')
   335    runcommand branch
   335   *** runcommand branch
   336   default
   336   default
   337   marked working directory as branch foo
   337   marked working directory as branch foo
   338   (branches are permanent and global, did you want a bookmark?)
   338   (branches are permanent and global, did you want a bookmark?)
   339    runcommand branch
   339   *** runcommand branch
   340   foo
   340   foo
   341   marked working directory as branch default
   341   marked working directory as branch default
   342   (branches are permanent and global, did you want a bookmark?)
   342   (branches are permanent and global, did you want a bookmark?)
   343 
   343 
   344   $ touch .hgignore
   344   $ touch .hgignore
   353   ...     f.close()
   353   ...     f.close()
   354   ...     f = open('.hgignore', 'ab')
   354   ...     f = open('.hgignore', 'ab')
   355   ...     f.write('ignored-file')
   355   ...     f.write('ignored-file')
   356   ...     f.close()
   356   ...     f.close()
   357   ...     runcommand(server, ['status', '-i', '-u'])
   357   ...     runcommand(server, ['status', '-i', '-u'])
   358    runcommand commit -Am.
   358   *** runcommand commit -Am.
   359   adding .hgignore
   359   adding .hgignore
   360    runcommand status -i -u
   360   *** runcommand status -i -u
   361   I ignored-file
   361   I ignored-file
   362 
   362 
   363   >>> import os
   363   >>> import os
   364   >>> from hgclient import readchannel, sep, runcommand, check
   364   >>> from hgclient import readchannel, sep, runcommand, check
   365   >>> @check
   365   >>> @check
   382   ...     # strip 1::4 outside server
   382   ...     # strip 1::4 outside server
   383   ...     os.system('hg -q --config extensions.mq= strip 1')
   383   ...     os.system('hg -q --config extensions.mq= strip 1')
   384   ... 
   384   ... 
   385   ...     # shouldn't raise "7966c8e3734d: no node!"
   385   ...     # shouldn't raise "7966c8e3734d: no node!"
   386   ...     runcommand(server, ['branches'])
   386   ...     runcommand(server, ['branches'])
   387    runcommand update -C 0
   387   *** runcommand update -C 0
   388   1 files updated, 0 files merged, 2 files removed, 0 files unresolved
   388   1 files updated, 0 files merged, 2 files removed, 0 files unresolved
   389   (leaving bookmark bm3)
   389   (leaving bookmark bm3)
   390    runcommand commit -Am. a
   390   *** runcommand commit -Am. a
   391   created new head
   391   created new head
   392    runcommand log -Gq
   392   *** runcommand log -Gq
   393   @  5:731265503d86
   393   @  5:731265503d86
   394   |
   394   |
   395   | o  4:7966c8e3734d
   395   | o  4:7966c8e3734d
   396   | |
   396   | |
   397   | o  3:b9b85890c400
   397   | o  3:b9b85890c400
   400   | |
   400   | |
   401   | o  1:d3a0a68be6de
   401   | o  1:d3a0a68be6de
   402   |/
   402   |/
   403   o  0:eff892de26ec
   403   o  0:eff892de26ec
   404   
   404   
   405    runcommand phase -p .
   405   *** runcommand phase -p .
   406    runcommand phase .
   406   *** runcommand phase .
   407   5: public
   407   5: public
   408    runcommand branches
   408   *** runcommand branches
   409   default                        1:731265503d86
   409   default                        1:731265503d86
   410 
   410 
   411   $ cat <<EOF > obs.py
   411   $ cat <<EOF > obs.py
   412   > import mercurial.obsolete
   412   > import mercurial.obsolete
   413   > mercurial.obsolete._enabled = True
   413   > mercurial.obsolete._enabled = True
   429   ...     if os.name == 'nt':
   429   ...     if os.name == 'nt':
   430   ...         cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
   430   ...         cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
   431   ...     os.system(cmd)
   431   ...     os.system(cmd)
   432   ...     runcommand(server, ['log', '--hidden'])
   432   ...     runcommand(server, ['log', '--hidden'])
   433   ...     runcommand(server, ['log'])
   433   ...     runcommand(server, ['log'])
   434    runcommand up null
   434   *** runcommand up null
   435   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   435   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   436    runcommand phase -df tip
   436   *** runcommand phase -df tip
   437    runcommand log --hidden
   437   *** runcommand log --hidden
   438   changeset:   1:731265503d86
   438   changeset:   1:731265503d86
   439   tag:         tip
   439   tag:         tip
   440   user:        test
   440   user:        test
   441   date:        Thu Jan 01 00:00:00 1970 +0000
   441   date:        Thu Jan 01 00:00:00 1970 +0000
   442   summary:     .
   442   summary:     .
   447   bookmark:    bm3
   447   bookmark:    bm3
   448   user:        test
   448   user:        test
   449   date:        Thu Jan 01 00:00:00 1970 +0000
   449   date:        Thu Jan 01 00:00:00 1970 +0000
   450   summary:     1
   450   summary:     1
   451   
   451   
   452    runcommand log
   452   *** runcommand log
   453   changeset:   0:eff892de26ec
   453   changeset:   0:eff892de26ec
   454   bookmark:    bm1
   454   bookmark:    bm1
   455   bookmark:    bm2
   455   bookmark:    bm2
   456   bookmark:    bm3
   456   bookmark:    bm3
   457   tag:         tip
   457   tag:         tip
   479   ... 
   479   ... 
   480   ...     runcommand(server, ['qpop', '--all'])
   480   ...     runcommand(server, ['qpop', '--all'])
   481   ...     os.system('hg qqueue --create foo')
   481   ...     os.system('hg qqueue --create foo')
   482   ...     # repo.mq should be recreated to point to new queue
   482   ...     # repo.mq should be recreated to point to new queue
   483   ...     runcommand(server, ['qqueue', '--active'])
   483   ...     runcommand(server, ['qqueue', '--active'])
   484    runcommand qapplied
   484   *** runcommand qapplied
   485    runcommand qapplied
   485   *** runcommand qapplied
   486   0.diff
   486   0.diff
   487    runcommand qpop --all
   487   *** runcommand qpop --all
   488   popping 0.diff
   488   popping 0.diff
   489   patch queue now empty
   489   patch queue now empty
   490    runcommand qqueue --active
   490   *** runcommand qqueue --active
   491   foo
   491   foo
   492 
   492 
   493   $ cat <<EOF > dbgui.py
   493   $ cat <<EOF > dbgui.py
   494   > from mercurial import cmdutil, commands
   494   > from mercurial import cmdutil, commands
   495   > cmdtable = {}
   495   > cmdtable = {}
   509   ... def getpass(server):
   509   ... def getpass(server):
   510   ...     readchannel(server)
   510   ...     readchannel(server)
   511   ...     runcommand(server, ['debuggetpass', '--config',
   511   ...     runcommand(server, ['debuggetpass', '--config',
   512   ...                         'ui.interactive=True'],
   512   ...                         'ui.interactive=True'],
   513   ...                input=cStringIO.StringIO('1234\n'))
   513   ...                input=cStringIO.StringIO('1234\n'))
   514    runcommand debuggetpass --config ui.interactive=True
   514   *** runcommand debuggetpass --config ui.interactive=True
   515   password: 1234
   515   password: 1234
   516 
   516 
   517 
   517 
   518 start without repository:
   518 start without repository:
   519 
   519 
   526   ...     print '%c, %r' % (ch, data)
   526   ...     print '%c, %r' % (ch, data)
   527   ...     # run an arbitrary command to make sure the next thing the server
   527   ...     # run an arbitrary command to make sure the next thing the server
   528   ...     # sends isn't part of the hello message
   528   ...     # sends isn't part of the hello message
   529   ...     runcommand(server, ['id'])
   529   ...     runcommand(server, ['id'])
   530   o, 'capabilities: getencoding runcommand\nencoding: *' (glob)
   530   o, 'capabilities: getencoding runcommand\nencoding: *' (glob)
   531    runcommand id
   531   *** runcommand id
   532   abort: there is no Mercurial repository here (.hg not found)
   532   abort: there is no Mercurial repository here (.hg not found)
   533    [255]
   533    [255]
   534 
   534 
   535   >>> from hgclient import readchannel, runcommand, check
   535   >>> from hgclient import readchannel, runcommand, check
   536   >>> @check
   536   >>> @check
   537   ... def startwithoutrepo(server):
   537   ... def startwithoutrepo(server):
   538   ...     readchannel(server)
   538   ...     readchannel(server)
   539   ...     runcommand(server, ['init', 'repo2'])
   539   ...     runcommand(server, ['init', 'repo2'])
   540   ...     runcommand(server, ['id', '-R', 'repo2'])
   540   ...     runcommand(server, ['id', '-R', 'repo2'])
   541    runcommand init repo2
   541   *** runcommand init repo2
   542    runcommand id -R repo2
   542   *** runcommand id -R repo2
   543   000000000000 tip
   543   000000000000 tip