summaryrefslogtreecommitdiff
path: root/tools/client-side/svnmucc/svnmucc-test.py
blob: c09d15cf95bf5c3efe8dfe013dcdda04f7802907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#!/usr/bin/env python
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
#

# Usage: svnmucc-test.py [build-dir-top [base-url]]

import sys
import os
import re
import shutil

# calculate the absolute directory in which this test script lives
this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))

# add the Subversion Python test suite libraries to the path, and import
sys.path.insert(0, '%s/../../../subversion/tests/cmdline' % (this_dir))
import svntest

# setup the global 'svntest.main.options' object so functions in the
# module don't freak out.
svntest.main._parse_options(arglist=[])

# calculate the top of the build tree
if len(sys.argv) > 1:
  build_top = os.path.abspath(sys.argv[1])
else:
  build_top = os.path.abspath('%s/../../../' % (this_dir))

# where lives svnmucc?
svnmucc_binary = \
   os.path.abspath('%s/tools/client-side/svnmucc/svnmucc' % (build_top))

# override some svntest binary locations
svntest.main.svn_binary = \
   os.path.abspath('%s/subversion/svn/svn' % (build_top))
svntest.main.svnlook_binary = \
   os.path.abspath('%s/subversion/svnlook/svnlook' % (build_top))
svntest.main.svnadmin_binary = \
   os.path.abspath('%s/subversion/svnadmin/svnadmin' % (build_top))

# where lives the test repository?
repos_path = \
   os.path.abspath(('%s/tools/client-side/svnmucc/svnmucc-test-repos'
                    % (build_top)))

if (len(sys.argv) > 2):
  repos_url = sys.argv[2] + '/svnmucc-test-repos'
else:
  repos_url = 'file://' + repos_path

def die(msg):
  """Write MSG (formatted as a failure) to stderr, and exit with a
  non-zero errorcode."""

  sys.stderr.write("FAIL: " + msg + "\n")
  sys.exit(1)


_svnmucc_re = re.compile('^(r[0-9]+) committed by svnmuccuser at (.*)$')
_log_re = re.compile('^   ([ADRM] /[^\(]+($| \(from .*:[0-9]+\)$))')
_err_re = re.compile('^svnmucc: (.*)$')

def xrun_svnmucc(expected_errors, *varargs):
  """Run svnmucc with the list of SVNMUCC_ARGS arguments.  Verify that
  its run results match the list of EXPECTED_ERRORS."""

  # First, run svnmucc.
  exit_code, outlines, errlines = \
    svntest.main.run_command(svnmucc_binary, 1, 0,
                             '-U', repos_url,
                             '-u', 'svnmuccuser',
                             '-p', 'svnmuccpass',
                             '--config-dir', 'dummy',
                             *varargs)
  errors = []
  for line in errlines:
    match = _err_re.match(line)
    if match:
      errors.append(line.rstrip('\n\r'))
  if errors != expected_errors:
    raise svntest.main.SVNUnmatchedError(str(errors))


def run_svnmucc(expected_path_changes, *varargs):
  """Run svnmucc with the list of SVNMUCC_ARGS arguments.  Verify that
  its run results in a new commit with 'svn log -rHEAD' changed paths
  that match the list of EXPECTED_PATH_CHANGES."""

  # First, run svnmucc.
  exit_code, outlines, errlines = \
    svntest.main.run_command(svnmucc_binary, 1, 0,
                             '-U', repos_url,
                             '-u', 'svnmuccuser',
                             '-p', 'svnmuccpass',
                             '--config-dir', 'dummy',
                             *varargs)
  if errlines:
    raise svntest.main.SVNCommitFailure(str(errlines))
  if len(outlines) != 1 or not _svnmucc_re.match(outlines[0]):
    raise svntest.main.SVNLineUnequal(str(outlines))

  # Now, run 'svn log -vq -rHEAD'
  changed_paths = []
  exit_code, outlines, errlines = \
    svntest.main.run_svn(None, 'log', '-vqrHEAD', repos_url)
  if errlines:
    raise svntest.Failure("Unable to verify commit with 'svn log': %s"
                          % (str(errlines)))
  for line in outlines:
    match = _log_re.match(line)
    if match:
      changed_paths.append(match.group(1).rstrip('\n\r'))

  expected_path_changes.sort()
  changed_paths.sort()
  if changed_paths != expected_path_changes:
    raise svntest.Failure("Logged path changes differ from expectations\n"
                          "   expected: %s\n"
                          "     actual: %s" % (str(expected_path_changes),
                                               str(changed_paths)))


def main():
  """Test svnmucc."""

  # revision 1
  run_svnmucc(['A /foo'
               ], # ---------
              'mkdir', 'foo')

  # revision 2
  run_svnmucc(['A /z.c',
               ], # ---------
              'put', '/dev/null', 'z.c')

  # revision 3
  run_svnmucc(['A /foo/z.c (from /z.c:2)',
               'A /foo/bar (from /foo:2)',
               ], # ---------
              'cp', '2', 'z.c', 'foo/z.c',
              'cp', '2', 'foo', 'foo/bar')

  # revision 4
  run_svnmucc(['A /zig (from /foo:3)',
               'D /zig/bar',
               'D /foo',
               'A /zig/zag (from /foo:3)',
               ], # ---------
              'cp', '3', 'foo', 'zig',
              'rm',             'zig/bar',
              'mv',      'foo', 'zig/zag')

  # revision 5
  run_svnmucc(['D /z.c',
               'A /zig/zag/bar/y.c (from /z.c:4)',
               'A /zig/zag/bar/x.c (from /z.c:2)',
               ], # ---------
              'mv',      'z.c', 'zig/zag/bar/y.c',
              'cp', '2', 'z.c', 'zig/zag/bar/x.c')

  # revision 6
  run_svnmucc(['D /zig/zag/bar/y.c',
               'A /zig/zag/bar/y y.c (from /zig/zag/bar/y.c:5)',
               'A /zig/zag/bar/y%20y.c (from /zig/zag/bar/y.c:5)',
               ], # ---------
              'mv',         'zig/zag/bar/y.c', 'zig/zag/bar/y%20y.c',
              'cp', 'HEAD', 'zig/zag/bar/y.c', 'zig/zag/bar/y%2520y.c')

  # revision 7
  run_svnmucc(['D /zig/zag/bar/y y.c',
               'A /zig/zag/bar/z z1.c (from /zig/zag/bar/y y.c:6)',
               'A /zig/zag/bar/z%20z.c (from /zig/zag/bar/y%20y.c:6)',
               'A /zig/zag/bar/z z2.c (from /zig/zag/bar/y y.c:6)',
               ], #---------
              'mv',         'zig/zag/bar/y%20y.c',   'zig/zag/bar/z z1.c',
              'cp', 'HEAD', 'zig/zag/bar/y%2520y.c', 'zig/zag/bar/z%2520z.c',
              'cp', 'HEAD', 'zig/zag/bar/y y.c',     'zig/zag/bar/z z2.c')

  # revision 8
  run_svnmucc(['D /zig/zag',
               'A /zig/foo (from /zig/zag:7)',
               'D /zig/foo/bar/z%20z.c',
               'D /zig/foo/bar/z z2.c',
               'R /zig/foo/bar/z z1.c (from /zig/zag/bar/x.c:5)',
               ], #---------
              'mv',      'zig/zag',         'zig/foo',
              'rm',                         'zig/foo/bar/z z1.c',
              'rm',                         'zig/foo/bar/z%20z2.c',
              'rm',                         'zig/foo/bar/z%2520z.c',
              'cp', '5', 'zig/zag/bar/x.c', 'zig/foo/bar/z%20z1.c')

  # revision 9
  run_svnmucc(['R /zig/foo/bar (from /zig/z.c:8)',
               ], #---------
              'rm',                 'zig/foo/bar',
              'cp', '8', 'zig/z.c', 'zig/foo/bar')

  # revision 10
  run_svnmucc(['R /zig/foo/bar (from /zig/foo/bar:8)',
               'D /zig/foo/bar/z z1.c',
               ], #---------
              'rm',                     'zig/foo/bar',
              'cp', '8', 'zig/foo/bar', 'zig/foo/bar',
              'rm',                     'zig/foo/bar/z%20z1.c')

  # revision 11
  run_svnmucc(['R /zig/foo (from /zig/foo/bar:10)',
               ], #---------
              'rm',                        'zig/foo',
              'cp', 'head', 'zig/foo/bar', 'zig/foo')

  # revision 12
  run_svnmucc(['D /zig',
               'A /foo (from /foo:3)',
               'A /foo/foo (from /foo:3)',
               'A /foo/foo/foo (from /foo:3)',
               'D /foo/foo/bar',
               'R /foo/foo/foo/bar (from /foo:3)',
               ], #---------
              'rm',             'zig',
              'cp', '3', 'foo', 'foo',
              'cp', '3', 'foo', 'foo/foo',
              'cp', '3', 'foo', 'foo/foo/foo',
              'rm',             'foo/foo/bar',
              'rm',             'foo/foo/foo/bar',
              'cp', '3', 'foo', 'foo/foo/foo/bar')

  # revision 13
  run_svnmucc(['A /boozle (from /foo:3)',
               'A /boozle/buz',
               'A /boozle/buz/nuz',
               ], #---------
              'cp',    '3', 'foo', 'boozle',
              'mkdir',             'boozle/buz',
              'mkdir',             'boozle/buz/nuz')

  # revision 14
  run_svnmucc(['A /boozle/buz/svnmucc-test.py',
               'A /boozle/guz (from /boozle/buz:13)',
               'A /boozle/guz/svnmucc-test.py',
               ], #---------
              'put',      '/dev/null',  'boozle/buz/svnmucc-test.py',
              'cp', '13', 'boozle/buz', 'boozle/guz',
              'put',      '/dev/null',  'boozle/guz/svnmucc-test.py')

  # revision 15
  run_svnmucc(['M /boozle/buz/svnmucc-test.py',
               'R /boozle/guz/svnmucc-test.py',
               ], #---------
              'put', sys.argv[0], 'boozle/buz/svnmucc-test.py',
              'rm',               'boozle/guz/svnmucc-test.py',
              'put', sys.argv[0], 'boozle/guz/svnmucc-test.py')

  # revision 16
  run_svnmucc(['R /foo/bar (from /foo/foo:15)'], #---------
              'rm',                            'foo/bar',
              'cp', '15', 'foo/foo',           'foo/bar',
              'propset',  'testprop',  'true', 'foo/bar')

  # revision 17
  run_svnmucc(['M /foo/bar'], #---------
              'propdel', 'testprop', 'foo/bar')

  # revision 18
  run_svnmucc(['M /foo/z.c',
               'M /foo/foo',
               ], #---------
              'propset', 'testprop', 'true', 'foo/z.c',
              'propset', 'testprop', 'true', 'foo/foo')

  # revision 19
  run_svnmucc(['M /foo/z.c',
               'M /foo/foo',
               ], #---------
              'propsetf', 'testprop', sys.argv[0], 'foo/z.c',
              'propsetf', 'testprop', sys.argv[0], 'foo/foo')

  # Expected missing revision error
  xrun_svnmucc(["svnmucc: E200004: 'a' is not a revision"
                ], #---------
              'cp', 'a', 'b')

  # Expected cannot be younger error
  xrun_svnmucc(['svnmucc: E205000: Copy source revision cannot be younger ' +
                'than base revision',
                ], #---------
              'cp', '42', 'a', 'b')

  # Expected already exists error
  xrun_svnmucc(["svnmucc: E125002: 'foo' already exists",
                ], #---------
              'cp', '17', 'a', 'foo')

  # Expected copy_src already exists error
  xrun_svnmucc(["svnmucc: E125002: 'a/bar' (from 'foo/bar:17') already exists",
                ], #---------
              'cp', '17', 'foo', 'a',
              'cp', '17', 'foo/foo', 'a/bar')

  # Expected not found error
  xrun_svnmucc(["svnmucc: E125002: 'a' not found",
                ], #---------
              'cp', '17', 'a', 'b')

if __name__ == "__main__":
  try:
    # remove any previously existing repository, then create a new one
    if os.path.exists(repos_path):
      shutil.rmtree(repos_path)
    exit_code, outlines, errlines = \
      svntest.main.run_svnadmin('create', '--fs-type',
                                'fsfs', repos_path)
    if errlines:
      raise svntest.main.SVNRepositoryCreateFailure(repos_path)
    fp = open(os.path.join(repos_path, 'conf', 'svnserve.conf'), 'w')
    fp.write('[general]\nauth-access = write\npassword-db = passwd\n')
    fp.close()
    fp = open(os.path.join(repos_path, 'conf', 'passwd'), 'w')
    fp.write('[users]\nsvnmuccuser = svnmuccpass\n')
    fp.close()
    main()
  except SystemExit, e:
    raise
  except svntest.main.SVNCommitFailure, e:
    die("Error committing via svnmucc: %s" % (str(e)))
  except svntest.main.SVNLineUnequal, e:
    die("Unexpected svnmucc output line: %s" % (str(e)))
  except svntest.main.SVNRepositoryCreateFailure, e:
    die("Error creating test repository: %s" % (str(e)))
  except svntest.Failure, e:
    die("Test failed: %s" % (str(e)))
  except Exception, e:
    die("Something bad happened: %s" % (str(e)))

  # cleanup the repository on a successful run
  try:
    if os.path.exists(repos_path):
      shutil.rmtree(repos_path)
  except:
    pass
  print("SUCCESS!")