Fix compiler warning due to missing function prototype.
[svn.git] / contrib / client-side / svnmucc / svnmucc-test.py
blob5ebc30e7928cbedbf9c9efd67c4d9dd05027525a
1 #!/usr/bin/env python
3 # Usage: svnmucc-test.py [build-dir-top [base-url]]
5 import sys
6 import os
7 import re
8 import shutil
10 # calculate the absolute directory in which this test script lives
11 this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
13 # add the Subversion Python test suite libraries to the path, and import
14 sys.path.insert(0, '%s/../../../subversion/tests/cmdline' % (this_dir))
15 import svntest
17 # calculate the top of the build tree
18 if len(sys.argv) > 1:
19 build_top = os.path.abspath(sys.argv[1])
20 else:
21 build_top = os.path.abspath('%s/../../../' % (this_dir))
23 # where lives svnmucc?
24 svnmucc_binary = \
25 os.path.abspath('%s/contrib/client-side/svnmucc/svnmucc' % (build_top))
27 # override some svntest binary locations
28 svntest.main.svn_binary = \
29 os.path.abspath('%s/subversion/svn/svn' % (build_top))
30 svntest.main.svnlook_binary = \
31 os.path.abspath('%s/subversion/svnlook/svnlook' % (build_top))
32 svntest.main.svnadmin_binary = \
33 os.path.abspath('%s/subversion/svnadmin/svnadmin' % (build_top))
35 # where lives the test repository?
36 repos_path = \
37 os.path.abspath(('%s/contrib/client-side/svnmucc/svnmucc-test-repos'
38 % (build_top)))
40 if (len(sys.argv) > 2):
41 repos_url = sys.argv[2] + '/svnmucc-test-repos'
42 else:
43 repos_url = 'file://' + repos_path
45 def die(msg):
46 """Write MSG (formatted as a failure) to stderr, and exit with a
47 non-zero errorcode."""
49 sys.stderr.write("FAIL: " + msg + "\n")
50 sys.exit(1)
53 _svnmucc_re = re.compile('^(r[0-9]+) committed by svnmuccuser at (.*)$')
54 _log_re = re.compile('^ ([ADRM] /[^\(]+($| \(from .*:[0-9]+\)$))')
56 def run_svnmucc(expected_path_changes, *varargs):
57 """Run svnmucc with the list of SVNMUCC_ARGS arguments. Verify that
58 its run results in a new commit with 'svn log -rHEAD' changed paths
59 that match the list of EXPECTED_PATH_CHANGES."""
61 # First, run svnmucc.
62 exit_code, outlines, errlines = \
63 svntest.main.run_command(svnmucc_binary, 1, 0,
64 '-U', repos_url,
65 '-u', 'svnmuccuser',
66 '-p', 'svnmuccpass',
67 '--config-dir', 'dummy',
68 *varargs)
69 if errlines:
70 raise svntest.main.SVNCommitFailure(str(errlines))
71 if len(outlines) != 1 or not _svnmucc_re.match(outlines[0]):
72 raise svntest.main.SVNLineUnequal(str(outlines))
74 # Now, run 'svn log -vq -rHEAD'
75 changed_paths = []
76 exit_code, outlines, errlines = \
77 svntest.main.run_svn(None, 'log', '-vqrHEAD', repos_url)
78 if errlines:
79 raise svntest.Failure("Unable to verify commit with 'svn log': %s"
80 % (str(errlines)))
81 for line in outlines:
82 match = _log_re.match(line)
83 if match:
84 changed_paths.append(match.group(1).rstrip('\n\r'))
86 expected_path_changes.sort()
87 changed_paths.sort()
88 if changed_paths != expected_path_changes:
89 raise svntest.Failure("Logged path changes differ from expectations\n"
90 " expected: %s\n"
91 " actual: %s" % (str(expected_path_changes),
92 str(changed_paths)))
95 def main():
96 """Test svnmucc."""
98 # revision 1
99 run_svnmucc(['A /foo'
100 ], # ---------
101 'mkdir', 'foo')
103 # revision 2
104 run_svnmucc(['A /z.c',
105 ], # ---------
106 'put', '/dev/null', 'z.c')
108 # revision 3
109 run_svnmucc(['A /foo/z.c (from /z.c:2)',
110 'A /foo/bar (from /foo:2)',
111 ], # ---------
112 'cp', '2', 'z.c', 'foo/z.c',
113 'cp', '2', 'foo', 'foo/bar')
115 # revision 4
116 run_svnmucc(['A /zig (from /foo:3)',
117 'D /zig/bar',
118 'D /foo',
119 'A /zig/zag (from /foo:3)',
120 ], # ---------
121 'cp', '3', 'foo', 'zig',
122 'rm', 'zig/bar',
123 'mv', 'foo', 'zig/zag')
125 # revision 5
126 run_svnmucc(['D /z.c',
127 'A /zig/zag/bar/y.c (from /z.c:4)',
128 'A /zig/zag/bar/x.c (from /z.c:2)',
129 ], # ---------
130 'mv', 'z.c', 'zig/zag/bar/y.c',
131 'cp', '2', 'z.c', 'zig/zag/bar/x.c')
133 # revision 6
134 run_svnmucc(['D /zig/zag/bar/y.c',
135 'A /zig/zag/bar/y y.c (from /zig/zag/bar/y.c:5)',
136 'A /zig/zag/bar/y%20y.c (from /zig/zag/bar/y.c:5)',
137 ], # ---------
138 'mv', 'zig/zag/bar/y.c', 'zig/zag/bar/y%20y.c',
139 'cp', 'HEAD', 'zig/zag/bar/y.c', 'zig/zag/bar/y%2520y.c')
141 # revision 7
142 run_svnmucc(['D /zig/zag/bar/y y.c',
143 'A /zig/zag/bar/z z1.c (from /zig/zag/bar/y y.c:6)',
144 'A /zig/zag/bar/z%20z.c (from /zig/zag/bar/y%20y.c:6)',
145 'A /zig/zag/bar/z z2.c (from /zig/zag/bar/y y.c:6)',
146 ], #---------
147 'mv', 'zig/zag/bar/y%20y.c', 'zig/zag/bar/z z1.c',
148 'cp', 'HEAD', 'zig/zag/bar/y%2520y.c', 'zig/zag/bar/z%2520z.c',
149 'cp', 'HEAD', 'zig/zag/bar/y y.c', 'zig/zag/bar/z z2.c')
151 # revision 8
152 run_svnmucc(['D /zig/zag',
153 'A /zig/foo (from /zig/zag:7)',
154 'D /zig/foo/bar/z%20z.c',
155 'D /zig/foo/bar/z z2.c',
156 'R /zig/foo/bar/z z1.c (from /zig/zag/bar/x.c:5)',
157 ], #---------
158 'mv', 'zig/zag', 'zig/foo',
159 'rm', 'zig/foo/bar/z z1.c',
160 'rm', 'zig/foo/bar/z%20z2.c',
161 'rm', 'zig/foo/bar/z%2520z.c',
162 'cp', '5', 'zig/zag/bar/x.c', 'zig/foo/bar/z%20z1.c')
164 # revision 9
165 run_svnmucc(['R /zig/foo/bar (from /zig/z.c:8)',
166 ], #---------
167 'rm', 'zig/foo/bar',
168 'cp', '8', 'zig/z.c', 'zig/foo/bar')
170 # revision 10
171 run_svnmucc(['R /zig/foo/bar (from /zig/foo/bar:8)',
172 'D /zig/foo/bar/z z1.c',
173 ], #---------
174 'rm', 'zig/foo/bar',
175 'cp', '8', 'zig/foo/bar', 'zig/foo/bar',
176 'rm', 'zig/foo/bar/z%20z1.c')
178 # revision 11
179 run_svnmucc(['R /zig/foo (from /zig/foo/bar:10)',
180 ], #---------
181 'rm', 'zig/foo',
182 'cp', 'head', 'zig/foo/bar', 'zig/foo')
184 # revision 12
185 run_svnmucc(['D /zig',
186 'A /foo (from /foo:3)',
187 'A /foo/foo (from /foo:3)',
188 'A /foo/foo/foo (from /foo:3)',
189 'D /foo/foo/bar',
190 'R /foo/foo/foo/bar (from /foo:3)',
191 ], #---------
192 'rm', 'zig',
193 'cp', '3', 'foo', 'foo',
194 'cp', '3', 'foo', 'foo/foo',
195 'cp', '3', 'foo', 'foo/foo/foo',
196 'rm', 'foo/foo/bar',
197 'rm', 'foo/foo/foo/bar',
198 'cp', '3', 'foo', 'foo/foo/foo/bar')
200 # revision 13
201 run_svnmucc(['A /boozle (from /foo:3)',
202 'A /boozle/buz',
203 'A /boozle/buz/nuz',
204 ], #---------
205 'cp', '3', 'foo', 'boozle',
206 'mkdir', 'boozle/buz',
207 'mkdir', 'boozle/buz/nuz')
209 # revision 14
210 run_svnmucc(['A /boozle/buz/svnmucc-test.py',
211 'A /boozle/guz (from /boozle/buz:13)',
212 'A /boozle/guz/svnmucc-test.py',
213 ], #---------
214 'put', '/dev/null', 'boozle/buz/svnmucc-test.py',
215 'cp', '13', 'boozle/buz', 'boozle/guz',
216 'put', '/dev/null', 'boozle/guz/svnmucc-test.py')
218 # revision 15
219 run_svnmucc(['M /boozle/buz/svnmucc-test.py',
220 'R /boozle/guz/svnmucc-test.py',
221 ], #---------
222 'put', sys.argv[0], 'boozle/buz/svnmucc-test.py',
223 'rm', 'boozle/guz/svnmucc-test.py',
224 'put', sys.argv[0], 'boozle/guz/svnmucc-test.py')
226 # revision 16
227 run_svnmucc(['R /foo/bar (from /foo/foo:15)'], #---------
228 'rm', 'foo/bar',
229 'cp', '15', 'foo/foo', 'foo/bar',
230 'propset', 'testprop', 'true', 'foo/bar')
232 # revision 17
233 run_svnmucc(['M /foo/bar'], #---------
234 'propdel', 'testprop', 'foo/bar')
236 if __name__ == "__main__":
237 try:
238 # remove any previously existing repository, then create a new one
239 if os.path.exists(repos_path):
240 shutil.rmtree(repos_path)
241 exit_code, outlines, errlines = \
242 svntest.main.run_svnadmin('create', '--fs-type',
243 'fsfs', repos_path)
244 if errlines:
245 raise svntest.main.SVNRepositoryCreateFailure(repos_path)
246 fp = open(os.path.join(repos_path, 'conf', 'svnserve.conf'), 'w')
247 fp.write('[general]\nauth-access = write\npassword-db = passwd\n')
248 fp.close()
249 fp = open(os.path.join(repos_path, 'conf', 'passwd'), 'w')
250 fp.write('[users]\nsvnmuccuser = svnmuccpass\n')
251 fp.close()
252 main()
253 except SystemExit, e:
254 raise
255 except svntest.main.SVNCommitFailure, e:
256 die("Error committing via svnmucc: %s" % (str(e)))
257 except svntest.main.SVNLineUnequal, e:
258 die("Unexpected svnmucc output line: %s" % (str(e)))
259 except svntest.main.SVNRepositoryCreateFailure, e:
260 die("Error creating test repository: %s" % (str(e)))
261 except svntest.Failure, e:
262 die("Test failed: %s" % (str(e)))
263 except Exception, e:
264 die("Something bad happened: %s" % (str(e)))
266 # cleanup the repository on a successful run
267 try:
268 if os.path.exists(repos_path):
269 shutil.rmtree(repos_path)
270 except:
271 pass
272 print "SUCCESS!"