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