Move definitions of generate_ignores() higher in the file.
[cvs2svn.git] / cvs2svn_rcsparse / run-tests.py
blobcaa0fdce522ce44337edb8fc51ace2f284edb9f8
1 #! /usr/bin/python
3 # (Be in -*- python -*- mode.)
5 # ====================================================================
6 # Copyright (c) 2007 CollabNet. All rights reserved.
8 # This software is licensed as described in the file COPYING, which
9 # you should have received as part of this distribution. The terms
10 # are also available at http://subversion.tigris.org/license-1.html.
11 # If newer versions of this license are posted there, you may use a
12 # newer version instead, at your option.
14 # This software consists of voluntary contributions made by many
15 # individuals. For exact contribution history, see the revision
16 # history and logs, available at http://viewvc.tigris.org/.
17 # ====================================================================
19 """Run tests of rcsparse code."""
21 import sys
22 import os
23 import glob
24 from cStringIO import StringIO
25 from difflib import Differ
27 # Since there is nontrivial logic in __init__.py, we have to import
28 # parse() via that file. First make sure that the directory
29 # containing this script is in the path:
30 script_dir = os.path.dirname(sys.argv[0])
31 sys.path.insert(0, script_dir)
33 from __init__ import parse
34 from parse_rcs_file import LoggingSink
37 test_dir = os.path.join(script_dir, 'test-data')
39 filelist = glob.glob(os.path.join(test_dir, '*,v'))
40 filelist.sort()
42 all_tests_ok = 1
44 for filename in filelist:
45 sys.stderr.write('%s: ' % (filename,))
46 f = StringIO()
47 try:
48 parse(open(filename, 'rb'), LoggingSink(f))
49 except Exception, e:
50 sys.stderr.write('Error parsing file: %s!\n' % (e,))
51 all_tests_ok = 0
52 else:
53 output = f.getvalue()
55 expected_output_filename = filename[:-2] + '.out'
56 expected_output = open(expected_output_filename, 'rb').read()
58 if output == expected_output:
59 sys.stderr.write('OK\n')
60 else:
61 sys.stderr.write('Output does not match expected output!\n')
62 differ = Differ()
63 for diffline in differ.compare(
64 expected_output.splitlines(1), output.splitlines(1)
66 sys.stderr.write(diffline)
67 all_tests_ok = 0
69 if all_tests_ok:
70 sys.exit(0)
71 else:
72 sys.exit(1)