8
VALGRIND_CMD = 'valgrind --tool=memcheck --leak-check=yes --undef-value-errors=yes'
10
class TestProxy(object):
11
def __init__( self, test_exe_path, use_valgrind=False ):
12
self.test_exe_path = os.path.normpath( os.path.abspath( test_exe_path ) )
13
self.use_valgrind = use_valgrind
15
def run( self, options ):
17
cmd = VALGRIND_CMD.split()
20
cmd.extend( [self.test_exe_path, '--test-auto'] + options )
21
process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
22
stdout = process.communicate()[0]
23
if process.returncode:
27
def runAllTests( exe_path, use_valgrind=False ):
28
test_proxy = TestProxy( exe_path, use_valgrind=use_valgrind )
29
status, test_names = test_proxy.run( ['--list-tests'] )
31
print >> sys.stderr, "Failed to obtain unit tests list:\n" + test_names
33
test_names = [name.strip() for name in test_names.strip().split('\n')]
35
for name in test_names:
36
print 'TESTING %s:' % name,
37
succeed, result = test_proxy.run( ['--test', name] )
41
failures.append( (name, result) )
43
failed_count = len(failures)
44
pass_count = len(test_names) - failed_count
47
for name, result in failures:
49
print '%d/%d tests passed (%d failure(s))' % (
50
pass_count, len(test_names), failed_count)
53
print 'All %d tests passed' % len(test_names)
57
from optparse import OptionParser
58
parser = OptionParser( usage="%prog [options] <path to test_lib_json.exe>" )
59
parser.add_option("--valgrind",
60
action="store_true", dest="valgrind", default=False,
61
help="run all the tests using valgrind to detect memory leaks")
62
parser.enable_interspersed_args()
63
options, args = parser.parse_args()
66
parser.error( 'Must provides at least path to test_lib_json executable.' )
69
exit_code = runAllTests( args[0], use_valgrind=options.valgrind )
72
if __name__ == '__main__':