Show More
@@ -1,202 +1,205 | |||
|
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 | server.stdin.write('runcommand\n') |
|
31 | 31 | writeblock(server, '\0'.join(args)) |
|
32 | 32 | |
|
33 | 33 | if not input: |
|
34 | 34 | input = cStringIO.StringIO() |
|
35 | 35 | |
|
36 | 36 | while True: |
|
37 | 37 | ch, data = readchannel(server) |
|
38 | 38 | if ch == 'o': |
|
39 | 39 | output.write(data) |
|
40 | 40 | output.flush() |
|
41 | 41 | elif ch == 'e': |
|
42 | 42 | error.write(data) |
|
43 | 43 | error.flush() |
|
44 | 44 | elif ch == 'I': |
|
45 | 45 | writeblock(server, input.read(data)) |
|
46 | 46 | elif ch == 'L': |
|
47 | 47 | writeblock(server, input.readline(data)) |
|
48 | 48 | elif ch == 'r': |
|
49 | 49 | return struct.unpack('>i', data)[0] |
|
50 | 50 | else: |
|
51 | 51 | print "unexpected channel %c: %r" % (ch, data) |
|
52 | 52 | if ch.isupper(): |
|
53 | 53 | return |
|
54 | 54 | |
|
55 | 55 | def check(func, repopath=None): |
|
56 | 56 | |
|
57 | 57 | print 'testing %s:' % func.__name__ |
|
58 | 58 | |
|
59 | 59 | server = connect(repopath) |
|
60 | 60 | try: |
|
61 | 61 | return func(server) |
|
62 | 62 | finally: |
|
63 | 63 | server.stdin.close() |
|
64 | 64 | server.wait() |
|
65 | 65 | |
|
66 | 66 | def unknowncommand(server): |
|
67 | 67 | server.stdin.write('unknowncommand\n') |
|
68 | 68 | |
|
69 | 69 | def hellomessage(server): |
|
70 | 70 | ch, data = readchannel(server) |
|
71 | 71 | # escaping python tests output not supported |
|
72 | 72 | print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***', data)) |
|
73 | 73 | |
|
74 | 74 | # run an arbitrary command to make sure the next thing the server sends |
|
75 | 75 | # isn't part of the hello message |
|
76 | 76 | runcommand(server, ['id']) |
|
77 | 77 | |
|
78 | 78 | def checkruncommand(server): |
|
79 | 79 | # hello block |
|
80 | 80 | readchannel(server) |
|
81 | 81 | |
|
82 | 82 | # no args |
|
83 | 83 | runcommand(server, []) |
|
84 | 84 | |
|
85 | 85 | # global options |
|
86 | 86 | runcommand(server, ['id', '--quiet']) |
|
87 | 87 | |
|
88 | 88 | # make sure global options don't stick through requests |
|
89 | 89 | runcommand(server, ['id']) |
|
90 | 90 | |
|
91 | 91 | # --config |
|
92 | 92 | runcommand(server, ['id', '--config', 'ui.quiet=True']) |
|
93 | 93 | |
|
94 | 94 | # make sure --config doesn't stick |
|
95 | 95 | runcommand(server, ['id']) |
|
96 | 96 | |
|
97 | 97 | def inputeof(server): |
|
98 | 98 | readchannel(server) |
|
99 | 99 | server.stdin.write('runcommand\n') |
|
100 | 100 | # close stdin while server is waiting for input |
|
101 | 101 | server.stdin.close() |
|
102 | 102 | |
|
103 | 103 | # server exits with 1 if the pipe closed while reading the command |
|
104 | 104 | print 'server exit code =', server.wait() |
|
105 | 105 | |
|
106 | 106 | def serverinput(server): |
|
107 | 107 | readchannel(server) |
|
108 | 108 | |
|
109 | 109 | patch = """ |
|
110 | 110 | # HG changeset patch |
|
111 | 111 | # User test |
|
112 | 112 | # Date 0 0 |
|
113 | 113 | # Node ID c103a3dec114d882c98382d684d8af798d09d857 |
|
114 | 114 | # Parent 0000000000000000000000000000000000000000 |
|
115 | 115 | 1 |
|
116 | 116 | |
|
117 | 117 | diff -r 000000000000 -r c103a3dec114 a |
|
118 | 118 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
119 | 119 | +++ b/a Thu Jan 01 00:00:00 1970 +0000 |
|
120 | 120 | @@ -0,0 +1,1 @@ |
|
121 | 121 | +1 |
|
122 | 122 | """ |
|
123 | 123 | |
|
124 | 124 | runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch)) |
|
125 | 125 | runcommand(server, ['log']) |
|
126 | 126 | |
|
127 | 127 | def cwd(server): |
|
128 | 128 | """ check that --cwd doesn't persist between requests """ |
|
129 | 129 | readchannel(server) |
|
130 | 130 | os.mkdir('foo') |
|
131 | f = open('foo/bar', 'w') | |
|
131 | f = open('foo/bar', 'wb') | |
|
132 | 132 | f.write('a') |
|
133 | 133 | f.close() |
|
134 | 134 | runcommand(server, ['--cwd', 'foo', 'st', 'bar']) |
|
135 | 135 | runcommand(server, ['st', 'foo/bar']) |
|
136 | 136 | os.remove('foo/bar') |
|
137 | 137 | |
|
138 | 138 | def localhgrc(server): |
|
139 | 139 | """ check that local configs for the cached repo aren't inherited when -R |
|
140 | 140 | is used """ |
|
141 | 141 | readchannel(server) |
|
142 | 142 | |
|
143 | 143 | # the cached repo local hgrc contains ui.foo=bar, so showconfig should show it |
|
144 | 144 | runcommand(server, ['showconfig']) |
|
145 | 145 | |
|
146 | 146 | # but not for this repo |
|
147 | 147 | runcommand(server, ['init', 'foo']) |
|
148 | runcommand(server, ['-R', 'foo', 'showconfig']) | |
|
148 | runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults']) | |
|
149 | 149 | shutil.rmtree('foo') |
|
150 | 150 | |
|
151 | 151 | def hook(**args): |
|
152 | 152 | print 'hook talking' |
|
153 | 153 | print 'now try to read something: %r' % sys.stdin.read() |
|
154 | 154 | |
|
155 | 155 | def hookoutput(server): |
|
156 | 156 | readchannel(server) |
|
157 | 157 | runcommand(server, ['--config', |
|
158 | 158 | 'hooks.pre-identify=python:test-commandserver.hook', 'id'], |
|
159 | 159 | input=cStringIO.StringIO('some input')) |
|
160 | 160 | |
|
161 | 161 | def outsidechanges(server): |
|
162 | 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 | 167 | runcommand(server, ['tip']) |
|
165 | 168 | |
|
166 | 169 | def bookmarks(server): |
|
167 | 170 | readchannel(server) |
|
168 | 171 | runcommand(server, ['bookmarks']) |
|
169 | 172 | |
|
170 | 173 | # changes .hg/bookmarks |
|
171 | 174 | os.system('hg bookmark -i bm1') |
|
172 | 175 | os.system('hg bookmark -i bm2') |
|
173 | 176 | runcommand(server, ['bookmarks']) |
|
174 | 177 | |
|
175 | 178 | # changes .hg/bookmarks.current |
|
176 | 179 | os.system('hg upd bm1 -q') |
|
177 | 180 | runcommand(server, ['bookmarks']) |
|
178 | 181 | |
|
179 | 182 | def tagscache(server): |
|
180 | 183 | readchannel(server) |
|
181 | 184 | runcommand(server, ['id', '-t', '-r', '0']) |
|
182 | 185 | os.system('hg tag -r 0 foo') |
|
183 | 186 | runcommand(server, ['id', '-t', '-r', '0']) |
|
184 | 187 | |
|
185 | 188 | if __name__ == '__main__': |
|
186 | 189 | os.system('hg init') |
|
187 | 190 | |
|
188 | 191 | check(hellomessage) |
|
189 | 192 | check(unknowncommand) |
|
190 | 193 | check(checkruncommand) |
|
191 | 194 | check(inputeof) |
|
192 | 195 | check(serverinput) |
|
193 | 196 | check(cwd) |
|
194 | 197 | |
|
195 | 198 | hgrc = open('.hg/hgrc', 'a') |
|
196 | 199 | hgrc.write('[ui]\nfoo=bar\n') |
|
197 | 200 | hgrc.close() |
|
198 | 201 | check(localhgrc) |
|
199 | 202 | check(hookoutput) |
|
200 | 203 | check(outsidechanges) |
|
201 | 204 | check(bookmarks) |
|
202 | 205 | check(tagscache) |
@@ -1,120 +1,119 | |||
|
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 | abort: unknown command unknowncommand |
|
8 | 8 | |
|
9 | 9 | testing unknowncommand: |
|
10 | 10 | |
|
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.foo=bar |
|
79 | 79 | runcommand init foo |
|
80 | runcommand -R foo showconfig | |
|
81 | bundle.mainreporoot=$TESTTMP/foo | |
|
80 | runcommand -R foo showconfig ui defaults | |
|
82 | 81 | defaults.backout=-d "0 0" |
|
83 | 82 | defaults.commit=-d "0 0" |
|
84 | 83 | defaults.tag=-d "0 0" |
|
85 | 84 | ui.slash=True |
|
86 | 85 | |
|
87 | 86 | testing hookoutput: |
|
88 | 87 | |
|
89 | 88 | runcommand --config hooks.pre-identify=python:test-commandserver.hook id |
|
90 | 89 | hook talking |
|
91 | 90 | now try to read something: 'some input' |
|
92 | 91 | eff892de26ec tip |
|
93 | 92 | |
|
94 | 93 | testing outsidechanges: |
|
95 | 94 | |
|
96 | 95 | runcommand tip |
|
97 | 96 | changeset: 1:d3a0a68be6de |
|
98 | 97 | tag: tip |
|
99 | 98 | user: test |
|
100 | 99 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
101 | 100 | summary: 2 |
|
102 | 101 | |
|
103 | 102 | |
|
104 | 103 | testing bookmarks: |
|
105 | 104 | |
|
106 | 105 | runcommand bookmarks |
|
107 | 106 | no bookmarks set |
|
108 | 107 | runcommand bookmarks |
|
109 | 108 | bm1 1:d3a0a68be6de |
|
110 | 109 | bm2 1:d3a0a68be6de |
|
111 | 110 | runcommand bookmarks |
|
112 | 111 | * bm1 1:d3a0a68be6de |
|
113 | 112 | bm2 1:d3a0a68be6de |
|
114 | 113 | |
|
115 | 114 | testing tagscache: |
|
116 | 115 | |
|
117 | 116 | runcommand id -t -r 0 |
|
118 | 117 | |
|
119 | 118 | runcommand id -t -r 0 |
|
120 | 119 | foo |
General Comments 0
You need to be logged in to leave comments.
Login now