Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 42620103d8ee8a2d972d3103bad0ab73 > files > 358

waf-1.5.19-1.fc14.noarch.rpm

#! /usr/bin/env python
# encoding: utf-8
# Richard Quirk, 2008

import unittestw, Utils, Options

top = '.'
out = 'build'

def set_options(opt):
	opt.tool_options('compiler_cxx')
	opt.tool_options('unittest')

	opt.add_option('--onlytests', action='store_true', default=True, help='Exec unit tests only', dest='only_tests')

def configure(conf):
	conf.check_tool('compiler_cxx')
	conf.check_tool('unittest')

	# the demo files require cppunit - but the waf tool does not
	conf.check_cfg(package='cppunit', args='--cflags --libs', mandatory=True)
	if 'dl' not in conf.env.LIB_CPPUNIT:
		l = conf.check(lib='dl', uselib_store='CPPUNIT')

def build(bld):
	bld.add_subdirs('src tests')

	# unittestw.summary is a pretty ugly function for displaying a report (feel free to improve!)
	# results -> bld.utest_results [(filename, returncode, stdout, stderr), (..., ), ...]
	bld.add_post_fun(unittestw.summary)

	# to execute all tests:
	# $ waf --alltests
	# to set this behaviour permanenly:
	Options.options.all_tests = True

	# to build on one computer and execute the tests on another:
	#  uncomment the following block, build on the first, then on the second, configure the project
	#  and build using "./waf --onlytests  --alltests" to force the test execution
	"""
	if Options.options.only_tests:
		import Task, Constants
		old = Task.Task.runnable_status
		def test_status(self):
			if self.__class__.__name__ != 'utest':

				for node in getattr(self, 'outputs', []):
					try:
						self.generator.bld.node_sigs[self.env.variant()][node.id]
					except:
						self.generator.bld.node_sigs[self.env.variant()][node.id] = Constants.SIG_NIL

				return Constants.SKIP_ME
			return old(self)
		Task.Task.runnable_status = test_status
	else:
		import Task, Constants
		old = Task.Task.runnable_status
		def test_status(self):
			if self.__class__.__name__ == 'utest':
				return Constants.SKIP_ME
			return old(self)
		Task.Task.runnable_status = test_status
	"""

	# debugging zone:
	# $ waf --zones=ut
	# setting the cwd for a unit test execution: see tests/test1/wscript_build (ut_cwd)

"""
old waf versions upgrade:
if the method check does not exist, add it:

def check(ctx):
	ut = UnitTest.unit_test()
	ut.change_to_testfile_dir = True
	ut.run()
	ut.print_results()
"""