waf

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

wscript (1828B)


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