##// END OF EJS Templates
tests: make test-commandserver.py independent of line ending and slash direction
Mads Kiilerich -
r15542:e1930259 default
parent child Browse files
Show More
@@ -1,202 +1,205
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 runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None):
29 print ' runcommand', ' '.join(args)
29 print ' runcommand', ' '.join(args)
30 server.stdin.write('runcommand\n')
30 server.stdin.write('runcommand\n')
31 writeblock(server, '\0'.join(args))
31 writeblock(server, '\0'.join(args))
32
32
33 if not input:
33 if not input:
34 input = cStringIO.StringIO()
34 input = cStringIO.StringIO()
35
35
36 while True:
36 while True:
37 ch, data = readchannel(server)
37 ch, data = readchannel(server)
38 if ch == 'o':
38 if ch == 'o':
39 output.write(data)
39 output.write(data)
40 output.flush()
40 output.flush()
41 elif ch == 'e':
41 elif ch == 'e':
42 error.write(data)
42 error.write(data)
43 error.flush()
43 error.flush()
44 elif ch == 'I':
44 elif ch == 'I':
45 writeblock(server, input.read(data))
45 writeblock(server, input.read(data))
46 elif ch == 'L':
46 elif ch == 'L':
47 writeblock(server, input.readline(data))
47 writeblock(server, input.readline(data))
48 elif ch == 'r':
48 elif ch == 'r':
49 return struct.unpack('>i', data)[0]
49 return struct.unpack('>i', data)[0]
50 else:
50 else:
51 print "unexpected channel %c: %r" % (ch, data)
51 print "unexpected channel %c: %r" % (ch, data)
52 if ch.isupper():
52 if ch.isupper():
53 return
53 return
54
54
55 def check(func, repopath=None):
55 def check(func, repopath=None):
56 print
56 print
57 print 'testing %s:' % func.__name__
57 print 'testing %s:' % func.__name__
58 print
58 print
59 server = connect(repopath)
59 server = connect(repopath)
60 try:
60 try:
61 return func(server)
61 return func(server)
62 finally:
62 finally:
63 server.stdin.close()
63 server.stdin.close()
64 server.wait()
64 server.wait()
65
65
66 def unknowncommand(server):
66 def unknowncommand(server):
67 server.stdin.write('unknowncommand\n')
67 server.stdin.write('unknowncommand\n')
68
68
69 def hellomessage(server):
69 def hellomessage(server):
70 ch, data = readchannel(server)
70 ch, data = readchannel(server)
71 # escaping python tests output not supported
71 # escaping python tests output not supported
72 print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***', data))
72 print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***', data))
73
73
74 # run an arbitrary command to make sure the next thing the server sends
74 # run an arbitrary command to make sure the next thing the server sends
75 # isn't part of the hello message
75 # isn't part of the hello message
76 runcommand(server, ['id'])
76 runcommand(server, ['id'])
77
77
78 def checkruncommand(server):
78 def checkruncommand(server):
79 # hello block
79 # hello block
80 readchannel(server)
80 readchannel(server)
81
81
82 # no args
82 # no args
83 runcommand(server, [])
83 runcommand(server, [])
84
84
85 # global options
85 # global options
86 runcommand(server, ['id', '--quiet'])
86 runcommand(server, ['id', '--quiet'])
87
87
88 # make sure global options don't stick through requests
88 # make sure global options don't stick through requests
89 runcommand(server, ['id'])
89 runcommand(server, ['id'])
90
90
91 # --config
91 # --config
92 runcommand(server, ['id', '--config', 'ui.quiet=True'])
92 runcommand(server, ['id', '--config', 'ui.quiet=True'])
93
93
94 # make sure --config doesn't stick
94 # make sure --config doesn't stick
95 runcommand(server, ['id'])
95 runcommand(server, ['id'])
96
96
97 def inputeof(server):
97 def inputeof(server):
98 readchannel(server)
98 readchannel(server)
99 server.stdin.write('runcommand\n')
99 server.stdin.write('runcommand\n')
100 # close stdin while server is waiting for input
100 # close stdin while server is waiting for input
101 server.stdin.close()
101 server.stdin.close()
102
102
103 # server exits with 1 if the pipe closed while reading the command
103 # server exits with 1 if the pipe closed while reading the command
104 print 'server exit code =', server.wait()
104 print 'server exit code =', server.wait()
105
105
106 def serverinput(server):
106 def serverinput(server):
107 readchannel(server)
107 readchannel(server)
108
108
109 patch = """
109 patch = """
110 # HG changeset patch
110 # HG changeset patch
111 # User test
111 # User test
112 # Date 0 0
112 # Date 0 0
113 # Node ID c103a3dec114d882c98382d684d8af798d09d857
113 # Node ID c103a3dec114d882c98382d684d8af798d09d857
114 # Parent 0000000000000000000000000000000000000000
114 # Parent 0000000000000000000000000000000000000000
115 1
115 1
116
116
117 diff -r 000000000000 -r c103a3dec114 a
117 diff -r 000000000000 -r c103a3dec114 a
118 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
118 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
119 +++ b/a Thu Jan 01 00:00:00 1970 +0000
119 +++ b/a Thu Jan 01 00:00:00 1970 +0000
120 @@ -0,0 +1,1 @@
120 @@ -0,0 +1,1 @@
121 +1
121 +1
122 """
122 """
123
123
124 runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
124 runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch))
125 runcommand(server, ['log'])
125 runcommand(server, ['log'])
126
126
127 def cwd(server):
127 def cwd(server):
128 """ check that --cwd doesn't persist between requests """
128 """ check that --cwd doesn't persist between requests """
129 readchannel(server)
129 readchannel(server)
130 os.mkdir('foo')
130 os.mkdir('foo')
131 f = open('foo/bar', 'w')
131 f = open('foo/bar', 'wb')
132 f.write('a')
132 f.write('a')
133 f.close()
133 f.close()
134 runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
134 runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
135 runcommand(server, ['st', 'foo/bar'])
135 runcommand(server, ['st', 'foo/bar'])
136 os.remove('foo/bar')
136 os.remove('foo/bar')
137
137
138 def localhgrc(server):
138 def localhgrc(server):
139 """ check that local configs for the cached repo aren't inherited when -R
139 """ check that local configs for the cached repo aren't inherited when -R
140 is used """
140 is used """
141 readchannel(server)
141 readchannel(server)
142
142
143 # the cached repo local hgrc contains ui.foo=bar, so showconfig should show it
143 # the cached repo local hgrc contains ui.foo=bar, so showconfig should show it
144 runcommand(server, ['showconfig'])
144 runcommand(server, ['showconfig'])
145
145
146 # but not for this repo
146 # but not for this repo
147 runcommand(server, ['init', 'foo'])
147 runcommand(server, ['init', 'foo'])
148 runcommand(server, ['-R', 'foo', 'showconfig'])
148 runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
149 shutil.rmtree('foo')
149 shutil.rmtree('foo')
150
150
151 def hook(**args):
151 def hook(**args):
152 print 'hook talking'
152 print 'hook talking'
153 print 'now try to read something: %r' % sys.stdin.read()
153 print 'now try to read something: %r' % sys.stdin.read()
154
154
155 def hookoutput(server):
155 def hookoutput(server):
156 readchannel(server)
156 readchannel(server)
157 runcommand(server, ['--config',
157 runcommand(server, ['--config',
158 'hooks.pre-identify=python:test-commandserver.hook', 'id'],
158 'hooks.pre-identify=python:test-commandserver.hook', 'id'],
159 input=cStringIO.StringIO('some input'))
159 input=cStringIO.StringIO('some input'))
160
160
161 def outsidechanges(server):
161 def outsidechanges(server):
162 readchannel(server)
162 readchannel(server)
163 os.system('echo a >> a && hg ci -Am2')
163 f = open('a', 'ab')
164 f.write('a\n')
165 f.close()
166 os.system('hg ci -Am2')
164 runcommand(server, ['tip'])
167 runcommand(server, ['tip'])
165
168
166 def bookmarks(server):
169 def bookmarks(server):
167 readchannel(server)
170 readchannel(server)
168 runcommand(server, ['bookmarks'])
171 runcommand(server, ['bookmarks'])
169
172
170 # changes .hg/bookmarks
173 # changes .hg/bookmarks
171 os.system('hg bookmark -i bm1')
174 os.system('hg bookmark -i bm1')
172 os.system('hg bookmark -i bm2')
175 os.system('hg bookmark -i bm2')
173 runcommand(server, ['bookmarks'])
176 runcommand(server, ['bookmarks'])
174
177
175 # changes .hg/bookmarks.current
178 # changes .hg/bookmarks.current
176 os.system('hg upd bm1 -q')
179 os.system('hg upd bm1 -q')
177 runcommand(server, ['bookmarks'])
180 runcommand(server, ['bookmarks'])
178
181
179 def tagscache(server):
182 def tagscache(server):
180 readchannel(server)
183 readchannel(server)
181 runcommand(server, ['id', '-t', '-r', '0'])
184 runcommand(server, ['id', '-t', '-r', '0'])
182 os.system('hg tag -r 0 foo')
185 os.system('hg tag -r 0 foo')
183 runcommand(server, ['id', '-t', '-r', '0'])
186 runcommand(server, ['id', '-t', '-r', '0'])
184
187
185 if __name__ == '__main__':
188 if __name__ == '__main__':
186 os.system('hg init')
189 os.system('hg init')
187
190
188 check(hellomessage)
191 check(hellomessage)
189 check(unknowncommand)
192 check(unknowncommand)
190 check(checkruncommand)
193 check(checkruncommand)
191 check(inputeof)
194 check(inputeof)
192 check(serverinput)
195 check(serverinput)
193 check(cwd)
196 check(cwd)
194
197
195 hgrc = open('.hg/hgrc', 'a')
198 hgrc = open('.hg/hgrc', 'a')
196 hgrc.write('[ui]\nfoo=bar\n')
199 hgrc.write('[ui]\nfoo=bar\n')
197 hgrc.close()
200 hgrc.close()
198 check(localhgrc)
201 check(localhgrc)
199 check(hookoutput)
202 check(hookoutput)
200 check(outsidechanges)
203 check(outsidechanges)
201 check(bookmarks)
204 check(bookmarks)
202 check(tagscache)
205 check(tagscache)
@@ -1,120 +1,119
1
1
2 testing hellomessage:
2 testing hellomessage:
3
3
4 o, 'capabilities: getencoding runcommand\nencoding: ***'
4 o, 'capabilities: getencoding runcommand\nencoding: ***'
5 runcommand id
5 runcommand id
6 000000000000 tip
6 000000000000 tip
7 abort: unknown command unknowncommand
7 abort: unknown command unknowncommand
8
8
9 testing unknowncommand:
9 testing unknowncommand:
10
10
11
11
12 testing checkruncommand:
12 testing checkruncommand:
13
13
14 runcommand
14 runcommand
15 Mercurial Distributed SCM
15 Mercurial Distributed SCM
16
16
17 basic commands:
17 basic commands:
18
18
19 add add the specified files on the next commit
19 add add the specified files on the next commit
20 annotate show changeset information by line for each file
20 annotate show changeset information by line for each file
21 clone make a copy of an existing repository
21 clone make a copy of an existing repository
22 commit commit the specified files or all outstanding changes
22 commit commit the specified files or all outstanding changes
23 diff diff repository (or selected files)
23 diff diff repository (or selected files)
24 export dump the header and diffs for one or more changesets
24 export dump the header and diffs for one or more changesets
25 forget forget the specified files on the next commit
25 forget forget the specified files on the next commit
26 init create a new repository in the given directory
26 init create a new repository in the given directory
27 log show revision history of entire repository or files
27 log show revision history of entire repository or files
28 merge merge working directory with another revision
28 merge merge working directory with another revision
29 pull pull changes from the specified source
29 pull pull changes from the specified source
30 push push changes to the specified destination
30 push push changes to the specified destination
31 remove remove the specified files on the next commit
31 remove remove the specified files on the next commit
32 serve start stand-alone webserver
32 serve start stand-alone webserver
33 status show changed files in the working directory
33 status show changed files in the working directory
34 summary summarize working directory state
34 summary summarize working directory state
35 update update working directory (or switch revisions)
35 update update working directory (or switch revisions)
36
36
37 use "hg help" for the full list of commands or "hg -v" for details
37 use "hg help" for the full list of commands or "hg -v" for details
38 runcommand id --quiet
38 runcommand id --quiet
39 000000000000
39 000000000000
40 runcommand id
40 runcommand id
41 000000000000 tip
41 000000000000 tip
42 runcommand id --config ui.quiet=True
42 runcommand id --config ui.quiet=True
43 000000000000
43 000000000000
44 runcommand id
44 runcommand id
45 000000000000 tip
45 000000000000 tip
46
46
47 testing inputeof:
47 testing inputeof:
48
48
49 server exit code = 1
49 server exit code = 1
50
50
51 testing serverinput:
51 testing serverinput:
52
52
53 runcommand import -
53 runcommand import -
54 applying patch from stdin
54 applying patch from stdin
55 runcommand log
55 runcommand log
56 changeset: 0:eff892de26ec
56 changeset: 0:eff892de26ec
57 tag: tip
57 tag: tip
58 user: test
58 user: test
59 date: Thu Jan 01 00:00:00 1970 +0000
59 date: Thu Jan 01 00:00:00 1970 +0000
60 summary: 1
60 summary: 1
61
61
62
62
63 testing cwd:
63 testing cwd:
64
64
65 runcommand --cwd foo st bar
65 runcommand --cwd foo st bar
66 ? bar
66 ? bar
67 runcommand st foo/bar
67 runcommand st foo/bar
68 ? foo/bar
68 ? foo/bar
69
69
70 testing localhgrc:
70 testing localhgrc:
71
71
72 runcommand showconfig
72 runcommand showconfig
73 bundle.mainreporoot=$TESTTMP
73 bundle.mainreporoot=$TESTTMP
74 defaults.backout=-d "0 0"
74 defaults.backout=-d "0 0"
75 defaults.commit=-d "0 0"
75 defaults.commit=-d "0 0"
76 defaults.tag=-d "0 0"
76 defaults.tag=-d "0 0"
77 ui.slash=True
77 ui.slash=True
78 ui.foo=bar
78 ui.foo=bar
79 runcommand init foo
79 runcommand init foo
80 runcommand -R foo showconfig
80 runcommand -R foo showconfig ui defaults
81 bundle.mainreporoot=$TESTTMP/foo
82 defaults.backout=-d "0 0"
81 defaults.backout=-d "0 0"
83 defaults.commit=-d "0 0"
82 defaults.commit=-d "0 0"
84 defaults.tag=-d "0 0"
83 defaults.tag=-d "0 0"
85 ui.slash=True
84 ui.slash=True
86
85
87 testing hookoutput:
86 testing hookoutput:
88
87
89 runcommand --config hooks.pre-identify=python:test-commandserver.hook id
88 runcommand --config hooks.pre-identify=python:test-commandserver.hook id
90 hook talking
89 hook talking
91 now try to read something: 'some input'
90 now try to read something: 'some input'
92 eff892de26ec tip
91 eff892de26ec tip
93
92
94 testing outsidechanges:
93 testing outsidechanges:
95
94
96 runcommand tip
95 runcommand tip
97 changeset: 1:d3a0a68be6de
96 changeset: 1:d3a0a68be6de
98 tag: tip
97 tag: tip
99 user: test
98 user: test
100 date: Thu Jan 01 00:00:00 1970 +0000
99 date: Thu Jan 01 00:00:00 1970 +0000
101 summary: 2
100 summary: 2
102
101
103
102
104 testing bookmarks:
103 testing bookmarks:
105
104
106 runcommand bookmarks
105 runcommand bookmarks
107 no bookmarks set
106 no bookmarks set
108 runcommand bookmarks
107 runcommand bookmarks
109 bm1 1:d3a0a68be6de
108 bm1 1:d3a0a68be6de
110 bm2 1:d3a0a68be6de
109 bm2 1:d3a0a68be6de
111 runcommand bookmarks
110 runcommand bookmarks
112 * bm1 1:d3a0a68be6de
111 * bm1 1:d3a0a68be6de
113 bm2 1:d3a0a68be6de
112 bm2 1:d3a0a68be6de
114
113
115 testing tagscache:
114 testing tagscache:
116
115
117 runcommand id -t -r 0
116 runcommand id -t -r 0
118
117
119 runcommand id -t -r 0
118 runcommand id -t -r 0
120 foo
119 foo
General Comments 0
You need to be logged in to leave comments. Login now