mirror of https://gitlab.com/ita1024/waf.git
Make the unit test result format API compatible with waf 2.0
This commit is contained in:
parent
b599c8bb9d
commit
a910d07d55
|
@ -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, ut_task) in lst:
|
for result in lst:
|
||||||
print(out.decode('utf-8'))
|
print(result.out.decode('utf-8'))
|
||||||
print(err.decode('utf-8'))
|
print(result.err.decode('utf-8'))
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,16 @@ 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, ut_task) in lst:
|
for result in lst:
|
||||||
if code:
|
if result.exit_code:
|
||||||
# In ut_task we have the task running the test and we can get any extra information
|
# 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)
|
# from there (in this example just the generator name)
|
||||||
Logs.pprint('CYAN', ' %s (%s)' % (f, ut_task.generator.name))
|
Logs.pprint('CYAN', ' %s (%s)' % (result.test_path, result.generator.name))
|
||||||
Logs.pprint('RED', 'status: %r' % code)
|
Logs.pprint('RED', 'status: %r' % result.exit_code)
|
||||||
if out: Logs.pprint('RED', 'out: %r' % out)
|
if result.out:
|
||||||
if err: Logs.pprint('RED', 'err: %r' % err)
|
Logs.pprint('RED', 'out: %r' % result.out)
|
||||||
|
if result.err:
|
||||||
|
Logs.pprint('RED', 'err: %r' % result.err)
|
||||||
|
|
||||||
def build(bld):
|
def build(bld):
|
||||||
bld.recurse('src tests')
|
bld.recurse('src tests')
|
||||||
|
|
|
@ -29,22 +29,22 @@ 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, ut_task) in lst:
|
for result in lst:
|
||||||
# if not code:
|
# if not result.exit_code:
|
||||||
# continue
|
# continue
|
||||||
|
|
||||||
# uncomment if you want to see what's happening
|
# uncomment if you want to see what's happening
|
||||||
# print(str(out, 'utf-8'))
|
# print(str(out, 'utf-8'))
|
||||||
output = str(out, 'utf-8').splitlines()
|
output = str(result.out, 'utf-8').splitlines()
|
||||||
for i, line in enumerate(output):
|
for i, line in enumerate(output):
|
||||||
if '[ RUN ]' in line and code:
|
if '[ RUN ]' in line and result.exit_code:
|
||||||
i += 1
|
i += 1
|
||||||
if ' OK ]' in output[i]:
|
if ' OK ]' in output[i]:
|
||||||
continue
|
continue
|
||||||
while not '[ ' in output[i]:
|
while not '[ ' in output[i]:
|
||||||
Logs.warn(output[i])
|
Logs.warn(output[i])
|
||||||
i += 1
|
i += 1
|
||||||
elif ' FAILED ]' in line and code:
|
elif ' FAILED ]' in line and result.exit_code:
|
||||||
Logs.error(line)
|
Logs.error(line)
|
||||||
elif ' PASSED ]' in line:
|
elif ' PASSED ]' in line:
|
||||||
Logs.info(line)
|
Logs.info(line)
|
||||||
|
|
|
@ -14,9 +14,9 @@ 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, ut_task) in lst:
|
for result in lst:
|
||||||
print(out.decode('utf-8'))
|
print(result.out.decode('utf-8'))
|
||||||
print(err.decode('utf-8'))
|
print(result.err.decode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def options(opt):
|
def options(opt):
|
||||||
|
|
|
@ -18,9 +18,9 @@ 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, ut_task) in lst:
|
for result in lst:
|
||||||
print(out.decode('utf-8'))
|
print(result.out.decode('utf-8'))
|
||||||
print(err.decode('utf-8'))
|
print(result.err.decode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def options(opt):
|
def options(opt):
|
||||||
|
|
|
@ -152,6 +152,24 @@ def add_test_results(self, tup):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.bld.utest_results = [tup]
|
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
|
@Task.deep_inputs
|
||||||
class utest(Task.Task):
|
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(),
|
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)
|
self.waf_unit_test_results = tup = test_result(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,14 +267,14 @@ 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, ut_task) in lst:
|
for result in lst:
|
||||||
if not code:
|
if not result.exit_code:
|
||||||
Logs.pprint('GREEN', ' %s' % f)
|
Logs.pprint('GREEN', ' %s' % result.test_path)
|
||||||
|
|
||||||
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, ut_task) in lst:
|
for result in lst:
|
||||||
if code:
|
if result.exit_code:
|
||||||
Logs.pprint('RED', ' %s' % f)
|
Logs.pprint('RED', ' %s' % result.test_path)
|
||||||
|
|
||||||
def set_exit_code(bld):
|
def set_exit_code(bld):
|
||||||
"""
|
"""
|
||||||
|
@ -271,13 +289,13 @@ 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, ut_task) in lst:
|
for result in lst:
|
||||||
if code:
|
if result.exit_code:
|
||||||
msg = []
|
msg = []
|
||||||
if out:
|
if result.out:
|
||||||
msg.append('stdout:%s%s' % (os.linesep, out.decode('utf-8')))
|
msg.append('stdout:%s%s' % (os.linesep, result.out.decode('utf-8')))
|
||||||
if err:
|
if result.err:
|
||||||
msg.append('stderr:%s%s' % (os.linesep, err.decode('utf-8')))
|
msg.append('stderr:%s%s' % (os.linesep, result.err.decode('utf-8')))
|
||||||
bld.fatal(os.linesep.join(msg))
|
bld.fatal(os.linesep.join(msg))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue