Make the unit test result format API compatible with waf 2.0

This commit is contained in:
Thomas Nagy 2020-04-28 01:17:07 +02:00
parent b599c8bb9d
commit a910d07d55
6 changed files with 53 additions and 33 deletions

View File

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

View File

@ -40,14 +40,16 @@ 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, ut_task) in lst:
if code:
for result in lst:
if result.exit_code:
# 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)
Logs.pprint('CYAN', ' %s (%s)' % (result.test_path, result.generator.name))
Logs.pprint('RED', 'status: %r' % result.exit_code)
if result.out:
Logs.pprint('RED', 'out: %r' % result.out)
if result.err:
Logs.pprint('RED', 'err: %r' % result.err)
def build(bld):
bld.recurse('src tests')

View File

@ -29,22 +29,22 @@ def gtest_results(bld):
lst = getattr(bld, 'utest_results', [])
if not lst:
return
for (f, code, out, err, ut_task) in lst:
# if not code:
for result in lst:
# if not result.exit_code:
# continue
# uncomment if you want to see what's happening
# print(str(out, 'utf-8'))
output = str(out, 'utf-8').splitlines()
output = str(result.out, 'utf-8').splitlines()
for i, line in enumerate(output):
if '[ RUN ]' in line and code:
if '[ RUN ]' in line and result.exit_code:
i += 1
if ' OK ]' in output[i]:
continue
while not '[ ' in output[i]:
Logs.warn(output[i])
i += 1
elif ' FAILED ]' in line and code:
elif ' FAILED ]' in line and result.exit_code:
Logs.error(line)
elif ' PASSED ]' in line:
Logs.info(line)

View File

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

View File

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

View File

@ -152,6 +152,24 @@ def add_test_results(self, tup):
except AttributeError:
self.bld.utest_results = [tup]
class test_result(object):
def __init__(self, test_path, exit_code, out, err, task):
self.task = task
self.generator = task.generator
self.out = out
self.err = err
self.exit_code = exit_code
self.test_path = test_path
def __iter__(self):
yield self.test_path
yield self.exit_code
yield self.out
yield self.err
def __getitem__(self, idx):
return list(self)[idx]
@Task.deep_inputs
class utest(Task.Task):
"""
@ -222,7 +240,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)
self.waf_unit_test_results = tup = test_result(self.inputs[0].abspath(), proc.returncode, stdout, stderr, self)
testlock.acquire()
try:
return self.generator.add_test_results(tup)
@ -249,14 +267,14 @@ 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, ut_task) in lst:
if not code:
Logs.pprint('GREEN', ' %s' % f)
for result in lst:
if not result.exit_code:
Logs.pprint('GREEN', ' %s' % result.test_path)
Logs.pprint('GREEN' if tfail == 0 else 'RED', ' tests that fail %d/%d' % (tfail, total))
for (f, code, out, err, ut_task) in lst:
if code:
Logs.pprint('RED', ' %s' % f)
for result in lst:
if result.exit_code:
Logs.pprint('RED', ' %s' % result.test_path)
def set_exit_code(bld):
"""
@ -271,13 +289,13 @@ 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, ut_task) in lst:
if code:
for result in lst:
if result.exit_code:
msg = []
if out:
msg.append('stdout:%s%s' % (os.linesep, out.decode('utf-8')))
if err:
msg.append('stderr:%s%s' % (os.linesep, err.decode('utf-8')))
if result.out:
msg.append('stdout:%s%s' % (os.linesep, result.out.decode('utf-8')))
if result.err:
msg.append('stderr:%s%s' % (os.linesep, result.err.decode('utf-8')))
bld.fatal(os.linesep.join(msg))