cppunit test

Nagy Thomas tnagy256 at yahoo.fr
Wed Jan 4 22:19:41 CET 2006


> I wrote a cppunit.py with its
> unix/generate_cppunit.py
> I want to execute the test after the compilation.
> But now it is just after scons parse all the
> sconscript and before the build

Until a better solution appears, here is an idea, in
pseudo-code:

"""
if 'test' in sys.argv:
    env['_RUNTTESTS_']=1



if '_RUNTESTS_' in env:
    run_some_unit_tests()
else:
    do_something_else()
"""

Scons functions like "addPostAction" may help too,
have a look.

Hope this helps,
Thomas


> Did someone already have a clue to make this the
> correct way.
> 
> By
> > # Made from scons qt4.py
> # Frederic-Emmanuel PICCA, 2006 <picca at
> synchrotron-soleil fr>
> 
> """
> Run scons -h to display the associated help, or look
> below ..
> """
> 
> import os
> 
> def exists(env):
> 	return True
> 
> def generate(env):
> 	import sys
> 	"""Set up the cppunit environment and builders"""
> 	if env['HELP']:
> 		p=env.pprint
> 		p('BOLD','*** cppunit options ***')
> 		p('BOLD','--------------------')
> 		p('BOLD','* cppunitincludes ','cppunit includes
> path (/usr/include/cppunit on debian, ..)')
> 		p('BOLD','* cppunitlibs     ','cppunit libraries
> path, for linking the program')
> 		p('BOLD','* scons configure
> cppunitincludes=/usr/include/cppunit
> cppunitlibs=/usr/lib\n')
> 		return
> 	
> 	# Detect the environment - replaces ./configure
> implicitely and store the options into a cache
> 	from SCons.Options import Options
> 	cachefile=env['CACHEDIR']+'cppunit.cache.py'
> 	opts = Options(cachefile)
> 	opts.AddOptions(
> 		('CACHED_CPPUNIT', 'whether  CPPUNIT  was found'),
> 		('RUNTESTS', 'enable compiling of test
> applications' ),	
> 		#('CPPUNITLIBPATH', 'path to the cppunit
> libraries'),
> 		#('CPPUNITINCLUDEPATH', 'path to the cppunit
> includes'),
> 		('CXXFLAGS_CPPUNIT', 'additional compilation
> flags'),
> 		('LINKFLAGS_CPPUNIT','')
> 		#('RPATH_CPPUNIT','')
> 	)
> 	opts.Update(env)
> 
> 	# reconfigure when things are missing
> 	if not env['HELP'] and (env['_CONFIGURE_'] or (not
> env.has_key('CACHED_CPPUNIT'))):
> 		env['_CONFIGURE_']=1
> 		for opt in opts.options:
> 			if env.has_key(opt.key): env.__delitem__(opt.key)
> 		import sys
> 		if sys.platform == 'darwin':
> 			sys.path.append('bksys'+os.sep+'osx')
> 			from detect_cppunit import detect
> 		elif env['WINDOWS']:
> 			sys.path.append('bksys'+os.sep+'win32')
> 			from detect_cppunit import detect
> 		else:
> 			sys.path.append('bksys'+os.sep+'unix')
> 			from detect_cppunit import detect
> 	
> 		# configure test
> 		if 'runtests' in sys.argv:
> 			print "compiling of test applications enabled"
> 			env['RUNTESTS'] = 1
> 		else:
> 			env['RUNTESTS'] = 0		
> 		
> 		conf = env.Configure(custom_tests = {
> 'Check_cppunit' : detect} )
> 		conf.Check_cppunit(env)
> 		env = conf.Finish()
> 		env['CACHED_CPPUNIT'] = 1
> 		opts.Save(cachefile, env)
> 
> 	# run the test if necessary
> 	if env['RUNTESTS']:
> 		def RunUnitTest(env):		
> 			import popen2
> 			print "running %s " % (env.target)
> 			process = popen2.Popen3(env.target, 1)
> 			process.tochild.close()
> 			status = process.wait()
> 	
> 		#env['BUILDERS']['RunUnitTest'] =
> env.Builder(action = RunUnitTest)
> 		#env.AlwaysBuild('runtest');
> 
> 					
> 	import generic
> 	class cppunitobj(generic.genobj):
> 		def __init__(self, senv=None):
> 			if senv: generic.genobj.__init__(self, 'program',
> senv)
> 			else: generic.genobj.__init__(self, 'program',
> env)
> 
> 		def execute(self):
> 			self.env=self.orenv.Copy()
> 		
>
self.env.AppendUnique(LINKFLAGS=self.env['LINKFLAGS_CPPUNIT'])
> 		
>
self.env.AppendUnique(CXXFLAGS=self.env['CXXFLAGS_CPPUNIT'])
> 			generic.genobj.execute(self)
> 			if self.env['RUNTESTS']:
> 				RunUnitTest(self)
> 				#self.env.Alias('runtests',
> self.env.RunUnitTest())
> 
> 	# Attach the functions to the environment so that
> SConscripts can use them
> 	from SCons.Script.SConscript import
> SConsEnvironment
> 	SConsEnvironment.cppunitobj=cppunitobj
> 
> > # Frederic-Emmanuel PICCA, 2006
> 
> import os
> import SCons.Util
> 
> CLVar = SCons.Util.CLVar
> 	
> def detect(context, env):			
> 	context.Message('Checking for cppunit... ')	
> 	cppunit_config = env.find_program('cppunit-config',
> os.environ['PATH'].split(':'))
> 	if cppunit_config:
> 		env.ParseConfig(cppunit_config+' --cflags
> --libs');
> 		env['CXXFLAGS_CPPUNIT'] = SCons.Util.CLVar(
> 			os.popen(cppunit_config+' --cflags
> 2>/dev/null').read().strip() );
> 		env['LINKFLAGS_CPPUNIT'] = SCons.Util.CLVar(
> 			os.popen(cppunit_config+' --libs
> 2>/dev/null').read().strip() );
> 		context.Result(True)
> 	else:
> 		context.Result(False)
> 		env.Exit(0)
> > _______________________________________________
> Kde-buildsystem mailing list
> Kde-buildsystem at kde.org
>
https://mail.kde.org/mailman/listinfo/kde-buildsystem
> 


/* Thomas Nagy */


	

	
		
___________________________________________________________________________ 
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.
Téléchargez sur http://fr.messenger.yahoo.com


More information about the Kde-buildsystem mailing list