2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-12 05:10:40 +01:00
waf/playground/gtest/wscript
2014-03-04 21:26:07 +01:00

69 lines
1.9 KiB
Python

#! /usr/bin/env python
# encoding: utf-8
# Sylvain Rouquette, 2014
# based on Richard Quirk's demo (unit_test), 2008
"""
Execute tests during the build - requires cppunit
To force all tests, run with "waf build --alltests"
"""
from waflib import Logs
top = '.'
out = 'build'
def options(opt):
opt.load('compiler_cxx')
opt.load('waf_unit_test')
opt.add_option('--onlytests', action='store_true', default=True, help='Exec unit tests only', dest='only_tests')
def configure(conf):
conf.load('compiler_cxx')
conf.load('waf_unit_test')
conf.check(lib='gtest', uselib_store='GTEST')
def gtest_results(bld):
lst = getattr(bld, 'utest_results', [])
if not lst:
return
for (f, code, out, err) in lst:
# if not code:
# continue
# uncomment if you want to see what's happening
# print(str(out, 'utf-8'))
output = str(out, 'utf-8').split('\n')
for i, line in enumerate(output):
if '[ RUN ]' in line and code:
i += 1
if ' OK ]' in output[i]:
continue
while not '[ ' in output[i]:
Logs.warn('%s' % output[i])
i += 1
elif ' FAILED ]' in line and code:
Logs.error('%s' % line)
elif ' PASSED ]' in line:
Logs.info('%s' % line)
def build(bld):
bld.recurse('src tests')
# unittestw.summary is a pretty ugly function for displaying a report (feel free to improve!)
# results -> bld.utest_results [(filename, returncode, stdout, stderr), (..., ), ...]
#bld.add_post_fun(waf_unit_test.summary)
bld.add_post_fun(gtest_results)
# to execute all tests:
# $ waf --alltests
# to set this behaviour permanenly:
bld.options.all_tests = True
# debugging zone:
# $ waf --zones=ut
# setting the cwd for a unit test execution: see tests/test1/wscript_build (ut_cwd)