waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

wscript (1962B)


      1 #! /usr/bin/env python
      2 # encoding: utf-8
      3 # Sylvain Rouquette, 2014
      4 # based on Richard Quirk's demo (unit_test), 2008
      5 
      6 """
      7 Execute tests during the build - requires cppunit
      8 
      9 To force all tests, run with "waf build --alltests"
     10 """
     11 
     12 from waflib import Logs
     13 
     14 top = '.'
     15 out = 'build'
     16 
     17 def options(opt):
     18     opt.load('compiler_cxx')
     19     opt.load('waf_unit_test')
     20     opt.add_option('--onlytests', action='store_true', default=True, help='Exec unit tests only', dest='only_tests')
     21 
     22 def configure(conf):
     23     conf.load('compiler_cxx')
     24     conf.load('waf_unit_test')
     25     conf.check(lib='gtest', uselib_store='GTEST')
     26 
     27 
     28 def gtest_results(bld):
     29     lst = getattr(bld, 'utest_results', [])
     30     if not lst:
     31         return
     32     for (f, code, out, err) in lst:
     33         # if not code:
     34         #     continue
     35 
     36         # uncomment if you want to see what's happening
     37         # print(str(out, 'utf-8'))
     38         output = str(out, 'utf-8').splitlines()
     39         for i, line in enumerate(output):
     40             if '[ RUN      ]' in line and code:
     41                 i += 1
     42                 if '    OK ]' in output[i]:
     43                     continue
     44                 while not '[ ' in output[i]:
     45                     Logs.warn(output[i])
     46                     i += 1
     47             elif ' FAILED  ]' in line and code:
     48                 Logs.error(line)
     49             elif ' PASSED  ]' in line:
     50                 Logs.info(line)
     51 
     52 def build(bld):
     53     bld.recurse('src tests')
     54 
     55     # waf_unit_test.summary is a pretty ugly function for displaying a report (feel free to improve!)
     56     # results -> bld.utest_results [(filename, returncode, stdout, stderr), (..., ), ...]
     57     #bld.add_post_fun(waf_unit_test.summary)
     58     bld.add_post_fun(gtest_results)
     59 
     60     # to execute all tests:
     61     # $ waf --alltests
     62     # to set this behaviour permanently:
     63     bld.options.all_tests = True
     64 
     65     # debugging zone:
     66     # $ waf --zones=ut
     67     # setting the cwd for a unit test execution: see tests/test1/wscript_build (ut_cwd)
     68