##// END OF EJS Templates
tests: quiet strip to avoid commandserver pathsep issue
Matt Mackall -
r19166:e958b176 stable
parent child Browse files
Show More
@@ -1,282 +1,282 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 runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None):
29 29 print ' runcommand', ' '.join(args)
30 30 sys.stdout.flush()
31 31 server.stdin.write('runcommand\n')
32 32 writeblock(server, '\0'.join(args))
33 33
34 34 if not input:
35 35 input = cStringIO.StringIO()
36 36
37 37 while True:
38 38 ch, data = readchannel(server)
39 39 if ch == 'o':
40 40 output.write(data)
41 41 output.flush()
42 42 elif ch == 'e':
43 43 error.write(data)
44 44 error.flush()
45 45 elif ch == 'I':
46 46 writeblock(server, input.read(data))
47 47 elif ch == 'L':
48 48 writeblock(server, input.readline(data))
49 49 elif ch == 'r':
50 50 return struct.unpack('>i', data)[0]
51 51 else:
52 52 print "unexpected channel %c: %r" % (ch, data)
53 53 if ch.isupper():
54 54 return
55 55
56 56 def check(func, repopath=None):
57 57 print
58 58 print 'testing %s:' % func.__name__
59 59 print
60 60 sys.stdout.flush()
61 61 server = connect(repopath)
62 62 try:
63 63 return func(server)
64 64 finally:
65 65 server.stdin.close()
66 66 server.wait()
67 67
68 68 def unknowncommand(server):
69 69 server.stdin.write('unknowncommand\n')
70 70
71 71 def hellomessage(server):
72 72 ch, data = readchannel(server)
73 73 # escaping python tests output not supported
74 74 print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***',
75 75 data))
76 76
77 77 # run an arbitrary command to make sure the next thing the server sends
78 78 # isn't part of the hello message
79 79 runcommand(server, ['id'])
80 80
81 81 def checkruncommand(server):
82 82 # hello block
83 83 readchannel(server)
84 84
85 85 # no args
86 86 runcommand(server, [])
87 87
88 88 # global options
89 89 runcommand(server, ['id', '--quiet'])
90 90
91 91 # make sure global options don't stick through requests
92 92 runcommand(server, ['id'])
93 93
94 94 # --config
95 95 runcommand(server, ['id', '--config', 'ui.quiet=True'])
96 96
97 97 # make sure --config doesn't stick
98 98 runcommand(server, ['id'])
99 99
100 100 def inputeof(server):
101 101 readchannel(server)
102 102 server.stdin.write('runcommand\n')
103 103 # close stdin while server is waiting for input
104 104 server.stdin.close()
105 105
106 106 # server exits with 1 if the pipe closed while reading the command
107 107 print 'server exit code =', server.wait()
108 108
109 109 def serverinput(server):
110 110 readchannel(server)
111 111
112 112 patch = """
113 113 # HG changeset patch
114 114 # User test
115 115 # Date 0 0
116 116 # Node ID c103a3dec114d882c98382d684d8af798d09d857
117 117 # Parent 0000000000000000000000000000000000000000
118 118 1
119 119
120 120 diff -r 000000000000 -r c103a3dec114 a
121 121 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
122 122 +++ b/a Thu Jan 01 00:00:00 1970 +0000
123 123 @@ -0,0 +1,1 @@
124 124 +1
125 125 """
126 126
127 127 runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
128 128 runcommand(server, ['log'])
129 129
130 130 def cwd(server):
131 131 """ check that --cwd doesn't persist between requests """
132 132 readchannel(server)
133 133 os.mkdir('foo')
134 134 f = open('foo/bar', 'wb')
135 135 f.write('a')
136 136 f.close()
137 137 runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
138 138 runcommand(server, ['st', 'foo/bar'])
139 139 os.remove('foo/bar')
140 140
141 141 def localhgrc(server):
142 142 """ check that local configs for the cached repo aren't inherited when -R
143 143 is used """
144 144 readchannel(server)
145 145
146 146 # the cached repo local hgrc contains ui.foo=bar, so showconfig should
147 147 # show it
148 148 runcommand(server, ['showconfig'])
149 149
150 150 # but not for this repo
151 151 runcommand(server, ['init', 'foo'])
152 152 runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
153 153 shutil.rmtree('foo')
154 154
155 155 def hook(**args):
156 156 print 'hook talking'
157 157 print 'now try to read something: %r' % sys.stdin.read()
158 158
159 159 def hookoutput(server):
160 160 readchannel(server)
161 161 runcommand(server, ['--config',
162 162 'hooks.pre-identify=python:test-commandserver.hook',
163 163 'id'],
164 164 input=cStringIO.StringIO('some input'))
165 165
166 166 def outsidechanges(server):
167 167 readchannel(server)
168 168 f = open('a', 'ab')
169 169 f.write('a\n')
170 170 f.close()
171 171 runcommand(server, ['status'])
172 172 os.system('hg ci -Am2')
173 173 runcommand(server, ['tip'])
174 174 runcommand(server, ['status'])
175 175
176 176 def bookmarks(server):
177 177 readchannel(server)
178 178 runcommand(server, ['bookmarks'])
179 179
180 180 # changes .hg/bookmarks
181 181 os.system('hg bookmark -i bm1')
182 182 os.system('hg bookmark -i bm2')
183 183 runcommand(server, ['bookmarks'])
184 184
185 185 # changes .hg/bookmarks.current
186 186 os.system('hg upd bm1 -q')
187 187 runcommand(server, ['bookmarks'])
188 188
189 189 runcommand(server, ['bookmarks', 'bm3'])
190 190 f = open('a', 'ab')
191 191 f.write('a\n')
192 192 f.close()
193 193 runcommand(server, ['commit', '-Amm'])
194 194 runcommand(server, ['bookmarks'])
195 195
196 196 def tagscache(server):
197 197 readchannel(server)
198 198 runcommand(server, ['id', '-t', '-r', '0'])
199 199 os.system('hg tag -r 0 foo')
200 200 runcommand(server, ['id', '-t', '-r', '0'])
201 201
202 202 def setphase(server):
203 203 readchannel(server)
204 204 runcommand(server, ['phase', '-r', '.'])
205 205 os.system('hg phase -r . -p')
206 206 runcommand(server, ['phase', '-r', '.'])
207 207
208 208 def rollback(server):
209 209 readchannel(server)
210 210 runcommand(server, ['phase', '-r', '.', '-p'])
211 211 f = open('a', 'ab')
212 212 f.write('a\n')
213 213 f.close()
214 214 runcommand(server, ['commit', '-Am.'])
215 215 runcommand(server, ['rollback'])
216 216 runcommand(server, ['phase', '-r', '.'])
217 217
218 218 def branch(server):
219 219 readchannel(server)
220 220 runcommand(server, ['branch'])
221 221 os.system('hg branch foo')
222 222 runcommand(server, ['branch'])
223 223 os.system('hg branch default')
224 224
225 225 def hgignore(server):
226 226 readchannel(server)
227 227 f = open('.hgignore', 'ab')
228 228 f.write('')
229 229 f.close()
230 230 runcommand(server, ['commit', '-Am.'])
231 231 f = open('ignored-file', 'ab')
232 232 f.write('')
233 233 f.close()
234 234 f = open('.hgignore', 'ab')
235 235 f.write('ignored-file')
236 236 f.close()
237 237 runcommand(server, ['status', '-i', '-u'])
238 238
239 239 def phasecacheafterstrip(server):
240 240 readchannel(server)
241 241
242 242 # create new head, 5:731265503d86
243 243 runcommand(server, ['update', '-C', '0'])
244 244 f = open('a', 'ab')
245 245 f.write('a\n')
246 246 f.close()
247 247 runcommand(server, ['commit', '-Am.', 'a'])
248 248 runcommand(server, ['log', '-Gq'])
249 249
250 250 # make it public; draft marker moves to 4:7966c8e3734d
251 251 runcommand(server, ['phase', '-p', '.'])
252 252 runcommand(server, ['phase', '.']) # load _phasecache.phaseroots
253 253
254 254 # strip 1::4 outside server
255 os.system('hg --config extensions.mq= strip 1')
255 os.system('hg -q --config extensions.mq= strip 1')
256 256
257 257 # shouldn't raise "7966c8e3734d: no node!"
258 258 runcommand(server, ['branches'])
259 259
260 260 if __name__ == '__main__':
261 261 os.system('hg init')
262 262
263 263 check(hellomessage)
264 264 check(unknowncommand)
265 265 check(checkruncommand)
266 266 check(inputeof)
267 267 check(serverinput)
268 268 check(cwd)
269 269
270 270 hgrc = open('.hg/hgrc', 'a')
271 271 hgrc.write('[ui]\nfoo=bar\n')
272 272 hgrc.close()
273 273 check(localhgrc)
274 274 check(hookoutput)
275 275 check(outsidechanges)
276 276 check(bookmarks)
277 277 check(tagscache)
278 278 check(setphase)
279 279 check(rollback)
280 280 check(branch)
281 281 check(hgignore)
282 282 check(phasecacheafterstrip)
@@ -1,192 +1,191 b''
1 1
2 2 testing hellomessage:
3 3
4 4 o, 'capabilities: getencoding runcommand\nencoding: ***'
5 5 runcommand id
6 6 000000000000 tip
7 7
8 8 testing unknowncommand:
9 9
10 10 abort: unknown command unknowncommand
11 11
12 12 testing checkruncommand:
13 13
14 14 runcommand
15 15 Mercurial Distributed SCM
16 16
17 17 basic commands:
18 18
19 19 add add the specified files on the next commit
20 20 annotate show changeset information by line for each file
21 21 clone make a copy of an existing repository
22 22 commit commit the specified files or all outstanding changes
23 23 diff diff repository (or selected files)
24 24 export dump the header and diffs for one or more changesets
25 25 forget forget the specified files on the next commit
26 26 init create a new repository in the given directory
27 27 log show revision history of entire repository or files
28 28 merge merge working directory with another revision
29 29 pull pull changes from the specified source
30 30 push push changes to the specified destination
31 31 remove remove the specified files on the next commit
32 32 serve start stand-alone webserver
33 33 status show changed files in the working directory
34 34 summary summarize working directory state
35 35 update update working directory (or switch revisions)
36 36
37 37 use "hg help" for the full list of commands or "hg -v" for details
38 38 runcommand id --quiet
39 39 000000000000
40 40 runcommand id
41 41 000000000000 tip
42 42 runcommand id --config ui.quiet=True
43 43 000000000000
44 44 runcommand id
45 45 000000000000 tip
46 46
47 47 testing inputeof:
48 48
49 49 server exit code = 1
50 50
51 51 testing serverinput:
52 52
53 53 runcommand import -
54 54 applying patch from stdin
55 55 runcommand log
56 56 changeset: 0:eff892de26ec
57 57 tag: tip
58 58 user: test
59 59 date: Thu Jan 01 00:00:00 1970 +0000
60 60 summary: 1
61 61
62 62
63 63 testing cwd:
64 64
65 65 runcommand --cwd foo st bar
66 66 ? bar
67 67 runcommand st foo/bar
68 68 ? foo/bar
69 69
70 70 testing localhgrc:
71 71
72 72 runcommand showconfig
73 73 bundle.mainreporoot=$TESTTMP
74 74 defaults.backout=-d "0 0"
75 75 defaults.commit=-d "0 0"
76 76 defaults.tag=-d "0 0"
77 77 ui.slash=True
78 78 ui.interactive=False
79 79 ui.foo=bar
80 80 runcommand init foo
81 81 runcommand -R foo showconfig ui defaults
82 82 defaults.backout=-d "0 0"
83 83 defaults.commit=-d "0 0"
84 84 defaults.tag=-d "0 0"
85 85 ui.slash=True
86 86 ui.interactive=False
87 87
88 88 testing hookoutput:
89 89
90 90 runcommand --config hooks.pre-identify=python:test-commandserver.hook id
91 91 hook talking
92 92 now try to read something: 'some input'
93 93 eff892de26ec tip
94 94
95 95 testing outsidechanges:
96 96
97 97 runcommand status
98 98 M a
99 99 runcommand tip
100 100 changeset: 1:d3a0a68be6de
101 101 tag: tip
102 102 user: test
103 103 date: Thu Jan 01 00:00:00 1970 +0000
104 104 summary: 2
105 105
106 106 runcommand status
107 107
108 108 testing bookmarks:
109 109
110 110 runcommand bookmarks
111 111 no bookmarks set
112 112 runcommand bookmarks
113 113 bm1 1:d3a0a68be6de
114 114 bm2 1:d3a0a68be6de
115 115 runcommand bookmarks
116 116 * bm1 1:d3a0a68be6de
117 117 bm2 1:d3a0a68be6de
118 118 runcommand bookmarks bm3
119 119 runcommand commit -Amm
120 120 runcommand bookmarks
121 121 bm1 1:d3a0a68be6de
122 122 bm2 1:d3a0a68be6de
123 123 * bm3 2:aef17e88f5f0
124 124
125 125 testing tagscache:
126 126
127 127 runcommand id -t -r 0
128 128
129 129 runcommand id -t -r 0
130 130 foo
131 131
132 132 testing setphase:
133 133
134 134 runcommand phase -r .
135 135 3: draft
136 136 runcommand phase -r .
137 137 3: public
138 138
139 139 testing rollback:
140 140
141 141 runcommand phase -r . -p
142 142 no phases changed
143 143 runcommand commit -Am.
144 144 runcommand rollback
145 145 repository tip rolled back to revision 3 (undo commit)
146 146 working directory now based on revision 3
147 147 runcommand phase -r .
148 148 3: public
149 149
150 150 testing branch:
151 151
152 152 runcommand branch
153 153 default
154 154 marked working directory as branch foo
155 155 (branches are permanent and global, did you want a bookmark?)
156 156 runcommand branch
157 157 foo
158 158 marked working directory as branch default
159 159 (branches are permanent and global, did you want a bookmark?)
160 160
161 161 testing hgignore:
162 162
163 163 runcommand commit -Am.
164 164 adding .hgignore
165 165 runcommand status -i -u
166 166 I ignored-file
167 167
168 168 testing phasecacheafterstrip:
169 169
170 170 runcommand update -C 0
171 171 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
172 172 runcommand commit -Am. a
173 173 created new head
174 174 runcommand log -Gq
175 175 @ 5:731265503d86
176 176 |
177 177 | o 4:7966c8e3734d
178 178 | |
179 179 | o 3:b9b85890c400
180 180 | |
181 181 | o 2:aef17e88f5f0
182 182 | |
183 183 | o 1:d3a0a68be6de
184 184 |/
185 185 o 0:eff892de26ec
186 186
187 187 runcommand phase -p .
188 188 runcommand phase .
189 189 5: public
190 saved backup bundle to $TESTTMP/.hg/strip-backup/d3a0a68be6de-backup.hg
191 190 runcommand branches
192 191 default 1:731265503d86
General Comments 0
You need to be logged in to leave comments. Login now