1#!/usr/local/bin/python3.8 2 3# (Be in -*- python -*- mode.) 4# 5# ==================================================================== 6# Copyright (c) 2007 CollabNet. All rights reserved. 7# 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. 13# 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 https://github.com/viewvc/viewvc/. 17# ==================================================================== 18 19"""Run tests of rcsparse code.""" 20 21import sys 22import os 23import glob 24from io import StringIO 25from difflib import Differ 26 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: 30script_dir = os.path.dirname(sys.argv[0]) 31sys.path.insert(0, script_dir) 32# Since there is nontrivial logic in __init__.py, we have to import 33# parse() via that file. However, __init__.py uses relative import 34# for the package now, so we must import it as a package: 35# containing this script is in the path: 36p_dir, p_name = os.path.split(os.path.dirname(os.path.abspath(sys.argv[0]))) 37sys.path.insert(0, p_dir) 38script_dir = os.path.dirname(sys.argv[0]) 39 40#from __init__ import parse 41rcsparse = __import__(p_name) 42parse = rcsparse.parse 43 44sys.path.insert(0, script_dir) 45from parse_rcs_file import LoggingSink 46 47test_dir = os.path.join(script_dir, 'test-data') 48 49filelist = glob.glob(os.path.join(test_dir, '*,v')) 50filelist.sort() 51 52all_tests_ok = 1 53 54for filename in filelist: 55 sys.stderr.write('%s: ' % (filename,)) 56 f = StringIO() 57 try: 58 parse(open(filename, 'rb'), LoggingSink(f)) 59 except Exception as e: 60 sys.stderr.write('Error parsing file: %s!\n' % (e,)) 61 raise 62 all_tests_ok = 0 63 else: 64 output = f.getvalue() 65 66 expected_output_filename = filename[:-2] + '.out' 67 expected_output = open(expected_output_filename, 'r').read() 68 69 if output == expected_output: 70 sys.stderr.write('OK\n') 71 else: 72 sys.stderr.write('Output does not match expected output!\n') 73 differ = Differ() 74 for diffline in differ.compare( 75 expected_output.splitlines(1), output.splitlines(1) 76 ): 77 sys.stderr.write(diffline) 78 all_tests_ok = 0 79 80if all_tests_ok: 81 sys.exit(0) 82else: 83 sys.exit(1) 84 85