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