Create a logfile with full test output.

pull/15/head
Jussi Pakkanen 12 years ago
parent 91331283be
commit 2cdfb14777
  1. 28
      meson_test.py

@ -19,14 +19,26 @@ from optparse import OptionParser
parser = OptionParser() parser = OptionParser()
parser.add_option('--wrapper', default=None, dest='wrapper', parser.add_option('--wrapper', default=None, dest='wrapper',
help='wrapper to run tests (e.g. valgrind') help='wrapper to run tests with (e.g. valgrind')
def write_log(logfile, test_name, result_str, stdo, stde):
logfile.write(result_str + '\n\n')
logfile.write('--- stdout ---\n')
logfile.write(stdo)
logfile.write('\n--- stderr ---\n')
logfile.write(stde)
logfile.write('\n')
def run_tests(options, datafilename): def run_tests(options, datafilename):
logfile_base = 'meson-private/testlog'
if options.wrapper is None: if options.wrapper is None:
wrap = [] wrap = []
logfilename = logfile_base + '.txt'
else: else:
wrap = [options.wrapper] wrap = [options.wrapper]
logfilename = logfile_base + '-' + options.wrapper.replace(' ', '_') + '.txt'
logfile = open(logfilename, 'w')
logfile.write('Log file for tests.\n\n')
for line in open(datafilename, 'r'): for line in open(datafilename, 'r'):
line = line.strip() line = line.strip()
if line == '': if line == '':
@ -34,12 +46,16 @@ def run_tests(options, datafilename):
cmd = wrap + [line] cmd = wrap + [line]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdo, stde) = p.communicate() (stdo, stde) = p.communicate()
stdo = stdo.decode()
stde = stde.decode()
if p.returncode != 0: if p.returncode != 0:
print('Error running test.') result_str = 'Test "%s": FAIL' % line
print('Stdout:\n' + stdo.decode()) else:
print('Stderr:\n' + stde.decode()) result_str = 'Test "%s": OK' % line
sys.exit(1) print(result_str)
print('Test "%s": OK' % line) write_log(logfile, line, result_str, stdo, stde)
print('\nFull log written to %s.' % logfilename)
if __name__ == '__main__': if __name__ == '__main__':
(options, args) = parser.parse_args(sys.argv) (options, args) = parser.parse_args(sys.argv)

Loading…
Cancel
Save