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