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