##// END OF EJS Templates
tests: on windows, run command explicitly in sh for working command substitution...
Simon Heimberg -
r20396:a8e6ab7e default
parent child Browse files
Show More
@@ -1,303 +1,306 b''
1 import sys, os, struct, subprocess, cStringIO, re, shutil
1 import sys, os, struct, subprocess, cStringIO, re, shutil
2
2
3 def connect(path=None):
3 def connect(path=None):
4 cmdline = ['hg', 'serve', '--cmdserver', 'pipe']
4 cmdline = ['hg', 'serve', '--cmdserver', 'pipe']
5 if path:
5 if path:
6 cmdline += ['-R', path]
6 cmdline += ['-R', path]
7
7
8 server = subprocess.Popen(cmdline, stdin=subprocess.PIPE,
8 server = subprocess.Popen(cmdline, stdin=subprocess.PIPE,
9 stdout=subprocess.PIPE)
9 stdout=subprocess.PIPE)
10
10
11 return server
11 return server
12
12
13 def writeblock(server, data):
13 def writeblock(server, data):
14 server.stdin.write(struct.pack('>I', len(data)))
14 server.stdin.write(struct.pack('>I', len(data)))
15 server.stdin.write(data)
15 server.stdin.write(data)
16 server.stdin.flush()
16 server.stdin.flush()
17
17
18 def readchannel(server):
18 def readchannel(server):
19 data = server.stdout.read(5)
19 data = server.stdout.read(5)
20 if not data:
20 if not data:
21 raise EOFError
21 raise EOFError
22 channel, length = struct.unpack('>cI', data)
22 channel, length = struct.unpack('>cI', data)
23 if channel in 'IL':
23 if channel in 'IL':
24 return channel, length
24 return channel, length
25 else:
25 else:
26 return channel, server.stdout.read(length)
26 return channel, server.stdout.read(length)
27
27
28 def sep(text):
28 def sep(text):
29 return text.replace('\\', '/')
29 return text.replace('\\', '/')
30
30
31 def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None,
31 def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None,
32 outfilter=lambda x: x):
32 outfilter=lambda x: x):
33 print ' runcommand', ' '.join(args)
33 print ' runcommand', ' '.join(args)
34 sys.stdout.flush()
34 sys.stdout.flush()
35 server.stdin.write('runcommand\n')
35 server.stdin.write('runcommand\n')
36 writeblock(server, '\0'.join(args))
36 writeblock(server, '\0'.join(args))
37
37
38 if not input:
38 if not input:
39 input = cStringIO.StringIO()
39 input = cStringIO.StringIO()
40
40
41 while True:
41 while True:
42 ch, data = readchannel(server)
42 ch, data = readchannel(server)
43 if ch == 'o':
43 if ch == 'o':
44 output.write(outfilter(data))
44 output.write(outfilter(data))
45 output.flush()
45 output.flush()
46 elif ch == 'e':
46 elif ch == 'e':
47 error.write(data)
47 error.write(data)
48 error.flush()
48 error.flush()
49 elif ch == 'I':
49 elif ch == 'I':
50 writeblock(server, input.read(data))
50 writeblock(server, input.read(data))
51 elif ch == 'L':
51 elif ch == 'L':
52 writeblock(server, input.readline(data))
52 writeblock(server, input.readline(data))
53 elif ch == 'r':
53 elif ch == 'r':
54 return struct.unpack('>i', data)[0]
54 return struct.unpack('>i', data)[0]
55 else:
55 else:
56 print "unexpected channel %c: %r" % (ch, data)
56 print "unexpected channel %c: %r" % (ch, data)
57 if ch.isupper():
57 if ch.isupper():
58 return
58 return
59
59
60 def check(func, repopath=None):
60 def check(func, repopath=None):
61 print
61 print
62 print 'testing %s:' % func.__name__
62 print 'testing %s:' % func.__name__
63 print
63 print
64 sys.stdout.flush()
64 sys.stdout.flush()
65 server = connect(repopath)
65 server = connect(repopath)
66 try:
66 try:
67 return func(server)
67 return func(server)
68 finally:
68 finally:
69 server.stdin.close()
69 server.stdin.close()
70 server.wait()
70 server.wait()
71
71
72 def unknowncommand(server):
72 def unknowncommand(server):
73 server.stdin.write('unknowncommand\n')
73 server.stdin.write('unknowncommand\n')
74
74
75 def hellomessage(server):
75 def hellomessage(server):
76 ch, data = readchannel(server)
76 ch, data = readchannel(server)
77 # escaping python tests output not supported
77 # escaping python tests output not supported
78 print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***',
78 print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***',
79 data))
79 data))
80
80
81 # run an arbitrary command to make sure the next thing the server sends
81 # run an arbitrary command to make sure the next thing the server sends
82 # isn't part of the hello message
82 # isn't part of the hello message
83 runcommand(server, ['id'])
83 runcommand(server, ['id'])
84
84
85 def checkruncommand(server):
85 def checkruncommand(server):
86 # hello block
86 # hello block
87 readchannel(server)
87 readchannel(server)
88
88
89 # no args
89 # no args
90 runcommand(server, [])
90 runcommand(server, [])
91
91
92 # global options
92 # global options
93 runcommand(server, ['id', '--quiet'])
93 runcommand(server, ['id', '--quiet'])
94
94
95 # make sure global options don't stick through requests
95 # make sure global options don't stick through requests
96 runcommand(server, ['id'])
96 runcommand(server, ['id'])
97
97
98 # --config
98 # --config
99 runcommand(server, ['id', '--config', 'ui.quiet=True'])
99 runcommand(server, ['id', '--config', 'ui.quiet=True'])
100
100
101 # make sure --config doesn't stick
101 # make sure --config doesn't stick
102 runcommand(server, ['id'])
102 runcommand(server, ['id'])
103
103
104 def inputeof(server):
104 def inputeof(server):
105 readchannel(server)
105 readchannel(server)
106 server.stdin.write('runcommand\n')
106 server.stdin.write('runcommand\n')
107 # close stdin while server is waiting for input
107 # close stdin while server is waiting for input
108 server.stdin.close()
108 server.stdin.close()
109
109
110 # server exits with 1 if the pipe closed while reading the command
110 # server exits with 1 if the pipe closed while reading the command
111 print 'server exit code =', server.wait()
111 print 'server exit code =', server.wait()
112
112
113 def serverinput(server):
113 def serverinput(server):
114 readchannel(server)
114 readchannel(server)
115
115
116 patch = """
116 patch = """
117 # HG changeset patch
117 # HG changeset patch
118 # User test
118 # User test
119 # Date 0 0
119 # Date 0 0
120 # Node ID c103a3dec114d882c98382d684d8af798d09d857
120 # Node ID c103a3dec114d882c98382d684d8af798d09d857
121 # Parent 0000000000000000000000000000000000000000
121 # Parent 0000000000000000000000000000000000000000
122 1
122 1
123
123
124 diff -r 000000000000 -r c103a3dec114 a
124 diff -r 000000000000 -r c103a3dec114 a
125 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
125 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
126 +++ b/a Thu Jan 01 00:00:00 1970 +0000
126 +++ b/a Thu Jan 01 00:00:00 1970 +0000
127 @@ -0,0 +1,1 @@
127 @@ -0,0 +1,1 @@
128 +1
128 +1
129 """
129 """
130
130
131 runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
131 runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
132 runcommand(server, ['log'])
132 runcommand(server, ['log'])
133
133
134 def cwd(server):
134 def cwd(server):
135 """ check that --cwd doesn't persist between requests """
135 """ check that --cwd doesn't persist between requests """
136 readchannel(server)
136 readchannel(server)
137 os.mkdir('foo')
137 os.mkdir('foo')
138 f = open('foo/bar', 'wb')
138 f = open('foo/bar', 'wb')
139 f.write('a')
139 f.write('a')
140 f.close()
140 f.close()
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 os.remove('foo/bar')
143 os.remove('foo/bar')
144
144
145 def localhgrc(server):
145 def localhgrc(server):
146 """ check that local configs for the cached repo aren't inherited when -R
146 """ check that local configs for the cached repo aren't inherited when -R
147 is used """
147 is used """
148 readchannel(server)
148 readchannel(server)
149
149
150 # the cached repo local hgrc contains ui.foo=bar, so showconfig should
150 # the cached repo local hgrc contains ui.foo=bar, so showconfig should
151 # show it
151 # show it
152 runcommand(server, ['showconfig'])
152 runcommand(server, ['showconfig'])
153
153
154 # but not for this repo
154 # but not for this repo
155 runcommand(server, ['init', 'foo'])
155 runcommand(server, ['init', 'foo'])
156 runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
156 runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
157 shutil.rmtree('foo')
157 shutil.rmtree('foo')
158
158
159 def hook(**args):
159 def hook(**args):
160 print 'hook talking'
160 print 'hook talking'
161 print 'now try to read something: %r' % sys.stdin.read()
161 print 'now try to read something: %r' % sys.stdin.read()
162
162
163 def hookoutput(server):
163 def hookoutput(server):
164 readchannel(server)
164 readchannel(server)
165 runcommand(server, ['--config',
165 runcommand(server, ['--config',
166 'hooks.pre-identify=python:test-commandserver.hook',
166 'hooks.pre-identify=python:test-commandserver.hook',
167 'id'],
167 'id'],
168 input=cStringIO.StringIO('some input'))
168 input=cStringIO.StringIO('some input'))
169
169
170 def outsidechanges(server):
170 def outsidechanges(server):
171 readchannel(server)
171 readchannel(server)
172 f = open('a', 'ab')
172 f = open('a', 'ab')
173 f.write('a\n')
173 f.write('a\n')
174 f.close()
174 f.close()
175 runcommand(server, ['status'])
175 runcommand(server, ['status'])
176 os.system('hg ci -Am2')
176 os.system('hg ci -Am2')
177 runcommand(server, ['tip'])
177 runcommand(server, ['tip'])
178 runcommand(server, ['status'])
178 runcommand(server, ['status'])
179
179
180 def bookmarks(server):
180 def bookmarks(server):
181 readchannel(server)
181 readchannel(server)
182 runcommand(server, ['bookmarks'])
182 runcommand(server, ['bookmarks'])
183
183
184 # changes .hg/bookmarks
184 # changes .hg/bookmarks
185 os.system('hg bookmark -i bm1')
185 os.system('hg bookmark -i bm1')
186 os.system('hg bookmark -i bm2')
186 os.system('hg bookmark -i bm2')
187 runcommand(server, ['bookmarks'])
187 runcommand(server, ['bookmarks'])
188
188
189 # changes .hg/bookmarks.current
189 # changes .hg/bookmarks.current
190 os.system('hg upd bm1 -q')
190 os.system('hg upd bm1 -q')
191 runcommand(server, ['bookmarks'])
191 runcommand(server, ['bookmarks'])
192
192
193 runcommand(server, ['bookmarks', 'bm3'])
193 runcommand(server, ['bookmarks', 'bm3'])
194 f = open('a', 'ab')
194 f = open('a', 'ab')
195 f.write('a\n')
195 f.write('a\n')
196 f.close()
196 f.close()
197 runcommand(server, ['commit', '-Amm'])
197 runcommand(server, ['commit', '-Amm'])
198 runcommand(server, ['bookmarks'])
198 runcommand(server, ['bookmarks'])
199
199
200 def tagscache(server):
200 def tagscache(server):
201 readchannel(server)
201 readchannel(server)
202 runcommand(server, ['id', '-t', '-r', '0'])
202 runcommand(server, ['id', '-t', '-r', '0'])
203 os.system('hg tag -r 0 foo')
203 os.system('hg tag -r 0 foo')
204 runcommand(server, ['id', '-t', '-r', '0'])
204 runcommand(server, ['id', '-t', '-r', '0'])
205
205
206 def setphase(server):
206 def setphase(server):
207 readchannel(server)
207 readchannel(server)
208 runcommand(server, ['phase', '-r', '.'])
208 runcommand(server, ['phase', '-r', '.'])
209 os.system('hg phase -r . -p')
209 os.system('hg phase -r . -p')
210 runcommand(server, ['phase', '-r', '.'])
210 runcommand(server, ['phase', '-r', '.'])
211
211
212 def rollback(server):
212 def rollback(server):
213 readchannel(server)
213 readchannel(server)
214 runcommand(server, ['phase', '-r', '.', '-p'])
214 runcommand(server, ['phase', '-r', '.', '-p'])
215 f = open('a', 'ab')
215 f = open('a', 'ab')
216 f.write('a\n')
216 f.write('a\n')
217 f.close()
217 f.close()
218 runcommand(server, ['commit', '-Am.'])
218 runcommand(server, ['commit', '-Am.'])
219 runcommand(server, ['rollback'])
219 runcommand(server, ['rollback'])
220 runcommand(server, ['phase', '-r', '.'])
220 runcommand(server, ['phase', '-r', '.'])
221
221
222 def branch(server):
222 def branch(server):
223 readchannel(server)
223 readchannel(server)
224 runcommand(server, ['branch'])
224 runcommand(server, ['branch'])
225 os.system('hg branch foo')
225 os.system('hg branch foo')
226 runcommand(server, ['branch'])
226 runcommand(server, ['branch'])
227 os.system('hg branch default')
227 os.system('hg branch default')
228
228
229 def hgignore(server):
229 def hgignore(server):
230 readchannel(server)
230 readchannel(server)
231 f = open('.hgignore', 'ab')
231 f = open('.hgignore', 'ab')
232 f.write('')
232 f.write('')
233 f.close()
233 f.close()
234 runcommand(server, ['commit', '-Am.'])
234 runcommand(server, ['commit', '-Am.'])
235 f = open('ignored-file', 'ab')
235 f = open('ignored-file', 'ab')
236 f.write('')
236 f.write('')
237 f.close()
237 f.close()
238 f = open('.hgignore', 'ab')
238 f = open('.hgignore', 'ab')
239 f.write('ignored-file')
239 f.write('ignored-file')
240 f.close()
240 f.close()
241 runcommand(server, ['status', '-i', '-u'])
241 runcommand(server, ['status', '-i', '-u'])
242
242
243 def phasecacheafterstrip(server):
243 def phasecacheafterstrip(server):
244 readchannel(server)
244 readchannel(server)
245
245
246 # create new head, 5:731265503d86
246 # create new head, 5:731265503d86
247 runcommand(server, ['update', '-C', '0'])
247 runcommand(server, ['update', '-C', '0'])
248 f = open('a', 'ab')
248 f = open('a', 'ab')
249 f.write('a\n')
249 f.write('a\n')
250 f.close()
250 f.close()
251 runcommand(server, ['commit', '-Am.', 'a'])
251 runcommand(server, ['commit', '-Am.', 'a'])
252 runcommand(server, ['log', '-Gq'])
252 runcommand(server, ['log', '-Gq'])
253
253
254 # make it public; draft marker moves to 4:7966c8e3734d
254 # make it public; draft marker moves to 4:7966c8e3734d
255 runcommand(server, ['phase', '-p', '.'])
255 runcommand(server, ['phase', '-p', '.'])
256 # load _phasecache.phaseroots
256 # load _phasecache.phaseroots
257 runcommand(server, ['phase', '.'], outfilter=sep)
257 runcommand(server, ['phase', '.'], outfilter=sep)
258
258
259 # strip 1::4 outside server
259 # strip 1::4 outside server
260 os.system('hg -q --config extensions.mq= strip 1')
260 os.system('hg -q --config extensions.mq= strip 1')
261
261
262 # shouldn't raise "7966c8e3734d: no node!"
262 # shouldn't raise "7966c8e3734d: no node!"
263 runcommand(server, ['branches'])
263 runcommand(server, ['branches'])
264
264
265 def obsolete(server):
265 def obsolete(server):
266 readchannel(server)
266 readchannel(server)
267
267
268 runcommand(server, ['up', 'null'])
268 runcommand(server, ['up', 'null'])
269 runcommand(server, ['phase', '-df', 'tip'])
269 runcommand(server, ['phase', '-df', 'tip'])
270 os.system('hg debugobsolete `hg log -r tip --template {node}`')
270 cmd = 'hg debugobsolete `hg log -r tip --template {node}`'
271 if os.name == 'nt':
272 cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
273 os.system(cmd)
271 runcommand(server, ['log', '--hidden'])
274 runcommand(server, ['log', '--hidden'])
272 runcommand(server, ['log'])
275 runcommand(server, ['log'])
273
276
274 if __name__ == '__main__':
277 if __name__ == '__main__':
275 os.system('hg init')
278 os.system('hg init')
276
279
277 check(hellomessage)
280 check(hellomessage)
278 check(unknowncommand)
281 check(unknowncommand)
279 check(checkruncommand)
282 check(checkruncommand)
280 check(inputeof)
283 check(inputeof)
281 check(serverinput)
284 check(serverinput)
282 check(cwd)
285 check(cwd)
283
286
284 hgrc = open('.hg/hgrc', 'a')
287 hgrc = open('.hg/hgrc', 'a')
285 hgrc.write('[ui]\nfoo=bar\n')
288 hgrc.write('[ui]\nfoo=bar\n')
286 hgrc.close()
289 hgrc.close()
287 check(localhgrc)
290 check(localhgrc)
288 check(hookoutput)
291 check(hookoutput)
289 check(outsidechanges)
292 check(outsidechanges)
290 check(bookmarks)
293 check(bookmarks)
291 check(tagscache)
294 check(tagscache)
292 check(setphase)
295 check(setphase)
293 check(rollback)
296 check(rollback)
294 check(branch)
297 check(branch)
295 check(hgignore)
298 check(hgignore)
296 check(phasecacheafterstrip)
299 check(phasecacheafterstrip)
297 obs = open('obs.py', 'w')
300 obs = open('obs.py', 'w')
298 obs.write('import mercurial.obsolete\nmercurial.obsolete._enabled = True\n')
301 obs.write('import mercurial.obsolete\nmercurial.obsolete._enabled = True\n')
299 obs.close()
302 obs.close()
300 hgrc = open('.hg/hgrc', 'a')
303 hgrc = open('.hg/hgrc', 'a')
301 hgrc.write('[extensions]\nobs=obs.py\n')
304 hgrc.write('[extensions]\nobs=obs.py\n')
302 hgrc.close()
305 hgrc.close()
303 check(obsolete)
306 check(obsolete)
General Comments 0
You need to be logged in to leave comments. Login now