-
Notifications
You must be signed in to change notification settings - Fork 1
/
testrunner.py
97 lines (87 loc) · 4.82 KB
/
testrunner.py
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
#!/usr/bin/env python
#
# This file is part of QMakeTestRunner - Python Test Runner for Qt and QMake.
#
# (C) Agile Workers Software, 2012.
# Author: Mirko Boehm <[email protected]>
#
# QMakeTestRunner file is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This file is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# QMakeTestRunner. If not, see http://www.gnu.org/licenses/.
import argparse
import os
import sys
import subprocess
import platform
import re
# First, parse the command line arguments, and generate help (-h) in the process:
parser = argparse.ArgumentParser( prog = 'QMakeTestRunner',
description = '''\
Python Test Runner for Qt and QMake, (C) Agile Workers Software, 2012.
Licensed under the GPL v3.
''' )
parser.add_argument( '-l', '--lib-path', dest = 'libPaths', required = False, action = 'append', default = [],
help = 'Library path to be added to the executable run time environment' )
# parser.add_argument( '-t', '--test-excutable', dest = 'testExecutable', required = False, action = 'store',
# help = 'A test executable to be executed' )
parser.add_argument( '-v', '--verbose', dest = 'verbose', required = False, action = 'store_true',
help = 'Toggle extra debug output' )
parser.add_argument( '-f', '--framework-path', dest = 'frameworkPaths', required = False, action = 'append', default = [],
help = 'Mac framework paths to be added to the executable run time environment' )
parser.add_argument( '--custom-env', dest = 'customEnvs', required = False, action = 'append', default = [],
help = 'Custom variables to be added to the executable run time environment' )
parser.add_argument( 'testExecutable', metavar = 'test', nargs = '?', type = str,
help = 'Test executable to be started' )
arguments, test_arguments = parser.parse_known_args()
# A function to print information if verbose is set:
def v_print( txt ):
if arguments.verbose:
print( txt )
# Some diagnostics:
v_print( "Library directories: {0}".format( ', '.join( arguments.libPaths ) or 'none' ) )
v_print( "Framework paths: {0}".format( ', '.join( arguments.frameworkPaths ) or 'none' ) )
v_print( "Test executable: {0}".format( arguments.testExecutable or 'not specified' ) )
v_print( "Custom variables: {0}".format( arguments.customEnvs or 'not specified' ) )
v_print( "Verbose: {0}".format( 'yes' if arguments.verbose else 'no' ) )
v_print( "Test arguments: {0}".format( ' '.join( test_arguments ) or 'none' ) )
# Determine which environment variable to change:
libPathVariable = ''
if 'Windows' in platform.platform():
libPathVariable = 'PATH'
elif 'Darwin' in platform.platform():
libPathVariable = 'DYLD_LIBRARY_PATH'
elif 'Linux' in platform.platform():
libPathVariable = 'LD_LIBRARY_PATH'
else:
print( 'Unsupported platform "{0}", it should be easy enough to add :-)!'.format( platform.platform() ) )
sys.exit( 1 )
# Assemble library path and set it in the environment:
original_ld_library_path = '' if not os.environ.has_key( libPathVariable ) else os.environ[libPathVariable]
ld_library_path_elements = filter( len, [] + arguments.libPaths + original_ld_library_path.split( os.pathsep ) )
new_ld_library_path = os.pathsep.join( ld_library_path_elements )
v_print( 'Library search path: {0}'.format( new_ld_library_path ) )
if new_ld_library_path: os.environ[libPathVariable] = new_ld_library_path
# Assemble framework path and set it in the environment:
frameworkPathVariable = 'DYLD_FRAMEWORK_PATH'
original_framework_path = '' if not os.environ.has_key( frameworkPathVariable ) else os.environ[frameworkPathVariable]
framework_path_elements = filter( len, [] + arguments.frameworkPaths + original_framework_path.split( os.pathsep ) )
new_framework_path = os.pathsep.join( framework_path_elements )
v_print( 'Framework search path: {0}'.format( new_framework_path ) )
if new_framework_path: os.environ[frameworkPathVariable] = new_framework_path
# Process custom environment variables
for env in arguments.customEnvs:
m = re.match("([a-zA-Z0-9_]+)=(.*)", env)
if m is not None:
variable = m.group(1)
value = m.group(2)
v_print( 'Custom variable: {0} {1}'.format(variable, value) )
os.environ[variable] = value
# Run the test program and return with it's exit code:
sys.exit( subprocess.call( [ arguments.testExecutable ] + test_arguments ) )