wscript 1.9 KB

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