tests/test-commandserver.t
changeset 22568 78b99149ed8a
parent 22567 f9a4a035003d
child 22570 db497a1ef1c1
equal deleted inserted replaced
22567:f9a4a035003d 22568:78b99149ed8a
     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   testing hellomessage:
    24   testing hellomessage:
     4   
    25   
     5   o, 'capabilities: getencoding runcommand\nencoding: ***'
    26   o, 'capabilities: getencoding runcommand\nencoding: ***'
     6    runcommand id
    27    runcommand id
     7   000000000000 tip
    28   000000000000 tip
       
    29 
       
    30   >>> from hgclient import check
       
    31   >>> @check
       
    32   ... def unknowncommand(server):
       
    33   ...     server.stdin.write('unknowncommand\n')
     8   
    34   
     9   testing unknowncommand:
    35   testing unknowncommand:
    10   
    36   
    11   abort: unknown command unknowncommand
    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   testing checkruncommand:
    63   testing checkruncommand:
    14   
    64   
    15    runcommand 
    65    runcommand 
    16   Mercurial Distributed SCM
    66   Mercurial Distributed SCM
    45    runcommand id
    95    runcommand id
    46   000000000000 tip
    96   000000000000 tip
    47    runcommand id -runknown
    97    runcommand id -runknown
    48   abort: unknown revision 'unknown'!
    98   abort: unknown revision 'unknown'!
    49    [255]
    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   testing inputeof:
   112   testing inputeof:
    52   
   113   
    53   server exit code = 1
   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   testing serverinput:
   140   testing serverinput:
    56   
   141   
    57    runcommand import -
   142    runcommand import -
    58   applying patch from stdin
   143   applying patch from stdin
    61   tag:         tip
   146   tag:         tip
    62   user:        test
   147   user:        test
    63   date:        Thu Jan 01 00:00:00 1970 +0000
   148   date:        Thu Jan 01 00:00:00 1970 +0000
    64   summary:     1
   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   testing cwd:
   163   testing cwd:
    68   
   164   
    69    runcommand --cwd foo st bar
   165    runcommand --cwd foo st bar
    70   ? bar
   166   ? bar
    71    runcommand st foo/bar
   167    runcommand st foo/bar
    72   ? foo/bar
   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   testing localhgrc:
   193   testing localhgrc:
    75   
   194   
    76    runcommand showconfig
   195    runcommand showconfig
    77   bundle.mainreporoot=$TESTTMP/repo
   196   bundle.mainreporoot=$TESTTMP/repo
    92   defaults.tag=-d "0 0"
   211   defaults.tag=-d "0 0"
    93   ui.slash=True
   212   ui.slash=True
    94   ui.interactive=False
   213   ui.interactive=False
    95   ui.mergemarkers=detailed
   214   ui.mergemarkers=detailed
    96   ui.nontty=true
   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   testing hookoutput:
   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   hook talking
   245   hook talking
   102   now try to read something: 'some input'
   246   now try to read something: 'some input'
   103   eff892de26ec tip
   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   testing outsidechanges:
   262   testing outsidechanges:
   106   
   263   
   107    runcommand status
   264    runcommand status
   108   M a
   265   M a
   112   user:        test
   269   user:        test
   113   date:        Thu Jan 01 00:00:00 1970 +0000
   270   date:        Thu Jan 01 00:00:00 1970 +0000
   114   summary:     2
   271   summary:     2
   115   
   272   
   116    runcommand status
   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   testing bookmarks:
   298   testing bookmarks:
   119   
   299   
   120    runcommand bookmarks
   300    runcommand bookmarks
   121   no bookmarks set
   301   no bookmarks set
   129    runcommand commit -Amm
   309    runcommand commit -Amm
   130    runcommand bookmarks
   310    runcommand bookmarks
   131      bm1                       1:d3a0a68be6de
   311      bm1                       1:d3a0a68be6de
   132      bm2                       1:d3a0a68be6de
   312      bm2                       1:d3a0a68be6de
   133    * bm3                       2:aef17e88f5f0
   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   testing tagscache:
   324   testing tagscache:
   136   
   325   
   137    runcommand id -t -r 0
   326    runcommand id -t -r 0
   138   
   327   
   139    runcommand id -t -r 0
   328    runcommand id -t -r 0
   140   foo
   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   testing setphase:
   340   testing setphase:
   143   
   341   
   144    runcommand phase -r .
   342    runcommand phase -r .
   145   3: draft
   343   3: draft
   146    runcommand phase -r .
   344    runcommand phase -r .
   147   3: public
   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   testing rollback:
   357   testing rollback:
   150   
   358   
   151    runcommand phase -r . -p
   359    runcommand phase -r . -p
   152   no phases changed
   360   no phases changed
   155    runcommand rollback
   363    runcommand rollback
   156   repository tip rolled back to revision 3 (undo commit)
   364   repository tip rolled back to revision 3 (undo commit)
   157   working directory now based on revision 3
   365   working directory now based on revision 3
   158    runcommand phase -r .
   366    runcommand phase -r .
   159   3: public
   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   testing branch:
   379   testing branch:
   162   
   380   
   163    runcommand branch
   381    runcommand branch
   164   default
   382   default
   166   (branches are permanent and global, did you want a bookmark?)
   384   (branches are permanent and global, did you want a bookmark?)
   167    runcommand branch
   385    runcommand branch
   168   foo
   386   foo
   169   marked working directory as branch default
   387   marked working directory as branch default
   170   (branches are permanent and global, did you want a bookmark?)
   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   testing hgignore:
   405   testing hgignore:
   173   
   406   
   174    runcommand commit -Am.
   407    runcommand commit -Am.
   175   adding .hgignore
   408   adding .hgignore
   176    runcommand status -i -u
   409    runcommand status -i -u
   177   I ignored-file
   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   testing phasecacheafterstrip:
   437   testing phasecacheafterstrip:
   180   
   438   
   181    runcommand update -C 0
   439    runcommand update -C 0
   182   1 files updated, 0 files merged, 2 files removed, 0 files unresolved
   440   1 files updated, 0 files merged, 2 files removed, 0 files unresolved
   199    runcommand phase -p .
   457    runcommand phase -p .
   200    runcommand phase .
   458    runcommand phase .
   201   5: public
   459   5: public
   202    runcommand branches
   460    runcommand branches
   203   default                        1:731265503d86
   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   testing obsolete:
   487   testing obsolete:
   206   
   488   
   207    runcommand up null
   489    runcommand up null
   208   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   490   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   230   tag:         tip
   512   tag:         tip
   231   user:        test
   513   user:        test
   232   date:        Thu Jan 01 00:00:00 1970 +0000
   514   date:        Thu Jan 01 00:00:00 1970 +0000
   233   summary:     1
   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   testing mqoutsidechanges:
   540   testing mqoutsidechanges:
   237   
   541   
   238    runcommand qapplied
   542    runcommand qapplied
   239    runcommand qapplied
   543    runcommand qapplied
   241    runcommand qpop --all
   545    runcommand qpop --all
   242   popping 0.diff
   546   popping 0.diff
   243   patch queue now empty
   547   patch queue now empty
   244    runcommand qqueue --active
   548    runcommand qqueue --active
   245   foo
   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   testing getpass:
   573   testing getpass:
   248   
   574   
   249    runcommand debuggetpass --config ui.interactive=True
   575    runcommand debuggetpass --config ui.interactive=True
   250   password: 1234
   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   testing hellomessage:
   596   testing hellomessage:
   253   
   597   
   254   o, 'capabilities: getencoding runcommand\nencoding: ***'
   598   o, 'capabilities: getencoding runcommand\nencoding: ***'
   255    runcommand id
   599    runcommand id
   256   abort: there is no Mercurial repository here (.hg not found)
   600   abort: there is no Mercurial repository here (.hg not found)
   257    [255]
   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   testing startwithoutrepo:
   610   testing startwithoutrepo:
   260   
   611   
   261    runcommand init repo2
   612    runcommand init repo2
   262    runcommand id -R repo2
   613    runcommand id -R repo2