[Avida-cvs] [avida3-svn] r47 - trunk/tests/c

kaben@myxo.css.msu.edu kaben at myxo.css.msu.edu
Sun Apr 9 16:37:44 PDT 2006


Author: kaben
Date: 2006-04-09 19:37:44 -0400 (Sun, 09 Apr 2006)
New Revision: 47

Modified:
   trunk/tests/c/SConscript
Log:

Changed c++ unit test support. Each test gets its own alias, and can be
run by name. All tests are run with alias 'force-test'. To run only
tests that have changed or haven't passed yet, use alias 'test-changed'.



Modified: trunk/tests/c/SConscript
===================================================================
--- trunk/tests/c/SConscript	2006-04-09 07:41:42 UTC (rev 46)
+++ trunk/tests/c/SConscript	2006-04-09 23:37:44 UTC (rev 47)
@@ -4,107 +4,86 @@
 
 Import('environment')
 
+e = environment
+
+def unit_test_action(target, source, env):
+  app = str(source[0].abspath)
+  if os.system(app)==0: open(str(target[0]), 'w').write("PASSED\n")
+  else: return 1
+unit_test_builder = Builder(action = unit_test_action)
+e.AppendUnique(BUILDERS = {'UnitTest' : unit_test_builder})
+
 def PhonyTarget(alias, action, depends = None):
-  """Returns an alias to a command that performs the
-  action.  This is implementated by a Command with a
-  nonexistant file target.  This command will run on every
-  build, and will never be considered 'up to date'. Acts
-  like a 'phony' target in make."""
+  """Returns an alias to a command that performs the action.
+  Implementated by a Command with a nonexistant file target.  This command will
+  run on every build, and will never be considered 'up to date'. Acts like a
+  'phony' target in make.
+  """
   phony_file = os.path.normpath(tempfile.mktemp(prefix="phony_%s_" % alias, dir="."))
   Depends(phony_file, depends)
   return Alias(alias, Command(target=phony_file, source=None, action=action))
 
+def Test(env, prg):
+  """Creates unit test from given program.
+  When unit test passes, a file stamp is made. If it ran successfully and there
+  is nothing changed, the unit test can be skipped next time.
 
-# Unit tests of tPtr in dumb and shared modes.
-#
-# Caveat: I have adapted the shared pointer unit tests from boost,
-# cutting and pasting, with little effort to understand the tests unless
-# they failed. Some the tests are probably consequently rendered
-# redundant or meaningless.
-#
-# On the other hand, they seem to indicate that shared and dumb tPtrs
-# behave in fundamentally the same way; and that shared tPtrs
-# interoperate well with boost::shared_ptrs.
-#
-# @kgn
+  Makes three alii: the name of program, force-test, and test-changed:
+  - First can be used to run individual unit test.
+  - Second is used to run changed unit tests.
+  - Third forces all unit tests to run.
+  """
+  name = str(prg[0])
+  stamp = name + '.passed'
+  env.UnitTest(stamp, prg)
+  alias = PhonyTarget(name, [prg], stamp)
+  env.Alias('force-test', name)
+  env.Alias('test-changed', stamp)
 
-# Unfortunately this test code relies on Boost's lightweight_test
-# libraries. So when $boostIncludeDir is undefined, I'm disabling the
-# unit tests, to permit building Avida without Boost.
+def TestList(env, name, list, *args, **kw):
+  """Creates a set of unit tests from given list of filename bases.
+
+  For each filename base 'blah', tries to make unit test using filename
+  'blah.cpp'.  Creates alias, of given name, to all tests in this set.
+  """
+  for i in list:
+    Test(e, e.Program(i, i + '.cpp', *args, **kw))
+  Alias(name, list)
+
+# Test code relies on Boost's lightweight_test libraries (for now). When
+# $boostIncludeDir is undefined, unit tests are disabled to permit building
+# Avida without Boost.
 #
 # @kgn
-if environment.subst('$boostIncludeDir') not in [None, 'None', '']:
-  tMemTrack_test = environment.Program('tMemTrack_test',
-    [
+if e.subst('$boostIncludeDir') not in [None, 'None', '']:
+  Test(e, e.Program('tMemTrack_test', [
       'tMemTrack_test.cpp',
-      'tMemTrack_test_auxillary.cpp'
-    ]
+      'tMemTrack_test_auxillary.cpp',
+    ],
+  ) )
+
+  TestList(e, 'tPtr_unit_tests', [
+      'dumb_tPtr_test',
+      'shared_tPtr_test',
+      'extended_shared_tPtr_test',
+      'shared_tPtr_basic_test',
+      'shared_tPtr_from_this_test',
+    ], LIBS = [
+      #'tools',
+    ],
   )
-  PhonyTarget('tMemTrack_test', [tMemTrack_test], tMemTrack_test[0].abspath)
 
-  tPtr_unit_tests = [
-    'dumb_tPtr_test',
-    'shared_tPtr_test',
-    'extended_shared_tPtr_test',
-    'shared_tPtr_basic_test',
-    'shared_tPtr_from_this_test',
-  ]
-  for name in tPtr_unit_tests:
-    test = environment.Program(name, name + '.cpp')
-    PhonyTarget(name, [test], test[0].abspath)
-  Alias('tPtr_unit_tests', tPtr_unit_tests)
-  
+  TestList(e, 'container_unit_tests', [
+      'dumb_tDictionary_test',
+      'shared_tDictionary_test',
+      'dumb_tList_test',
+      'shared_tList_test',
+    ], LIBS = [
+      'tools',
+    ],
+  )
 
-  container_unit_tests = [
-    'dumb_tDictionary_test',
-    'shared_tDictionary_test',
-    'dumb_tList_test',
-    'shared_tList_test',
-  ]
-  for name in container_unit_tests:
-    test = environment.Program(name, name + '.cpp', LIBS = ['tools',],)
-    PhonyTarget(name, [test], test[0].abspath)
-  Alias('container_unit_tests', container_unit_tests)
-
-
-  tArray_archive_test = environment.Program(
-    'tArray_archive_test', 'tArray_archive_test.cpp', LIBS = ['archive', 'boost_serialization'],) 
-  PhonyTarget('tArray_archive_test', [tArray_archive_test], tArray_archive_test[0].abspath)
-
-  tDictionary_archive_test = environment.Program(
-    'tDictionary_archive_test', 'tDictionary_archive_test.cpp', LIBS = ['archive', 'tools', 'boost_serialization'],) 
-  PhonyTarget('tDictionary_archive_test', [tDictionary_archive_test], tDictionary_archive_test[0].abspath)
-
-  tList_archive_test = environment.Program(
-    'tList_archive_test', 'tList_archive_test.cpp', LIBS = ['archive', 'boost_serialization'],) 
-  PhonyTarget('tList_archive_test', [tList_archive_test], tList_archive_test[0].abspath)
-
-  tMatrix_archive_test = environment.Program(
-    'tMatrix_archive_test', 'tMatrix_archive_test.cpp', LIBS = ['archive', 'boost_serialization'],) 
-  PhonyTarget('tMatrix_archive_test', [tMatrix_archive_test], tMatrix_archive_test[0].abspath)
-
-  cFile_archive_test = environment.Program(
-    'cFile_archive_test', 'cFile_archive_test.cpp', LIBS = ['archive', 'tools', 'boost_serialization'],) 
-  PhonyTarget('cFile_archive_test', [cFile_archive_test], cFile_archive_test[0].abspath)
-
-  cInitFile_archive_test = environment.Program(
-    'cInitFile_archive_test', 'cInitFile_archive_test.cpp', LIBS = ['archive', 'tools', 'boost_serialization'],) 
-  PhonyTarget('cInitFile_archive_test', [cInitFile_archive_test], cInitFile_archive_test[0].abspath)
-
-  cRandom_archive_test = environment.Program(
-    'cRandom_archive_test', 'cRandom_archive_test.cpp', LIBS = ['archive', 'tools', 'boost_serialization'],) 
-  PhonyTarget('cRandom_archive_test', [cRandom_archive_test], cRandom_archive_test[0].abspath)
-
-  cString_archive_test = environment.Program(
-    'cString_archive_test', 'cString_archive_test.cpp', LIBS = ['archive', 'tools', 'boost_serialization'],) 
-  PhonyTarget('cString_archive_test', [cString_archive_test], cString_archive_test[0].abspath)
-
-  cStringList_archive_test = environment.Program(
-    'cStringList_archive_test', 'cStringList_archive_test.cpp', LIBS = ['archive', 'tools', 'boost_serialization'],) 
-  PhonyTarget('cStringList_archive_test', [cStringList_archive_test], cStringList_archive_test[0].abspath)
-
-  Alias( 'archive_unit_tests',
-    [
+  TestList(e, 'archive_unit_tests', [
       'tArray_archive_test',
       'tDictionary_archive_test',
       'tList_archive_test',
@@ -114,17 +93,26 @@
       'cRandom_archive_test',
       'cString_archive_test',
       'cStringList_archive_test',
+    ], LIBS = [
+      'archive',
+      'tools',
+      'boost_serialization',
     ]
   )
 
-  cConfig_test = environment.Program('cConfig_test', 'cConfig_test.cpp', LIBS = ['tools'],)
-  PhonyTarget('cConfig_test', [cConfig_test], cConfig_test[0].abspath)
+  Test(e, e.Program('cConfig_test', [
+      'cConfig_test.cpp',
+    ], LIBS = [
+      'tools',
+    ],
+  ) )
 
-  cConfig_override_env = environment.Copy(
-    CPPDEFINES = string.split(environment.subst('$CPPDEFINES')) + ['OVERIDE_CONFIG'],
-    CPPPATH = string.split(environment.subst('$CPPPATH')) + [environment.GetLaunchDir()],
+  e2 = e.Copy(
+    CPPDEFINES = string.split(e.subst('$CPPDEFINES')) + ['OVERIDE_CONFIG'],
+    CPPPATH = string.split(e.subst('$CPPPATH')) + [e.GetLaunchDir()],
   );
-  cConfig_override_objects = [cConfig_override_env.Object(
+  cConfig_override_objects = [
+    e2.Object(
       '%s_cConfig_override' % n,
       '../../source/tools/%s.cpp' % n
     ) for n in [
@@ -136,23 +124,17 @@
       'cStringList',
       'cStringUtil',
   ] ]
-  cConfigOverrides_test = cConfig_override_env.Program(
-    'cConfigOverrides_test',
-    source = ['cConfigOverrides_test.cpp'] + cConfig_override_objects
-  )
-  Depends(cConfigOverrides_test, cConfig_test)
-  PhonyTarget('cConfigOverrides_test', [cConfigOverrides_test], cConfigOverrides_test[0].abspath)
+  Test(e2, e2.Program('cConfigOverrides_test',
+    source = [
+      'cConfigOverrides_test.cpp',
+    ] + cConfig_override_objects
+  ) )
 
-  brainstorm_test = environment.Program('brainstorm_test',
-    'brainstorm_test.cpp',
-    LIBS = ['tools'],)
-  PhonyTarget('brainstorm_test', [brainstorm_test], brainstorm_test[0].abspath)
-  Alias(
-    'brainstorm_unit_tests',
-    [
+  TestList(e, 'brainstorm_unit_tests', [
       'brainstorm_test',
-    ]
+    ], LIBS = [
+      'tools',
+    ],
   )
 
-
 # vim: set ft=python:




More information about the Avida-cvs mailing list