Esempio n. 1
0
def hwaf_utest_set_exit_code(bld, *k):
    """
    If any of the tests fail waf will exit with that exit code.
    This is useful if you have an automated build system which need
    to report on errors from the tests.
    You may use it like this:
    
    def build(bld):
        bld(features='cxx cxxprogram test', source='main.c', target='app')
        bld.add_post_fun(hwaf_unit_set_exit_code)
    """
    lst = getattr(bld, 'hwaf_utest_results', [])
    if not lst:
        return

    msg = []
    for (f, code, out, err, exp_rc) in lst:
        if code != exp_rc:
            msg.append('=== %s === (err=%d expected=%d)' % (f,code, exp_rc))
            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')))
            pass
        pass
    
    if msg: bld.fatal(os.linesep.join(msg))
    return