[Avida-SVN] r1224 - in extras: . source/testsuites source/tools

avidaedward at myxo.css.msu.edu avidaedward at myxo.css.msu.edu
Sat Jan 27 22:16:58 PST 2007


Author: avidaedward
Date: 2007-01-28 01:16:57 -0500 (Sun, 28 Jan 2007)
New Revision: 1224

Modified:
   extras/
   extras/source/testsuites/nTestDriver.cpp
   extras/source/testsuites/nTestLib.cpp
   extras/source/testsuites/nTestSettings.cpp
   extras/source/tools/cTestDriver.cpp
   extras/source/tools/cTestDriver.h
   extras/source/tools/cTestLib.cpp
   extras/source/tools/cTestLib.h
   extras/source/tools/cTestSettings.cpp
   extras/source/tools/cTestSettings.h
Log:
 r1241 at clearly:  kaben | 2007-01-21 19:14:27 -0500
 Completed integration of cTestSettings into cTestDriver and cTestLib.
 Next step: removing "test attributes".



Property changes on: extras
___________________________________________________________________
Name: svk:merge
   - 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1206
   + 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1241

Modified: extras/source/testsuites/nTestDriver.cpp
===================================================================
--- extras/source/testsuites/nTestDriver.cpp	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/testsuites/nTestDriver.cpp	2007-01-28 06:16:57 UTC (rev 1224)
@@ -7,10 +7,17 @@
 
 using namespace std;
 
+/*
+XXX To-Do:
+- cTestDriver_FunctionalTest_Settings
+*/
+
 namespace nTestDriver {
+/* Brainstorms. {{{1 */
+  /* cTestDriver_Brainstorm_HelloWorld {{{2 */
   namespace Brainstorm_HelloWorld {
-    void test(const cStringList &attrs){
-      if(!attrs.HasString("HelloWorld")){
+    void test(cTestSettings &settings){
+      if(!settings.HasSetting("HelloWorld")){
         cout << "XXX Skipping HelloWorld test." << endl;
         return;
       }
@@ -22,6 +29,8 @@
     cAddTestSuite t("cTestDriver_Brainstorm_HelloWorld", test);
   }
 
+/* Functional Tests. {{{1 */
+  /* cTestDriver_FunctionalTest_Attributes {{{2 */
   namespace FunctionalTest_Attributes {
     bool test_attribute_enabled;
     void testrunner(const cStringList &attrs){
@@ -53,6 +62,43 @@
     cAddTestSuite t("cTestDriver_FunctionalTest_Attributes", test);
   }
 
+  /* cTestDriver_FunctionalTest_Settings {{{2 */
+  namespace FunctionalTest_Settings {
+    bool has_setting;
+    cString setting_value;
+    void testrunner(cTestSettings &settings){
+      has_setting = settings.HasSetting("TestSettings");
+      setting_value = settings.Setting("TestSettings");
+    }
+    void test(){
+      cStringList args;
+      cTestDriver td;
+
+      cTestLib::getLib().reg(
+        "cTestDriver_FunctionalTest_Settings_subtest",
+        testrunner
+      );
+
+      args.Clear();
+      args.PushRear("Set_TestSettings_blah");
+      args.PushRear("cTestDriver_FunctionalTest_Settings_subtest");
+      td.Tests(args);
+      TEST(has_setting);
+      TEST(setting_value == "blah");
+
+      args.Clear();
+      args.PushRear("Unset_TestSettings");
+      args.PushRear("cTestDriver_FunctionalTest_Settings_subtest");
+      td.Tests(args);
+      TEST(!has_setting);
+      TEST(setting_value == "");
+
+      cTestLib::getLib().unreg("cTestDriver_FunctionalTest_Settings_subtest");
+    }
+    cAddTestSuite t("cTestDriver_FunctionalTest_Settings", test);
+  }
+
+  /* cTestDriver_FunctionalTest_AlteringErrorCount {{{2 */
   namespace FunctionalTest_AlteringErrorCount {
     void test(const cStringList &attrs){
       int original_error_count, new_error_count;
@@ -81,6 +127,8 @@
     cAddTestSuite t("cTestDriver_FunctionalTest_AlteringErrorCount", test);
   }
 
+/* Regressions. {{{1 */
+  /* cTestDriver_Regression_SomeTestSuitesNotProperlyMatched {{{2 */
   namespace Regression_SomeTestSuitesNotProperlyMatched {
 
     bool t1_called, t2_called, t3_called, t4_called;
@@ -111,12 +159,12 @@
       cConsoleCatcher cc;
       cc.Capture(cerr);
       {
-        cout << "... ('key not supported' error expected; saving error count of ";
-        cout << saved_error_count << ") ..." << endl;
+        cerr << "... ('key not supported' error expected; saving error count of ";
+        cerr << saved_error_count << ") ..." << endl;
         td.Tests(args);
         td.testErrors() = saved_error_count;
-        cout << "... (error count restored to ";
-        cout << saved_error_count << ") ..." << endl;
+        cerr << "... (error count restored to ";
+        cerr << saved_error_count << ") ..." << endl;
       }
       cString captured = cc.Release();
 
@@ -189,6 +237,8 @@
     cAddTestSuite t("cTestDriver_Regression_SomeTestSuitesNotProperlyMatched", test);
   }
 
+/* Unit Tests. {{{1 */
+  /* cTestDriver_UnitTest_HelloWorld {{{2 */
   namespace UnitTest_HelloWorld {
     void test(const cStringList &attrs){
       if(!attrs.HasString("HelloWorld")){
@@ -203,14 +253,21 @@
     cAddTestSuite t("cTestDriver_UnitTest_HelloWorld", test);
   }
 
+  /* cTestDriver_RegisterAndUnregisterAndSupports {{{2 */
   namespace UnitTest_RegisterAndUnregisterAndSupports {
     void t1WithAttrs(const cStringList &attrs){ }
     void t3WithoutAttrs(){ }
+    void testSettings(cTestSettings &settings){}
+
     void test(const cStringList &attrs){
+      ERROR("kgn at FIXME : redundancy with cTestLib_UnitTest_SupportsAndRegAndUnreg");
+
       TEST(!cTestLib::getLib().supports(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs"));
       TEST(!cTestLib::getLib().supports(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs"));
+      TEST(!cTestLib::getLib().supports(
+        "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_testSettings"));
 
       /* Install subtests. */
       cTestLib::getLib().reg(
@@ -221,25 +278,36 @@
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs",
         t3WithoutAttrs
       );
+      cTestLib::getLib().reg(
+        "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_testSettings",
+        testSettings
+      );
 
       TEST(cTestLib::getLib().supports(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs"));
       TEST(cTestLib::getLib().supports(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs"));
+      TEST(cTestLib::getLib().supports(
+        "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_testSettings"));
 
       cTestLib::getLib().unreg(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs");
       cTestLib::getLib().unreg(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs");
+      cTestLib::getLib().unreg(
+        "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_testSettings");
 
       TEST(!cTestLib::getLib().supports(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs"));
       TEST(!cTestLib::getLib().supports(
         "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs"));
+      TEST(!cTestLib::getLib().supports(
+        "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_testSettings"));
     }
     cAddTestSuite t("cTestDriver_RegisterAndUnregisterAndSupports", test);
   }
 
+  /* cTestDriver_UnitTest_TestErrors {{{2 */
   namespace UnitTest_TestErrors {
     void test(const cStringList &attrs){
       int original_error_count, new_error_count;
@@ -263,6 +331,7 @@
     cAddTestSuite t("cTestDriver_UnitTest_TestErrors", test);
   }
 
+  /* cTestDriver_UnitTest_ResetTestErrors {{{2 */
   namespace UnitTest_ResetTestErrors {
     void test(const cStringList &attrs){
       int original_error_count, new_error_count;
@@ -288,6 +357,7 @@
     cAddTestSuite t("cTestDriver_UnitTest_ResetTestErrors", test);
   }
 
+/* Physical Link. {{{1 */
   /*
   This function does nothing;
   but if the compiler sees that this function is called, then the

Modified: extras/source/testsuites/nTestLib.cpp
===================================================================
--- extras/source/testsuites/nTestLib.cpp	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/testsuites/nTestLib.cpp	2007-01-28 06:16:57 UTC (rev 1224)
@@ -3,6 +3,11 @@
 #include <iostream>
 using namespace std;
 
+/*
+XXX To-Do:
+- test void tryRun(cString key, const cTestSettings &settings);
+*/
+
 namespace nTestLib {
 /* Brainstorms. {{{1 */
   /* cTestLib_Brainstorm_HelloWorld {{{2 */
@@ -42,21 +47,31 @@
   namespace UnitTest_SupportsAndRegAndUnreg {
     void testVoid(){}
     void testAttr(const cStringList &attrs){}
+    void testSettings(cTestSettings &settings){}
+
     void test(){
-
-      /* Test a testrunner taking no args. */
+      /* Test a testrunner taking no args. {{{3 */
       TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testVoid"));
       cTestLib::getLib().reg("cTestLib_SupportsAndRegAndUnreg_testVoid", testVoid);
       TEST(cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testVoid"));
       cTestLib::getLib().unreg("cTestLib_SupportsAndRegAndUnreg_testVoid");
       TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testVoid"));
 
-      /* Test a testrunner taking attributes as arg. */
+      /* Test a testrunner taking attributes as arg. {{{3 */
       TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testAttr"));
       cTestLib::getLib().reg("cTestLib_SupportsAndRegAndUnreg_testAttr", testAttr);
       TEST(cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testAttr"));
       cTestLib::getLib().unreg("cTestLib_SupportsAndRegAndUnreg_testAttr");
       TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testAttr"));
+
+      /* Test a testrunner taking settings as arg. {{{3 */
+      TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testSettings"));
+      cTestLib::getLib().reg("cTestLib_SupportsAndRegAndUnreg_testSettings", testSettings);
+      TEST(cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testSettings"));
+      cTestLib::getLib().unreg("cTestLib_SupportsAndRegAndUnreg_testSettings");
+      TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testSettings"));
+
+      /* }}}3 */
     }
     cAddTestSuite t("cTestLib_UnitTest_SupportsAndRegAndUnreg", test);
   }
@@ -165,6 +180,7 @@
     cAddTestSuite t3("cTestLib_Regression_ErrorLoadingTestrunnerByKey3", test3);
   }
 
+/* Physical Link. {{{1 */
   /*
   This function does nothing;
   but if the compiler sees that this function is called, then the
@@ -173,4 +189,3 @@
   void PhysicalLink(){}
 }
 
-

Modified: extras/source/testsuites/nTestSettings.cpp
===================================================================
--- extras/source/testsuites/nTestSettings.cpp	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/testsuites/nTestSettings.cpp	2007-01-28 06:16:57 UTC (rev 1224)
@@ -4,6 +4,11 @@
 
 using namespace std;
 
+/*
+XXX To-Do:
+- test void Clear();
+*/
+
 namespace nTestSettings {
 /* Brainstorms. {{{1 */
   /* cTestSettings_Brainstorm_HelloWorld {{{2 */
@@ -25,56 +30,45 @@
   namespace Brainstorm_ClassDesign {
     void test(){
       cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
-
-      /* Verify basic functionality : shadowing tDictionary. */
+      /* Verify basic functionality : shadowing tDictionary. {{{3 */
       {
         cTestSettings ts;
         cString value("ick");
-
-        /* Verify initial number of settings is zero. */
+        /* Verify initial number of settings is zero. {{{4 */
         TEST(0 == ts.Size());
-
-        /* Verify behavior on checking a setting that hasn't been set. */
+        /* Verify behavior on checking a setting that hasn't been set. {{{4 */
         TEST(!ts.HasSetting("blah"));
         TEST(ts.Setting("blah") == "");
-
-        /* Set "blah" to "hum". */
+        /* Set "blah" to "hum". {{{4 */
         ts.Set("blah", "hum");
         TEST(1 == ts.Size());
-
-        /* Verify behavior on checking a valid setting. */
+        /* Verify behavior on checking a valid setting. {{{4 */
         TEST(ts.HasSetting("blah"));
         TEST(ts.Setting("blah") == "hum");
-
-        /* Reset "blah" to "ho". */
+        /* Reset "blah" to "ho". {{{4 */
         ts.Set("blah", "ho");
         TEST(1 == ts.Size());
-
-        /* Verify behavior on reset of a valid setting. */
+        /* Verify behavior on reset of a valid setting. {{{4 */
         TEST(ts.HasSetting("blah"));
         TEST(ts.Setting("blah") != "hum");
         TEST(ts.Setting("blah") == "ho");
-
-        /* Verify unsetting an invalid setting. */
+        /* Verify unsetting an invalid setting. {{{4 */
         TEST(!ts.HasSetting("urk"));
         TEST(ts.Setting("urk") == "");
-
-        /* Verify unsetting a valid setting. */
+        /* Verify unsetting a valid setting. {{{4 */
         TEST(ts.HasSetting("blah"));
         value = ts.Unset("blah");
         TEST(value == "ho");
         TEST(0 == ts.Size());
         TEST(ts.Setting("blah") == "");
-
-        /* Verify unsetting a formerly valid setting. */
+        /* Verify unsetting a formerly valid setting. {{{4 */
         TEST(!ts.HasSetting("blah"));
         value = ts.Unset("blah");
         TEST(value == "");
         TEST(0 == ts.Size());
         TEST(ts.Setting("blah") == "");
-
-        /* Verify parsing various "setting" strings. */
-        /* - This shouldn't parse. */
+        /* Verify parsing various "setting" strings. {{{4 */
+        /* - This shouldn't parse. {{{5 */
         TEST(!ts.ParseSettingString("nope"));
         TEST(0 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -83,7 +77,7 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
-        /* - This should parse, but sets "" to "". */
+        /* - This should parse, but sets "" to "". {{{5 */
         TEST(ts.ParseSettingString("Set"));
         TEST(1 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -92,7 +86,7 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
-        /* - This should parse, but sets "" to "". */
+        /* - This should parse, but sets "" to "". {{{5 */
         TEST(ts.ParseSettingString("Set_"));
         TEST(1 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -101,7 +95,7 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
-        /* - This should parse, but sets "" to "". */
+        /* - This should parse, but sets "" to "". {{{5 */
         TEST(ts.ParseSettingString("Set__"));
         TEST(1 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -110,7 +104,7 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
-        /* - This should parse, but sets "" to "hmf". */
+        /* - This should parse, but sets "" to "hmf". {{{5 */
         TEST(ts.ParseSettingString("Set__hmf"));
         TEST(1 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -119,7 +113,7 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "hmf");
-        /* - This should parse, but sets "" to "hmf". */
+        /* - This should parse, but sets "" to "hmf". {{{5 */
         TEST(ts.ParseSettingString("Set__good_grief"));
         TEST(1 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -128,7 +122,7 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "good_grief");
-        /*   This should parse, and should set "x" to "". */
+        /* - This should parse, and should set "x" to "". {{{5 */
         TEST(ts.ParseSettingString("Set_x"));
         TEST(2 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -137,7 +131,7 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "good_grief");
-        /*   This should parse, and should set "y" to "fubar. */
+        /* - This should parse, and should set "y" to "fubar". {{{5 */
         TEST(ts.ParseSettingString("Set_y_fubar"));
         TEST(3 == ts.Size());
         TEST(ts.HasSetting("y"));
@@ -146,7 +140,7 @@
         TEST(ts.Setting("y") == "fubar");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "good_grief");
-        /*   This should parse, and should set "y" to "z_z. */
+        /* - This should parse, and should set "y" to "z_z". {{{5 */
         TEST(ts.ParseSettingString("Set_y_z_z"));
         TEST(3 == ts.Size());
         TEST(ts.HasSetting("y"));
@@ -155,7 +149,7 @@
         TEST(ts.Setting("y") == "z_z");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "good_grief");
-        /*   This should parse, but unset "" . */
+        /* - This should parse, but unset "" . {{{5 */
         TEST(ts.ParseSettingString("Unset"));
         TEST(2 == ts.Size());
         TEST(ts.HasSetting("y"));
@@ -164,7 +158,7 @@
         TEST(ts.Setting("y") == "z_z");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
-        /*   This should parse, but unset "". */
+        /* - This should parse, but unset "". {{{5 */
         TEST(ts.ParseSettingString("Unset_"));
         TEST(2 == ts.Size());
         TEST(ts.HasSetting("y"));
@@ -173,7 +167,7 @@
         TEST(ts.Setting("y") == "z_z");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
-        /*   This should parse, and should unset "x". */
+        /* - This should parse, and should unset "x". {{{5 */
         TEST(ts.ParseSettingString("Unset_x"));
         TEST(1 == ts.Size());
         TEST(ts.HasSetting("y"));
@@ -182,7 +176,7 @@
         TEST(ts.Setting("y") == "z_z");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
-        /*   This should parse, and should unset "y". */
+        /* - This should parse, and should unset "y". {{{5 */
         TEST(ts.ParseSettingString("Unset_y_z_z"));
         TEST(0 == ts.Size());
         TEST(!ts.HasSetting("y"));
@@ -191,6 +185,17 @@
         TEST(ts.Setting("y") == "");
         TEST(ts.Setting("x") == "");
         TEST(ts.Setting("") == "");
+        /* - This should set "x", "y", and "", then unset all at once. {{{5 */
+        TEST(ts.ParseSettingString("Set_x"));
+        TEST(ts.ParseSettingString("Set_y_fubar"));
+        TEST(ts.ParseSettingString("Set"));
+        TEST(ts.HasSetting("y"));
+        TEST(ts.HasSetting("x"));
+        TEST(ts.HasSetting(""));
+        ts.Clear();
+        TEST(!ts.HasSetting("y"));
+        TEST(!ts.HasSetting("x"));
+        TEST(!ts.HasSetting(""));
       }
     }
     cAddTestSuite t("cTestSettings_Brainstorm_ClassDesign", test);
@@ -213,7 +218,7 @@
     cAddTestSuite t("cTestSettings_UnitTest_HelloWorld", test);
   }
 
-  // }}}1
+/* Physical Link. {{{1 */
   /*
   This function does nothing;
   but if the compiler sees that this function is called, then the

Modified: extras/source/tools/cTestDriver.cpp
===================================================================
--- extras/source/tools/cTestDriver.cpp	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/tools/cTestDriver.cpp	2007-01-28 06:16:57 UTC (rev 1224)
@@ -1,6 +1,5 @@
 #include "cTestDriver.h"
 
-#include "cStringList.h"
 #include "cTestLib.h"
 
 #include <fstream>
@@ -53,8 +52,40 @@
   }
   cout << "****** Done running all known tests." << endl;
 }
+void cTestDriver::TestAll(cTestSettings &settings){
+  cout << "------ Running all known tests ..." << endl;
+  {
+    /* Get a list of names of known test suites. */
+    tList<cString> name_list;
+    tList<Testrunner> test_list;
+    cTestLib::getLib().asLists(name_list, test_list);
+    /* Iterate through list of test suite names. */
+    tListIterator<cString> list_it(name_list);
+    while(list_it.Next() != 0) {
+      /* Run each test suite by name. */
+      cout << "--- '" << *list_it.Get() << "' : testing ..." << endl;
+      cTestLib::getLib().run(*list_it.Get());
+      cout << "*** '" << *list_it.Get() << "' : done." << endl;
+    }
+  }
+  /* Settings */
+  {
+    /* Get a list of names of known test suites. */
+    tList<cString> name_list;
+    tList<TestrunnerWithSettings> test_list;
+    cTestLib::getLib().asLists(name_list, test_list);
+    /* Iterate through list of test suite names. */
+    tListIterator<cString> list_it(name_list);
+    while(list_it.Next() != 0) {
+      /* Run each test suite by name. */
+      cout << "--- '" << *list_it.Get() << "' : testing ..." << endl;
+      cTestLib::getLib().run(*list_it.Get(), settings);
+      cout << "*** '" << *list_it.Get() << "' : done." << endl;
+    }
+  }
+  cout << "****** Done running all known tests." << endl;
+}
 
-
 int cTestDriver::Tests(cStringList &args){
   /* Whether to be verbose (enable cout) or quiet (disable cout). */
   cout << "...... Being verbose by default." << endl;
@@ -67,7 +98,9 @@
 
   while(args.GetSize() > 0){
     cString test_name(args.Pop());
-    if(test_name.Find("Enable_") == 0){
+    if(m_test_settings.ParseSettingString(test_name)){
+      // Do nothing extra...
+    } else if(test_name.Find("Enable_") == 0){
       test_name.ClipFront(7);
       cStringList attributes(test_name, '_');
       while(attributes.GetSize() > 0){
@@ -105,13 +138,15 @@
       */
       did_already_test_something = true;
       TestAll(m_test_attributes);
+      TestAll(m_test_settings);
     } else {
       /*
       Look for and try to run a test suite by name.
       */
       did_already_test_something = true;
       cout << "--- '" << test_name << "' : testing ..." << endl;
-      cTestLib::getLib().tryRun(test_name, m_test_attributes);
+      //cTestLib::getLib().tryRun(test_name, m_test_attributes);
+      cTestLib::getLib().tryRun(test_name, m_test_settings);
       cout << "*** '" << test_name << "' : done." << endl;
     }
   }
@@ -120,6 +155,7 @@
     Test everything if nothing has been tested yet.
     */
     TestAll(m_test_attributes);
+    TestAll(m_test_settings);
   }
   cout.flush();
   clog.flush();
@@ -142,7 +178,11 @@
 */
 int cTestDriver::Tests(int argc, char * argv[]){
   cStringList sl;
-  for(int i=1; i<argc; i++){ sl.PushRear(argv[i]); }
+
+  cStringList non_test_settings;
+  for(int i=1; i<argc; i++){
+    sl.PushRear(argv[i]);
+  }
   return Tests(sl);
 }
 

Modified: extras/source/tools/cTestDriver.h
===================================================================
--- extras/source/tools/cTestDriver.h	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/tools/cTestDriver.h	2007-01-28 06:16:57 UTC (rev 1224)
@@ -5,14 +5,20 @@
 #include "cStringList.h"
 #endif
 
+#ifndef cTestSettings_h
+#include "cTestSettings.h"
+#endif
+
 class cTestDriver {
 protected:
   cStringList m_test_attributes;
+  cTestSettings m_test_settings;
 public:
   int & testErrors(void);
   void resetTestErrors(void);
   int reportErrors(void);
   void TestAll(cStringList &attrs);
+  void TestAll(cTestSettings &settings);
   int Tests(cStringList &args);
   int Tests(int argc, char * argv[]);
 };

Modified: extras/source/tools/cTestLib.cpp
===================================================================
--- extras/source/tools/cTestLib.cpp	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/tools/cTestLib.cpp	2007-01-28 06:16:57 UTC (rev 1224)
@@ -20,16 +20,30 @@
   m_test_runners_with_attributes.Add(key, test_runner);
   return true;
 }
+bool cTestLib::reg(const cString &key, TestrunnerWithSettings test_runner){
+  TestrunnerWithSettings tr;
+  if(m_test_runners_with_settings.Find(key, tr)) { return false; }
+  m_test_runners_with_settings.Add(key, test_runner);
+  return true;
+}
 
 bool cTestLib::unreg(const cString &key){
-  Testrunner tr;
-  TestrunnerWithAttrs tra;
+  Testrunner tr(0);
+  TestrunnerWithAttrs tra(0);
+  TestrunnerWithSettings trs(0);
   if(m_test_runners.Find(key, tr)){ tr = m_test_runners.Remove(key); }
   if(m_test_runners_with_attributes.Find(key, tra)){ tra = m_test_runners_with_attributes.Remove(key); }
-  return (tr || tra);
+  if(m_test_runners_with_settings.Find(key, trs)){ trs = m_test_runners_with_settings.Remove(key); }
+  return (tr || tra || trs);
 }
 bool cTestLib::supports(const cString &key){
-  return (m_test_runners.HasEntry(key) || m_test_runners_with_attributes.HasEntry(key));
+  return (
+    m_test_runners.HasEntry(key)
+    ||
+    m_test_runners_with_attributes.HasEntry(key)
+    ||
+    m_test_runners_with_settings.HasEntry(key)
+  );
 }
 
 void cTestLib::run(cString key){
@@ -40,11 +54,18 @@
 }
 /* XXX Needs tests relating to Attributes -- @kgn */
 void cTestLib::run(cString key, const cStringList &attributes){
-  TestrunnerWithAttrs tra;
+  TestrunnerWithAttrs tr;
 
-  if(m_test_runners_with_attributes.Find(key, tra)) tra(attributes);
+  if(m_test_runners_with_attributes.Find(key, tr)) tr(attributes);
   else ERROR(cString("error loading test runner by key '") + key + "'");
 }
+/* XXX Needs tests relating to Settings -- @kgn */
+void cTestLib::run(cString key, cTestSettings &settings){
+  TestrunnerWithSettings tr;
+
+  if(m_test_runners_with_settings.Find(key, tr)) tr(settings);
+  else ERROR(cString("error loading test runner by key '") + key + "'");
+}
 /* XXX Needs tests relating to Attributes -- @kgn */
 void cTestLib::tryRun(cString key, const cStringList &attributes){
   if(supports(key)){
@@ -95,6 +116,56 @@
     }
   }
 }
+/* XXX Needs tests relating to Settings -- @kgn */
+void cTestLib::tryRun(cString key, cTestSettings &settings){
+  if(supports(key)){
+    if(m_test_runners.HasEntry(key)){
+      run(key);
+    } else if(m_test_runners_with_settings.HasEntry(key)){
+      run(key, settings);
+    }
+  } else {
+    bool found_match = false;
+    {
+      tList<cString> keys;
+      tList<Testrunner> runners;
+
+      asLists(keys, runners);
+      tListIterator<cString> list_it(keys);
+
+      while (list_it.Next() != 0) {
+        cString test_key(*list_it.Get());
+        if(0 <= test_key.Find(key)){
+          found_match = true;
+          cout << "--- '" << test_key << "' (matches '" << key << "') : testing ..." << endl;
+          /* FIXME : convert to no-args but key. @kgn */
+          run(test_key);
+          cout << "*** '" << test_key << "' (matches '" << key << "') : done." << endl;
+        }
+      }
+    }
+    {
+      tList<cString> keys;
+      tList<TestrunnerWithSettings> runners;
+
+      asLists(keys, runners);
+      tListIterator<cString> list_it(keys);
+
+      while (list_it.Next() != 0) {
+        cString test_key(*list_it.Get());
+        if(0 <= test_key.Find(key)){
+          found_match = true;
+          cout << "--- '" << test_key << "' (matches '" << key << "') : testing ..." << endl;
+          run(test_key, settings);
+          cout << "*** '" << test_key << "' (matches '" << key << "') : done." << endl;
+        }
+      }
+    }
+    if(!found_match){
+      ERROR(cString("key '") + key + "' not supported");
+    }
+  }
+}
 void cTestLib::asLists(tList<cString> & name_list, tList<Testrunner> & value_list){
   m_test_runners.AsLists(name_list, value_list);
 }
@@ -102,6 +173,10 @@
 void cTestLib::asLists(tList<cString> & name_list, tList<TestrunnerWithAttrs> & value_list){
   m_test_runners_with_attributes.AsLists(name_list, value_list);
 }
+/* XXX Needs tests relating to Settings -- @kgn */
+void cTestLib::asLists(tList<cString> & name_list, tList<TestrunnerWithSettings> & value_list){
+  m_test_runners_with_settings.AsLists(name_list, value_list);
+}
 
 cTestLib &cTestLib::getLib(){
   static cTestLib s_test_lib;
@@ -119,6 +194,11 @@
     ERROR(cString("error adding test runner by '") + key + "'");
   }
 }
+void addTestSuite(const cString &key, TestrunnerWithSettings test_runner){
+  if(!cTestLib::getLib().reg(key, test_runner)){
+    ERROR(cString("error adding test runner by '") + key + "'");
+  }
+}
 
 cAddTestSuite::cAddTestSuite(const cString &key, Testrunner test_runner){
   addTestSuite(key, test_runner);
@@ -126,3 +206,6 @@
 cAddTestSuite::cAddTestSuite(const cString &key, TestrunnerWithAttrs test_runner){
   addTestSuite(key, test_runner);
 }
+cAddTestSuite::cAddTestSuite(const cString &key, TestrunnerWithSettings test_runner){
+  addTestSuite(key, test_runner);
+}

Modified: extras/source/tools/cTestLib.h
===================================================================
--- extras/source/tools/cTestLib.h	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/tools/cTestLib.h	2007-01-28 06:16:57 UTC (rev 1224)
@@ -4,6 +4,9 @@
 #ifndef cStringList_h
 #include "cStringList.h"
 #endif
+#ifndef cTestSettings_h
+#include "cTestSettings.h"
+#endif
 #ifndef lightweight_test_h
 #include "lightweight_test.h"
 #endif
@@ -13,22 +16,28 @@
 
 typedef void(*Testrunner)(void);
 typedef void(*TestrunnerWithAttrs)(const cStringList &);
+typedef void(*TestrunnerWithSettings)(cTestSettings &);
 
 class cTestLib {
 protected:
   tDictionary<Testrunner> m_test_runners;
   tDictionary<TestrunnerWithAttrs> m_test_runners_with_attributes;
+  tDictionary<TestrunnerWithSettings> m_test_runners_with_settings;
 public:
   virtual ~cTestLib(){}
   bool reg(const cString &key, Testrunner test_runner);
   bool reg(const cString &key, TestrunnerWithAttrs test_runner);
+  bool reg(const cString &key, TestrunnerWithSettings test_runner);
   bool unreg(const cString &key);
   bool supports(const cString &key);
   void asLists(tList<cString> & name_list, tList<Testrunner> & value_list);
   void asLists(tList<cString> & name_list, tList<TestrunnerWithAttrs> & value_list);
+  void asLists(tList<cString> & name_list, tList<TestrunnerWithSettings> & value_list);
   void tryRun(cString key, const cStringList &attributes);
+  void tryRun(cString key, cTestSettings &settings);
   void run(cString key);
   void run(cString key, const cStringList &attributes);
+  void run(cString key, cTestSettings &settings);
 public:
   static cTestLib &getLib();
 };
@@ -41,8 +50,10 @@
 public:
   cAddTestSuite(const cString &key, Testrunner test_runner);
   cAddTestSuite(const cString &key, TestrunnerWithAttrs test_runner);
+  cAddTestSuite(const cString &key, TestrunnerWithSettings test_runner);
 };
 void addTestSuite(const cString &key, Testrunner test_runner);
 void addTestSuite(const cString &key, TestrunnerWithAttrs test_runner);
+void addTestSuite(const cString &key, TestrunnerWithSettings test_runner);
 
 #endif

Modified: extras/source/tools/cTestSettings.cpp
===================================================================
--- extras/source/tools/cTestSettings.cpp	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/tools/cTestSettings.cpp	2007-01-28 06:16:57 UTC (rev 1224)
@@ -18,6 +18,17 @@
   }
 }
 
+void cTestSettings::Clear(){
+  tList<cString> name_list;
+  tList<cString> settings_list;
+  m_settings_dict.AsLists(name_list, settings_list);
+  /* Iterate through list of setting names. */
+  tListIterator<cString> list_it(name_list);
+  while(list_it.Next() != 0) {
+    m_settings_dict.Remove(*list_it.Get());
+  }
+}
+
 int cTestSettings::Size(){
   return m_settings_dict.GetSize();
 }

Modified: extras/source/tools/cTestSettings.h
===================================================================
--- extras/source/tools/cTestSettings.h	2007-01-28 06:16:54 UTC (rev 1223)
+++ extras/source/tools/cTestSettings.h	2007-01-28 06:16:57 UTC (rev 1224)
@@ -15,6 +15,8 @@
   void Set(const cString& name, const cString &data);
   cString Unset(const cString& name);
 
+  void Clear();
+
   int Size();
   bool HasSetting(const cString& name) const;
 




More information about the Avida-cvs mailing list