Patchwork [5,of,9] test-commandserver: port test functions from .py to .t

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 28, 2014, 2:17 p.m.
Message ID <314d7969cf6e262e0fbc.1411913840@mimosa>
Download mbox | patch
Permalink /patch/6000/
State Accepted
Commit 78b99149ed8a015a79d6d27a7db8e1498575434e
Headers show

Comments

Yuya Nishihara - Sept. 28, 2014, 2:17 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1411887937 -32400
#      Sun Sep 28 16:05:37 2014 +0900
# Node ID 314d7969cf6e262e0fbc51b0aed9f37ebcff4797
# Parent  077b1eb1635039bdb0369ee7b3577e7a802cac6b
test-commandserver: port test functions from .py to .t

Though we have to duplicate import statements, .t test is still more handy
than .py test which has cryptic .out file.

This change allows to skip a part of test by #if conditional, which my next
patch series depends on.

Patch

diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -1,14 +1,64 @@ 
-#require false
+#if windows
+  $ PYTHONPATH="$TESTDIR/../contrib;$PYTHONPATH"
+#else
+  $ PYTHONPATH="$TESTDIR/../contrib:$PYTHONPATH"
+#endif
+  $ export PYTHONPATH
+
+  $ hg init repo
+  $ cd repo
+
+  >>> import re
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def hellomessage(server):
+  ...     ch, data = readchannel(server)
+  ...     # escaping python tests output not supported
+  ...     print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+',
+  ...                                  'encoding: ***', data))
+  ... 
+  ...     # run an arbitrary command to make sure the next thing the server
+  ...     # sends isn't part of the hello message
+  ...     runcommand(server, ['id'])
   
   testing hellomessage:
   
   o, 'capabilities: getencoding runcommand\nencoding: ***'
    runcommand id
   000000000000 tip
+
+  >>> from hgclient import check
+  >>> @check
+  ... def unknowncommand(server):
+  ...     server.stdin.write('unknowncommand\n')
   
   testing unknowncommand:
   
   abort: unknown command unknowncommand
+
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def checkruncommand(server):
+  ...     # hello block
+  ...     readchannel(server)
+  ... 
+  ...     # no args
+  ...     runcommand(server, [])
+  ... 
+  ...     # global options
+  ...     runcommand(server, ['id', '--quiet'])
+  ... 
+  ...     # make sure global options don't stick through requests
+  ...     runcommand(server, ['id'])
+  ... 
+  ...     # --config
+  ...     runcommand(server, ['id', '--config', 'ui.quiet=True'])
+  ... 
+  ...     # make sure --config doesn't stick
+  ...     runcommand(server, ['id'])
+  ... 
+  ...     # negative return code should be masked
+  ...     runcommand(server, ['id', '-runknown'])
   
   testing checkruncommand:
   
@@ -47,10 +97,45 @@ 
    runcommand id -runknown
   abort: unknown revision 'unknown'!
    [255]
+
+  >>> from hgclient import readchannel, check
+  >>> @check
+  ... def inputeof(server):
+  ...     readchannel(server)
+  ...     server.stdin.write('runcommand\n')
+  ...     # close stdin while server is waiting for input
+  ...     server.stdin.close()
+  ... 
+  ...     # server exits with 1 if the pipe closed while reading the command
+  ...     print 'server exit code =', server.wait()
   
   testing inputeof:
   
   server exit code = 1
+
+  >>> import cStringIO
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def serverinput(server):
+  ...     readchannel(server)
+  ... 
+  ...     patch = """
+  ... # HG changeset patch
+  ... # User test
+  ... # Date 0 0
+  ... # Node ID c103a3dec114d882c98382d684d8af798d09d857
+  ... # Parent  0000000000000000000000000000000000000000
+  ... 1
+  ... 
+  ... diff -r 000000000000 -r c103a3dec114 a
+  ... --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  ... +++ b/a	Thu Jan 01 00:00:00 1970 +0000
+  ... @@ -0,0 +1,1 @@
+  ... +1
+  ... """
+  ... 
+  ...     runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
+  ...     runcommand(server, ['log'])
   
   testing serverinput:
   
@@ -63,6 +148,17 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     1
   
+
+check that --cwd doesn't persist between requests:
+
+  $ mkdir foo
+  $ touch foo/bar
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def cwd(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
+  ...     runcommand(server, ['st', 'foo/bar'])
   
   testing cwd:
   
@@ -70,6 +166,29 @@ 
   ? bar
    runcommand st foo/bar
   ? foo/bar
+
+  $ rm foo/bar
+
+
+check that local configs for the cached repo aren't inherited when -R is used:
+
+  $ cat <<EOF >> .hg/hgrc
+  > [ui]
+  > foo = bar
+  > EOF
+
+  >>> from hgclient import readchannel, sep, runcommand, check
+  >>> @check
+  ... def localhgrc(server):
+  ...     readchannel(server)
+  ... 
+  ...     # the cached repo local hgrc contains ui.foo=bar, so showconfig should
+  ...     # show it
+  ...     runcommand(server, ['showconfig'], outfilter=sep)
+  ... 
+  ...     # but not for this repo
+  ...     runcommand(server, ['init', 'foo'])
+  ...     runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
   
   testing localhgrc:
   
@@ -94,13 +213,51 @@ 
   ui.interactive=False
   ui.mergemarkers=detailed
   ui.nontty=true
+
+  $ rm -R foo
+
+#if windows
+  $ PYTHONPATH="$TESTTMP/repo;$PYTHONPATH"
+#else
+  $ PYTHONPATH="$TESTTMP/repo:$PYTHONPATH"
+#endif
+
+  $ cat <<EOF > hook.py
+  > import sys
+  > def hook(**args):
+  >     print 'hook talking'
+  >     print 'now try to read something: %r' % sys.stdin.read()
+  > EOF
+
+  >>> import cStringIO
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def hookoutput(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['--config',
+  ...                         'hooks.pre-identify=python:hook.hook',
+  ...                         'id'],
+  ...                input=cStringIO.StringIO('some input'))
   
   testing hookoutput:
   
-   runcommand --config hooks.pre-identify=python:test-commandserver.hook id
+   runcommand --config hooks.pre-identify=python:hook.hook id
   hook talking
   now try to read something: 'some input'
   eff892de26ec tip
+
+  $ rm hook.py*
+
+  $ echo a >> a
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def outsidechanges(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['status'])
+  ...     os.system('hg ci -Am2')
+  ...     runcommand(server, ['tip'])
+  ...     runcommand(server, ['status'])
   
   testing outsidechanges:
   
@@ -114,6 +271,29 @@ 
   summary:     2
   
    runcommand status
+
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def bookmarks(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['bookmarks'])
+  ... 
+  ...     # changes .hg/bookmarks
+  ...     os.system('hg bookmark -i bm1')
+  ...     os.system('hg bookmark -i bm2')
+  ...     runcommand(server, ['bookmarks'])
+  ... 
+  ...     # changes .hg/bookmarks.current
+  ...     os.system('hg upd bm1 -q')
+  ...     runcommand(server, ['bookmarks'])
+  ... 
+  ...     runcommand(server, ['bookmarks', 'bm3'])
+  ...     f = open('a', 'ab')
+  ...     f.write('a\n')
+  ...     f.close()
+  ...     runcommand(server, ['commit', '-Amm'])
+  ...     runcommand(server, ['bookmarks'])
   
   testing bookmarks:
   
@@ -131,6 +311,15 @@ 
      bm1                       1:d3a0a68be6de
      bm2                       1:d3a0a68be6de
    * bm3                       2:aef17e88f5f0
+
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def tagscache(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['id', '-t', '-r', '0'])
+  ...     os.system('hg tag -r 0 foo')
+  ...     runcommand(server, ['id', '-t', '-r', '0'])
   
   testing tagscache:
   
@@ -138,6 +327,15 @@ 
   
    runcommand id -t -r 0
   foo
+
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def setphase(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['phase', '-r', '.'])
+  ...     os.system('hg phase -r . -p')
+  ...     runcommand(server, ['phase', '-r', '.'])
   
   testing setphase:
   
@@ -145,6 +343,16 @@ 
   3: draft
    runcommand phase -r .
   3: public
+
+  $ echo a >> a
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def rollback(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['phase', '-r', '.', '-p'])
+  ...     runcommand(server, ['commit', '-Am.'])
+  ...     runcommand(server, ['rollback'])
+  ...     runcommand(server, ['phase', '-r', '.'])
   
   testing rollback:
   
@@ -157,6 +365,16 @@ 
   working directory now based on revision 3
    runcommand phase -r .
   3: public
+
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def branch(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['branch'])
+  ...     os.system('hg branch foo')
+  ...     runcommand(server, ['branch'])
+  ...     os.system('hg branch default')
   
   testing branch:
   
@@ -168,6 +386,21 @@ 
   foo
   marked working directory as branch default
   (branches are permanent and global, did you want a bookmark?)
+
+  $ touch .hgignore
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def hgignore(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['commit', '-Am.'])
+  ...     f = open('ignored-file', 'ab')
+  ...     f.write('')
+  ...     f.close()
+  ...     f = open('.hgignore', 'ab')
+  ...     f.write('ignored-file')
+  ...     f.close()
+  ...     runcommand(server, ['status', '-i', '-u'])
   
   testing hgignore:
   
@@ -175,6 +408,31 @@ 
   adding .hgignore
    runcommand status -i -u
   I ignored-file
+
+  >>> import os
+  >>> from hgclient import readchannel, sep, runcommand, check
+  >>> @check
+  ... def phasecacheafterstrip(server):
+  ...     readchannel(server)
+  ... 
+  ...     # create new head, 5:731265503d86
+  ...     runcommand(server, ['update', '-C', '0'])
+  ...     f = open('a', 'ab')
+  ...     f.write('a\n')
+  ...     f.close()
+  ...     runcommand(server, ['commit', '-Am.', 'a'])
+  ...     runcommand(server, ['log', '-Gq'])
+  ... 
+  ...     # make it public; draft marker moves to 4:7966c8e3734d
+  ...     runcommand(server, ['phase', '-p', '.'])
+  ...     # load _phasecache.phaseroots
+  ...     runcommand(server, ['phase', '.'], outfilter=sep)
+  ... 
+  ...     # strip 1::4 outside server
+  ...     os.system('hg -q --config extensions.mq= strip 1')
+  ... 
+  ...     # shouldn't raise "7966c8e3734d: no node!"
+  ...     runcommand(server, ['branches'])
   
   testing phasecacheafterstrip:
   
@@ -201,6 +459,30 @@ 
   5: public
    runcommand branches
   default                        1:731265503d86
+
+  $ cat <<EOF > obs.py
+  > import mercurial.obsolete
+  > mercurial.obsolete._enabled = True
+  > EOF
+  $ cat <<EOF >> .hg/hgrc
+  > [extensions]
+  > obs = obs.py
+  > EOF
+
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def obsolete(server):
+  ...     readchannel(server)
+  ... 
+  ...     runcommand(server, ['up', 'null'])
+  ...     runcommand(server, ['phase', '-df', 'tip'])
+  ...     cmd = 'hg debugobsolete `hg log -r tip --template {node}`'
+  ...     if os.name == 'nt':
+  ...         cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
+  ...     os.system(cmd)
+  ...     runcommand(server, ['log', '--hidden'])
+  ...     runcommand(server, ['log'])
   
   testing obsolete:
   
@@ -232,6 +514,28 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     1
   
+
+  $ cat <<EOF >> .hg/hgrc
+  > [extensions]
+  > mq =
+  > EOF
+
+  >>> import os
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def mqoutsidechanges(server):
+  ...     readchannel(server)
+  ... 
+  ...     # load repo.mq
+  ...     runcommand(server, ['qapplied'])
+  ...     os.system('hg qnew 0.diff')
+  ...     # repo.mq should be invalidated
+  ...     runcommand(server, ['qapplied'])
+  ... 
+  ...     runcommand(server, ['qpop', '--all'])
+  ...     os.system('hg qqueue --create foo')
+  ...     # repo.mq should be recreated to point to new queue
+  ...     runcommand(server, ['qqueue', '--active'])
   
   testing mqoutsidechanges:
   
@@ -243,11 +547,51 @@ 
   patch queue now empty
    runcommand qqueue --active
   foo
+
+  $ cat <<EOF > dbgui.py
+  > from mercurial import cmdutil, commands
+  > cmdtable = {}
+  > command = cmdutil.command(cmdtable)
+  > @command("debuggetpass", norepo=True)
+  > def debuggetpass(ui):
+  >     ui.write("%s\\n" % ui.getpass())
+  > EOF
+  $ cat <<EOF >> .hg/hgrc
+  > [extensions]
+  > dbgui = dbgui.py
+  > EOF
+
+  >>> import cStringIO
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def getpass(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['debuggetpass', '--config',
+  ...                         'ui.interactive=True'],
+  ...                input=cStringIO.StringIO('1234\n'))
   
   testing getpass:
   
    runcommand debuggetpass --config ui.interactive=True
   password: 1234
+
+
+start without repository:
+
+  $ cd ..
+
+  >>> import re
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def hellomessage(server):
+  ...     ch, data = readchannel(server)
+  ...     # escaping python tests output not supported
+  ...     print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+',
+  ...                                  'encoding: ***', data))
+  ... 
+  ...     # run an arbitrary command to make sure the next thing the server
+  ...     # sends isn't part of the hello message
+  ...     runcommand(server, ['id'])
   
   testing hellomessage:
   
@@ -255,6 +599,13 @@ 
    runcommand id
   abort: there is no Mercurial repository here (.hg not found)
    [255]
+
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def startwithoutrepo(server):
+  ...     readchannel(server)
+  ...     runcommand(server, ['init', 'repo2'])
+  ...     runcommand(server, ['id', '-R', 'repo2'])
   
   testing startwithoutrepo: