waf_unit_test: return also test task in report tuples

This commit is contained in:
Federico Pellegrin 2020-04-21 05:58:05 +02:00
parent 186f627203
commit ba9ddfbfcb
7 changed files with 16 additions and 9 deletions

View File

@ -2,6 +2,7 @@ CHANGES IN WAF 2.1.0
--------------------
* While the Waf file runs on Python 2 and 3, creating it requires version 3
+ Added wafcache
+ waf_unit_test: Added task in returned tuples, custom reports should be adapted
- Remove waflib.Runner.PriorityTasks.appendleft
- Remove waflib.Task.TaskBase
- Remove the upper class of waflib.Task.Task (metaclass syntax)

View File

@ -7,6 +7,7 @@ bld(
source = 'HelloWorldTest.cpp',
target = 'unit_test_program',
use = 'unittestmain useless CPPUNIT',
ut_str = '${SRC[0].abspath()} -flag1 ${NARG}'
ut_str = '${SRC[0].abspath()} -flag1 ${NARG}',
name = 'test0',
)

View File

@ -7,5 +7,6 @@ bld(
target = 'unit_test_program',
use = 'unittestmain useless CPPUNIT',
ut_cwd = bld.path,
name = 'test1',
)

View File

@ -5,7 +5,8 @@ if bld.env['PYTHON']:
bld(
features = 'test_scripts',
test_scripts_source = 'test.py',
test_scripts_template = '${PYTHON} ${SCRIPT}'
test_scripts_template = '${PYTHON} ${SCRIPT}',
name = 'test2',
)

View File

@ -23,7 +23,8 @@ if bld.env['PYTHON']:
features = 'test_scripts',
test_scripts_source = 'test.1.py test.2.py',
test_scripts_template = '${PYTHON} ${SCRIPT}',
test_scripts_paths = paths
test_scripts_paths = paths,
name = 'test3',
)

View File

@ -40,9 +40,11 @@ def summary(bld):
Logs.pprint('CYAN', 'test report %3.0f%% success' % val)
Logs.pprint('CYAN', ' tests that fail %d/%d' % (tfail, total))
for (f, code, out, err) in lst:
for (f, code, out, err, ut_task) in lst:
if code:
Logs.pprint('CYAN', ' %s' % f)
# In ut_task we have the task running the test and we can get any extra information
# from there (in this example just the generator name)
Logs.pprint('CYAN', ' %s (%s)' % (f, ut_task.generator.name))
Logs.pprint('RED', 'status: %r' % code)
if out: Logs.pprint('RED', 'out: %r' % out)
if err: Logs.pprint('RED', 'err: %r' % err)

View File

@ -222,7 +222,7 @@ class utest(Task.Task):
proc = Utils.subprocess.Popen(cmd, cwd=self.get_cwd().abspath(), env=self.get_test_env(),
stderr=Utils.subprocess.PIPE, stdout=Utils.subprocess.PIPE, shell=isinstance(cmd,str))
(stdout, stderr) = proc.communicate()
self.waf_unit_test_results = tup = (self.inputs[0].abspath(), proc.returncode, stdout, stderr)
self.waf_unit_test_results = tup = (self.inputs[0].abspath(), proc.returncode, stdout, stderr, self)
testlock.acquire()
try:
return self.generator.add_test_results(tup)
@ -249,12 +249,12 @@ def summary(bld):
tfail = len([x for x in lst if x[1]])
Logs.pprint('GREEN', ' tests that pass %d/%d' % (total-tfail, total))
for (f, code, out, err) in lst:
for (f, code, out, err, ut_task) in lst:
if not code:
Logs.pprint('GREEN', ' %s' % f)
Logs.pprint('GREEN' if tfail == 0 else 'RED', ' tests that fail %d/%d' % (tfail, total))
for (f, code, out, err) in lst:
for (f, code, out, err, ut_task) in lst:
if code:
Logs.pprint('RED', ' %s' % f)
@ -271,7 +271,7 @@ def set_exit_code(bld):
bld.add_post_fun(waf_unit_test.set_exit_code)
"""
lst = getattr(bld, 'utest_results', [])
for (f, code, out, err) in lst:
for (f, code, out, err, ut_task) in lst:
if code:
msg = []
if out: