Merge branch 'waf_unit_tg' into 'waf-2.1'

waf_unit_test: return also task generator in report tuples

See merge request ita1024/waf!2285
This commit is contained in:
ita1024 2020-04-27 22:56:38 +00:00
commit b599c8bb9d
11 changed files with 20 additions and 13 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 * While the Waf file runs on Python 2 and 3, creating it requires version 3
+ Added wafcache + Added wafcache
+ waf_unit_test: Added task in returned tuples, custom reports should be adapted
- Remove waflib.Runner.PriorityTasks.appendleft - Remove waflib.Runner.PriorityTasks.appendleft
- Remove waflib.Task.TaskBase - Remove waflib.Task.TaskBase
- Remove the upper class of waflib.Task.Task (metaclass syntax) - Remove the upper class of waflib.Task.Task (metaclass syntax)

View File

@ -78,7 +78,7 @@ def print_test_results(bld):
lst = getattr(bld, 'utest_results', []) lst = getattr(bld, 'utest_results', [])
if not lst: if not lst:
return return
for (f, code, out, err) in lst: for (f, code, out, err, ut_task) in lst:
print(out.decode('utf-8')) print(out.decode('utf-8'))
print(err.decode('utf-8')) print(err.decode('utf-8'))

View File

@ -7,6 +7,7 @@ bld(
source = 'HelloWorldTest.cpp', source = 'HelloWorldTest.cpp',
target = 'unit_test_program', target = 'unit_test_program',
use = 'unittestmain useless CPPUNIT', 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', target = 'unit_test_program',
use = 'unittestmain useless CPPUNIT', use = 'unittestmain useless CPPUNIT',
ut_cwd = bld.path, ut_cwd = bld.path,
name = 'test1',
) )

View File

@ -5,7 +5,8 @@ if bld.env['PYTHON']:
bld( bld(
features = 'test_scripts', features = 'test_scripts',
test_scripts_source = 'test.py', 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', features = 'test_scripts',
test_scripts_source = 'test.1.py test.2.py', test_scripts_source = 'test.1.py test.2.py',
test_scripts_template = '${PYTHON} ${SCRIPT}', 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', 'test report %3.0f%% success' % val)
Logs.pprint('CYAN', ' tests that fail %d/%d' % (tfail, total)) 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: 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) Logs.pprint('RED', 'status: %r' % code)
if out: Logs.pprint('RED', 'out: %r' % out) if out: Logs.pprint('RED', 'out: %r' % out)
if err: Logs.pprint('RED', 'err: %r' % err) if err: Logs.pprint('RED', 'err: %r' % err)

View File

@ -29,7 +29,7 @@ def gtest_results(bld):
lst = getattr(bld, 'utest_results', []) lst = getattr(bld, 'utest_results', [])
if not lst: if not lst:
return return
for (f, code, out, err) in lst: for (f, code, out, err, ut_task) in lst:
# if not code: # if not code:
# continue # continue

View File

@ -14,7 +14,7 @@ def test_results(bld):
lst = getattr(bld, 'utest_results', []) lst = getattr(bld, 'utest_results', [])
if not lst: if not lst:
return return
for (f, code, out, err) in lst: for (f, code, out, err, ut_task) in lst:
print(out.decode('utf-8')) print(out.decode('utf-8'))
print(err.decode('utf-8')) print(err.decode('utf-8'))

View File

@ -18,7 +18,7 @@ def test_results(bld):
lst = getattr(bld, 'utest_results', []) lst = getattr(bld, 'utest_results', [])
if not lst: if not lst:
return return
for (f, code, out, err) in lst: for (f, code, out, err, ut_task) in lst:
print(out.decode('utf-8')) print(out.decode('utf-8'))
print(err.decode('utf-8')) print(err.decode('utf-8'))

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(), 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)) stderr=Utils.subprocess.PIPE, stdout=Utils.subprocess.PIPE, shell=isinstance(cmd,str))
(stdout, stderr) = proc.communicate() (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() testlock.acquire()
try: try:
return self.generator.add_test_results(tup) return self.generator.add_test_results(tup)
@ -249,12 +249,12 @@ def summary(bld):
tfail = len([x for x in lst if x[1]]) tfail = len([x for x in lst if x[1]])
Logs.pprint('GREEN', ' tests that pass %d/%d' % (total-tfail, total)) 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: if not code:
Logs.pprint('GREEN', ' %s' % f) Logs.pprint('GREEN', ' %s' % f)
Logs.pprint('GREEN' if tfail == 0 else 'RED', ' tests that fail %d/%d' % (tfail, total)) 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: if code:
Logs.pprint('RED', ' %s' % f) Logs.pprint('RED', ' %s' % f)
@ -271,7 +271,7 @@ def set_exit_code(bld):
bld.add_post_fun(waf_unit_test.set_exit_code) bld.add_post_fun(waf_unit_test.set_exit_code)
""" """
lst = getattr(bld, 'utest_results', []) lst = getattr(bld, 'utest_results', [])
for (f, code, out, err) in lst: for (f, code, out, err, ut_task) in lst:
if code: if code:
msg = [] msg = []
if out: if out: