wscript 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Richard Quirk, 2008
  4. """
  5. Execute tests during the build - requires cppunit
  6. To force all tests, run with "waf build --alltests"
  7. """
  8. from waflib.Tools import waf_unit_test
  9. top = '.'
  10. out = 'build'
  11. def options(opt):
  12. opt.load('compiler_cxx')
  13. opt.load('waf_unit_test')
  14. def configure(conf):
  15. conf.load('compiler_cxx')
  16. conf.load('waf_unit_test')
  17. # the demo files require cppunit - but the waf tool does not
  18. conf.check_cfg(package='cppunit', args='--cflags --libs', mandatory=True)
  19. if 'dl' not in conf.env.LIB_CPPUNIT:
  20. l = conf.check(lib='dl', uselib_store='CPPUNIT')
  21. # the interpreted tests need python
  22. conf.find_program('python', mandatory=False)
  23. from waflib import Logs
  24. def summary(bld):
  25. lst = getattr(bld, 'utest_results', [])
  26. if lst:
  27. total = len(lst)
  28. tfail = len([x for x in lst if x[1]])
  29. val = 100 * (total - tfail) / (1.0 * total)
  30. Logs.pprint('CYAN', 'test report %3.0f%% success' % val)
  31. Logs.pprint('CYAN', ' tests that fail %d/%d' % (tfail, total))
  32. for (f, code, out, err) in lst:
  33. if code:
  34. Logs.pprint('CYAN', ' %s' % f)
  35. Logs.pprint('RED', 'status: %r' % code)
  36. if out: Logs.pprint('RED', 'out: %r' % out)
  37. if err: Logs.pprint('RED', 'err: %r' % err)
  38. def build(bld):
  39. bld.recurse('src tests')
  40. # waf_unit_test.summary is a pretty ugly function for displaying a report (feel free to improve!)
  41. # results -> bld.utest_results [(filename, returncode, stdout, stderr), (..., ), ...]
  42. #bld.add_post_fun(waf_unit_test.summary)
  43. bld.add_post_fun(summary)
  44. # to execute all tests:
  45. # $ waf --alltests
  46. # to set this behaviour permanenly:
  47. #bld.options.all_tests = True
  48. bld.options.clear_failed_tests = True
  49. # debugging zone:
  50. # $ waf --zones=ut
  51. # setting the cwd for a unit test execution: see tests/test1/wscript_build (ut_cwd)