Commit 4f25618d authored by Ludovic Courtès's avatar Ludovic Courtès

tests: Redirect command output to the .log files.

This makes 'scons tests' less noisy and also allows users to preserve
the command output in .log files.
parent 7e9555ed
import os, sys import os, sys
from subprocess import call from subprocess import call, Popen, STDOUT
from os.path import basename, splitext from os.path import basename, splitext
import filecmp import filecmp
...@@ -81,9 +81,9 @@ def run_unit_test(env, target, source): ...@@ -81,9 +81,9 @@ def run_unit_test(env, target, source):
envvars = build_environment_variables() envvars = build_environment_variables()
with open(str(target[0]),'w') as log: with open(str(target[0]),'w') as log:
log.write(str(envvars) + '\n')
if splitext(program)[1] == '.py': if splitext(program)[1] == '.py':
command = env['PYTHON'] + ' ' + program command = env['PYTHON'] + ' ' + program
log.write(str(envvars) + '\n')
if call([env['PYTHON'], program], env=envvars) == 0: if call([env['PYTHON'], program], env=envvars) == 0:
log.write("PASS: " + command + "\n") log.write("PASS: " + command + "\n")
return 0 return 0
...@@ -91,7 +91,11 @@ def run_unit_test(env, target, source): ...@@ -91,7 +91,11 @@ def run_unit_test(env, target, source):
log.write("FAIL: " + command + "\n") log.write("FAIL: " + command + "\n")
return 1 return 1
else: else:
if os.spawnle(os.P_WAIT, program, program, envvars) == 0: pipe = Popen([program], env = envvars,
stdout = log, stderr = STDOUT)
pipe.wait()
log.write('\n' + str(envvars) + '\n')
if pipe.returncode == 0:
log.write("PASS: " + program + "\n") log.write("PASS: " + program + "\n")
return 0 return 0
else: else:
...@@ -104,10 +108,13 @@ def run_command(arguments): ...@@ -104,10 +108,13 @@ def run_command(arguments):
program = str(source[0].abspath) program = str(source[0].abspath)
envvars = build_environment_variables() envvars = build_environment_variables()
status = os.spawnve(os.P_WAIT, program, [program] + arguments, envvars)
command = ' '.join([program] + arguments)
with open(str(target[0]), 'w') as log: with open(str(target[0]), 'w') as log:
log.write(str(envvars) + '\n'); pipe = Popen([program] + arguments, env = envvars, \
stdout = log, stderr = STDOUT)
pipe.wait()
status = pipe.returncode
command = ' '.join([program] + arguments)
log.write('\n' + str(envvars) + '\n');
if status == 0: if status == 0:
log.write("PASS: '" + command + "' succeeded\n") log.write("PASS: '" + command + "' succeeded\n")
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment