Imported Upstream version 1.0.10
[platform/upstream/fribidi.git] / test / test-runner.py
1 #!/usr/bin/env python3
2
3 # Test runner that calls ../bin/fribidi --test --charset CHARSET *.input,
4 # captures the output and compares it to the data in the reference file given
5 import subprocess
6 import sys
7 import os
8
9 if len(sys.argv) != 5:
10   raise Exception('Expected 4 command-line arguments: test_exe charset test.input test.reference')
11
12 script = sys.argv[0]
13 test_exe = sys.argv[1]
14 charset = sys.argv[2]
15 input_file = sys.argv[3]
16 reference_file = sys.argv[4]
17
18 if os.name == 'nt':
19   libpath = os.path.join(os.path.dirname(os.path.realpath(test_exe)),
20                          '..',
21                          'lib')
22   os.environ['PATH'] = libpath + ';' + os.environ['PATH']
23
24 try:
25   output = subprocess.check_output([test_exe, '--test', '--charset', charset, input_file])
26   ref_data = open(reference_file, "rb").read()
27   if os.name == 'nt':
28     output = output.replace(b'\r\n', b'\n')
29     ref_data = ref_data.replace(b'\r\n', b'\n') 
30   if output != ref_data:
31     print('Output:\n', output)
32     print('Reference file:\n', ref_data)
33     raise Exception('fribidi --test output for charset ' + charset + ' and input file ' + input_file + ' does not match data from reference file ' + reference_file)
34 except:
35   raise Exception('fribidi --test failed for charset ' + charset + ' and input file ' + input_file)