author | Alexander Sauta <demosito@gmail.com> |
Fri, 27 Jan 2012 12:25:02 +0400 | |
branch | stable |
changeset 16003 | 0d898ebb424e |
parent 15989 | 6548a2e32285 |
child 16114 | acfca07a8f26 |
permissions | -rw-r--r-- |
14882
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
1 |
import sys, os, struct, subprocess, cStringIO, re, shutil |
14770
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
2 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
3 |
def connect(path=None): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
4 |
cmdline = ['hg', 'serve', '--cmdserver', 'pipe'] |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 |
if path: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 |
cmdline += ['-R', path] |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 |
server = subprocess.Popen(cmdline, stdin=subprocess.PIPE, |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 |
stdout=subprocess.PIPE) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 |
return server |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 |
def writeblock(server, data): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 |
server.stdin.write(struct.pack('>I', len(data))) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
15 |
server.stdin.write(data) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 |
server.stdin.flush() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 |
def readchannel(server): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 |
data = server.stdout.read(5) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 |
if not data: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 |
raise EOFError() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 |
channel, length = struct.unpack('>cI', data) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 |
if channel in 'IL': |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 |
return channel, length |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 |
else: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 |
return channel, server.stdout.read(length) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
27 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 |
def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None): |
15541
3aee6e26b28b
tests: make test-commandserver.py output readable
Mads Kiilerich <mads@kiilerich.com>
parents:
14939
diff
changeset
|
29 |
print ' runcommand', ' '.join(args) |
14770
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 |
server.stdin.write('runcommand\n') |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
31 |
writeblock(server, '\0'.join(args)) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
32 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 |
if not input: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 |
input = cStringIO.StringIO() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
36 |
while True: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
37 |
ch, data = readchannel(server) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 |
if ch == 'o': |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
39 |
output.write(data) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 |
output.flush() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
41 |
elif ch == 'e': |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
42 |
error.write(data) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
43 |
error.flush() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
44 |
elif ch == 'I': |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
45 |
writeblock(server, input.read(data)) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
46 |
elif ch == 'L': |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 |
writeblock(server, input.readline(data)) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
48 |
elif ch == 'r': |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
49 |
return struct.unpack('>i', data)[0] |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
50 |
else: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
51 |
print "unexpected channel %c: %r" % (ch, data) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
52 |
if ch.isupper(): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
53 |
return |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
54 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
55 |
def check(func, repopath=None): |
15541
3aee6e26b28b
tests: make test-commandserver.py output readable
Mads Kiilerich <mads@kiilerich.com>
parents:
14939
diff
changeset
|
56 |
|
3aee6e26b28b
tests: make test-commandserver.py output readable
Mads Kiilerich <mads@kiilerich.com>
parents:
14939
diff
changeset
|
57 |
print 'testing %s:' % func.__name__ |
3aee6e26b28b
tests: make test-commandserver.py output readable
Mads Kiilerich <mads@kiilerich.com>
parents:
14939
diff
changeset
|
58 |
|
14770
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
59 |
server = connect(repopath) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
60 |
try: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
61 |
return func(server) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
62 |
finally: |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
63 |
server.stdin.close() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
64 |
server.wait() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
65 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
66 |
def unknowncommand(server): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
67 |
server.stdin.write('unknowncommand\n') |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
68 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
69 |
def hellomessage(server): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
70 |
ch, data = readchannel(server) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
71 |
# escaping python tests output not supported |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
72 |
print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***', data)) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
73 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
74 |
# run an arbitrary command to make sure the next thing the server sends |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
75 |
# isn't part of the hello message |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
76 |
runcommand(server, ['id']) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
77 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
78 |
def checkruncommand(server): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
79 |
# hello block |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
80 |
readchannel(server) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
81 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
82 |
# no args |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
83 |
runcommand(server, []) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
84 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
85 |
# global options |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
86 |
runcommand(server, ['id', '--quiet']) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
87 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
88 |
# make sure global options don't stick through requests |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
89 |
runcommand(server, ['id']) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
90 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
91 |
# --config |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
92 |
runcommand(server, ['id', '--config', 'ui.quiet=True']) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
93 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
94 |
# make sure --config doesn't stick |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
95 |
runcommand(server, ['id']) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
96 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
97 |
def inputeof(server): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
98 |
readchannel(server) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
99 |
server.stdin.write('runcommand\n') |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
100 |
# close stdin while server is waiting for input |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
101 |
server.stdin.close() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
102 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
103 |
# server exits with 1 if the pipe closed while reading the command |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
104 |
print 'server exit code =', server.wait() |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
105 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
106 |
def serverinput(server): |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
107 |
readchannel(server) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
108 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
109 |
patch = """ |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
110 |
# HG changeset patch |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
111 |
# User test |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
112 |
# Date 0 0 |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
113 |
# Node ID c103a3dec114d882c98382d684d8af798d09d857 |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
114 |
# Parent 0000000000000000000000000000000000000000 |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
115 |
1 |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
116 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
117 |
diff -r 000000000000 -r c103a3dec114 a |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
118 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
119 |
+++ b/a Thu Jan 01 00:00:00 1970 +0000 |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
120 |
@@ -0,0 +1,1 @@ |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
121 |
+1 |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
122 |
""" |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
123 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
124 |
runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch)) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
125 |
runcommand(server, ['log']) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
126 |
|
14864
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
127 |
def cwd(server): |
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
128 |
""" check that --cwd doesn't persist between requests """ |
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
129 |
readchannel(server) |
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
130 |
os.mkdir('foo') |
15542
e19302598df8
tests: make test-commandserver.py independent of line ending and slash direction
Mads Kiilerich <mads@kiilerich.com>
parents:
15541
diff
changeset
|
131 |
f = open('foo/bar', 'wb') |
14880
5233df79deed
test-commandserver: explicitly close opened file
Idan Kamara <idankk86@gmail.com>
parents:
14864
diff
changeset
|
132 |
f.write('a') |
5233df79deed
test-commandserver: explicitly close opened file
Idan Kamara <idankk86@gmail.com>
parents:
14864
diff
changeset
|
133 |
f.close() |
14864
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
134 |
runcommand(server, ['--cwd', 'foo', 'st', 'bar']) |
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
135 |
runcommand(server, ['st', 'foo/bar']) |
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
136 |
os.remove('foo/bar') |
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
137 |
|
14882
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
138 |
def localhgrc(server): |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
139 |
""" check that local configs for the cached repo aren't inherited when -R |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
140 |
is used """ |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
141 |
readchannel(server) |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
142 |
|
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
143 |
# the cached repo local hgrc contains ui.foo=bar, so showconfig should show it |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
144 |
runcommand(server, ['showconfig']) |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
145 |
|
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
146 |
# but not for this repo |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
147 |
runcommand(server, ['init', 'foo']) |
15542
e19302598df8
tests: make test-commandserver.py independent of line ending and slash direction
Mads Kiilerich <mads@kiilerich.com>
parents:
15541
diff
changeset
|
148 |
runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults']) |
14882
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
149 |
shutil.rmtree('foo') |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
150 |
|
14889
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
151 |
def hook(**args): |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
152 |
print 'hook talking' |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
153 |
print 'now try to read something: %r' % sys.stdin.read() |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
154 |
|
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
155 |
def hookoutput(server): |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
156 |
readchannel(server) |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
157 |
runcommand(server, ['--config', |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
158 |
'hooks.pre-identify=python:test-commandserver.hook', 'id'], |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
159 |
input=cStringIO.StringIO('some input')) |
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
160 |
|
14939
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
161 |
def outsidechanges(server): |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
162 |
readchannel(server) |
15542
e19302598df8
tests: make test-commandserver.py independent of line ending and slash direction
Mads Kiilerich <mads@kiilerich.com>
parents:
15541
diff
changeset
|
163 |
f = open('a', 'ab') |
e19302598df8
tests: make test-commandserver.py independent of line ending and slash direction
Mads Kiilerich <mads@kiilerich.com>
parents:
15541
diff
changeset
|
164 |
f.write('a\n') |
e19302598df8
tests: make test-commandserver.py independent of line ending and slash direction
Mads Kiilerich <mads@kiilerich.com>
parents:
15541
diff
changeset
|
165 |
f.close() |
e19302598df8
tests: make test-commandserver.py independent of line ending and slash direction
Mads Kiilerich <mads@kiilerich.com>
parents:
15541
diff
changeset
|
166 |
os.system('hg ci -Am2') |
14939
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
167 |
runcommand(server, ['tip']) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
168 |
|
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
169 |
def bookmarks(server): |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
170 |
readchannel(server) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
171 |
runcommand(server, ['bookmarks']) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
172 |
|
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
173 |
# changes .hg/bookmarks |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
174 |
os.system('hg bookmark -i bm1') |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
175 |
os.system('hg bookmark -i bm2') |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
176 |
runcommand(server, ['bookmarks']) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
177 |
|
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
178 |
# changes .hg/bookmarks.current |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
179 |
os.system('hg upd bm1 -q') |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
180 |
runcommand(server, ['bookmarks']) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
181 |
|
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
182 |
def tagscache(server): |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
183 |
readchannel(server) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
184 |
runcommand(server, ['id', '-t', '-r', '0']) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
185 |
os.system('hg tag -r 0 foo') |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
186 |
runcommand(server, ['id', '-t', '-r', '0']) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
187 |
|
15989
6548a2e32285
test-commandserver: test that phase data is being refreshed
Idan Kamara <idankk86@gmail.com>
parents:
15542
diff
changeset
|
188 |
def setphase(server): |
6548a2e32285
test-commandserver: test that phase data is being refreshed
Idan Kamara <idankk86@gmail.com>
parents:
15542
diff
changeset
|
189 |
readchannel(server) |
6548a2e32285
test-commandserver: test that phase data is being refreshed
Idan Kamara <idankk86@gmail.com>
parents:
15542
diff
changeset
|
190 |
runcommand(server, ['phase', '-r', '.']) |
6548a2e32285
test-commandserver: test that phase data is being refreshed
Idan Kamara <idankk86@gmail.com>
parents:
15542
diff
changeset
|
191 |
os.system('hg phase -r . -p') |
6548a2e32285
test-commandserver: test that phase data is being refreshed
Idan Kamara <idankk86@gmail.com>
parents:
15542
diff
changeset
|
192 |
runcommand(server, ['phase', '-r', '.']) |
6548a2e32285
test-commandserver: test that phase data is being refreshed
Idan Kamara <idankk86@gmail.com>
parents:
15542
diff
changeset
|
193 |
|
14770
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
194 |
if __name__ == '__main__': |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
195 |
os.system('hg init') |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
196 |
|
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
197 |
check(hellomessage) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
198 |
check(unknowncommand) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
199 |
check(checkruncommand) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
200 |
check(inputeof) |
95a8c0f5dd3f
tests: add basic commandserver test
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
201 |
check(serverinput) |
14864
1b872599f39f
cmdserver: restore old working dir after dispatch when we have --cwd
Idan Kamara <idankk86@gmail.com>
parents:
14770
diff
changeset
|
202 |
check(cwd) |
14882
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
203 |
|
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
204 |
hgrc = open('.hg/hgrc', 'a') |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
205 |
hgrc.write('[ui]\nfoo=bar\n') |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
206 |
hgrc.close() |
bb2cffe81a94
cmdserver: take repo.baseui as our ui
Idan Kamara <idankk86@gmail.com>
parents:
14880
diff
changeset
|
207 |
check(localhgrc) |
14889
a59058fd074a
hooks: redirect stdout/err/in to the ui descriptors when calling python hooks
Idan Kamara <idankk86@gmail.com>
parents:
14882
diff
changeset
|
208 |
check(hookoutput) |
14939
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
209 |
check(outsidechanges) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
210 |
check(bookmarks) |
b4c06b97dfe0
cmdserver: repo.invalidate() on every runcommand
Idan Kamara <idankk86@gmail.com>
parents:
14889
diff
changeset
|
211 |
check(tagscache) |
15989
6548a2e32285
test-commandserver: test that phase data is being refreshed
Idan Kamara <idankk86@gmail.com>
parents:
15542
diff
changeset
|
212 |
check(setphase) |