[Avida-SVN] r1215 - in extras: . source/testsuites
avidaedward at myxo.css.msu.edu
avidaedward at myxo.css.msu.edu
Sat Jan 27 22:16:25 PST 2007
Author: avidaedward
Date: 2007-01-28 01:16:25 -0500 (Sun, 28 Jan 2007)
New Revision: 1215
Modified:
extras/
extras/source/testsuites/nTestDriver.cpp
Log:
r1181 at clearly: kaben | 2006-12-24 23:48:14 -0500
Tests of cTestDriver now use cConsoleCatcher to detect expected error
output.
Property changes on: extras
___________________________________________________________________
Name: svk:merge
- 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1180
+ 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1181
Modified: extras/source/testsuites/nTestDriver.cpp
===================================================================
--- extras/source/testsuites/nTestDriver.cpp 2007-01-28 06:16:22 UTC (rev 1214)
+++ extras/source/testsuites/nTestDriver.cpp 2007-01-28 06:16:25 UTC (rev 1215)
@@ -1,17 +1,13 @@
#include "cTestDriver.h"
+#include "cConsoleCatcher.h"
#include "cTestLib.h"
+
#include <iostream>
-#include <assert.h>
-#include <signal.h>
+
using namespace std;
namespace nTestDriver {
- cString classname(
- cString("cTestDriver")
- + "_"
- );
-
namespace Brainstorm_HelloWorld {
void test(const cStringList &attrs){
if(!attrs.HasString("HelloWorld")){
@@ -23,7 +19,7 @@
TEST(true);
TEST(false);
}
- cAddTestSuite t(classname + "Brainstorm_HelloWorld", test);
+ cAddTestSuite t("cTestDriver_Brainstorm_HelloWorld", test);
}
namespace FunctionalTest_Attributes {
@@ -36,25 +32,25 @@
cTestDriver td;
cTestLib::getLib().reg(
- classname + "FunctionalTest_Attributes_subtest",
+ "cTestDriver_FunctionalTest_Attributes_subtest",
testrunner
);
args.Clear();
args.PushRear("Enable_TestAttribute");
- args.PushRear(classname + "FunctionalTest_Attributes_subtest");
+ args.PushRear("cTestDriver_FunctionalTest_Attributes_subtest");
td.Tests(args);
TEST(test_attribute_enabled);
args.Clear();
args.PushRear("Disable_TestAttribute");
- args.PushRear(classname + "FunctionalTest_Attributes_subtest");
+ args.PushRear("cTestDriver_FunctionalTest_Attributes_subtest");
td.Tests(args);
TEST(!test_attribute_enabled);
- cTestLib::getLib().unreg(classname + "FunctionalTest_Attributes_subtest");
+ cTestLib::getLib().unreg("cTestDriver_FunctionalTest_Attributes_subtest");
}
- cAddTestSuite t(classname + "FunctionalTest_Attributes", test);
+ cAddTestSuite t("cTestDriver_FunctionalTest_Attributes", test);
}
namespace FunctionalTest_AlteringErrorCount {
@@ -62,20 +58,27 @@
int original_error_count, new_error_count;
original_error_count = test_errors();
- cerr << "... (the following test fails on purpose; saving error count of ";
- cerr << original_error_count << ") ..." << endl;
- bool fail_on_purpose = false;
- TEST(fail_on_purpose);
- new_error_count = test_errors();
- TEST(original_error_count < new_error_count);
- --test_errors();
- new_error_count = test_errors();
- test_errors() = original_error_count;
- cerr << "... (error count restored to ";
- cerr << original_error_count << ") ..." << endl;
- TEST(original_error_count == new_error_count);
+
+ cConsoleCatcher cc;
+ cc.Capture(cerr);
+ {
+ cerr << "... (the following test fails on purpose; saving error count of ";
+ cerr << original_error_count << ") ..." << endl;
+ bool fail_on_purpose = false;
+ TEST(fail_on_purpose);
+ new_error_count = test_errors();
+ TEST(original_error_count < new_error_count);
+ --test_errors();
+ new_error_count = test_errors();
+ test_errors() = original_error_count;
+ cerr << "... (error count restored to ";
+ cerr << original_error_count << ") ..." << endl;
+ }
+ cString captured(cc.Release());
+
+ TEST(0 <= captured.Find("test 'fail_on_purpose' failed"));
}
- cAddTestSuite t(classname + "FunctionalTest_AlteringErrorCount", test);
+ cAddTestSuite t("cTestDriver_FunctionalTest_AlteringErrorCount", test);
}
namespace Regression_SomeTestSuitesNotProperlyMatched {
@@ -102,39 +105,48 @@
/* Make sure subtests aren't installed. */
t1_called = t2_called = t3_called = t4_called = false;
args.Clear();
- args.Push(classname + "RegressionSubtest");
+ args.Push("cTestDriver_RegressionSubtest");
saved_error_count = td.testErrors();
- cerr << "... ('key not supported' error expected; saving error count of ";
- cerr << saved_error_count << ") ..." << endl;
- td.Tests(args);
- td.testErrors() = saved_error_count;
- cerr << "... (error count restored to ";
- cerr << saved_error_count << ") ..." << endl;
+
+ cConsoleCatcher cc;
+ cc.Capture(cerr);
+ {
+ cout << "... ('key not supported' error expected; saving error count of ";
+ cout << saved_error_count << ") ..." << endl;
+ td.Tests(args);
+ td.testErrors() = saved_error_count;
+ cout << "... (error count restored to ";
+ cout << saved_error_count << ") ..." << endl;
+ }
+ cString captured = cc.Release();
+
+ TEST(0 <= captured.Find("key 'cTestDriver_RegressionSubtest' not supported"));
TEST((!t1_called) && (!t2_called) && (!t3_called) && (!t4_called));
/* Install subtests. */
cTestLib::getLib().reg(
- classname + "RegressionSubtest_" + "t1WithAttrs",
+ "cTestDriver_RegressionSubtest_t1WithAttrs",
t1WithAttrs
);
cTestLib::getLib().reg(
- classname + "RegressionSubtest_" + "t2WithAttrs",
+ "cTestDriver_RegressionSubtest_t2WithAttrs",
t2WithAttrs
);
cTestLib::getLib().reg(
- classname + "RegressionSubtest_" + "t3WithoutAttrs",
+ "cTestDriver_RegressionSubtest_t3WithoutAttrs",
t3WithoutAttrs
);
cTestLib::getLib().reg(
- classname + "RegressionSubtest_" + "t4WithoutAttrs",
+ "cTestDriver_RegressionSubtest_t4WithoutAttrs",
t4WithoutAttrs
);
/* Make sure subtests are all called. */
t1_called = t2_called = t3_called = t4_called = false;
args.Clear();
- args.Push(classname + "RegressionSubtest");
+ args.Push("cTestDriver_RegressionSubtest");
saved_error_count = td.testErrors();
+
cout << "... (saving error count of ";
cout << saved_error_count << ") ..." << endl;
td.Tests(args);
@@ -147,28 +159,34 @@
TEST(t4_called);
/* Uninstall subtests. */
- cTestLib::getLib().unreg(classname + "RegressionSubtest_" + "t1WithAttrs");
- cTestLib::getLib().unreg(classname + "RegressionSubtest_" + "t2WithAttrs");
- cTestLib::getLib().unreg(classname + "RegressionSubtest_" + "t3WithoutAttrs");
- cTestLib::getLib().unreg(classname + "RegressionSubtest_" + "t4WithoutAttrs");
+ cTestLib::getLib().unreg("cTestDriver_RegressionSubtest_t1WithAttrs");
+ cTestLib::getLib().unreg("cTestDriver_RegressionSubtest_t2WithAttrs");
+ cTestLib::getLib().unreg("cTestDriver_RegressionSubtest_t3WithoutAttrs");
+ cTestLib::getLib().unreg("cTestDriver_RegressionSubtest_t4WithoutAttrs");
/* Make sure subtests aren't installed. */
t1_called = t2_called = t3_called = t4_called = false;
args.Clear();
- args.Push(classname + "RegressionSubtest");
+ args.Push("cTestDriver_RegressionSubtest");
saved_error_count = td.testErrors();
- cerr << "... ('key not supported' error expected; saving error count of ";
- cerr << saved_error_count << ") ..." << endl;
- td.Tests(args);
- td.testErrors() = saved_error_count;
- cerr << "... (error count restored to ";
- cerr << saved_error_count << ") ..." << endl;
+ cc.Capture(cerr);
+ {
+ cout << "... ('key not supported' error expected; saving error count of ";
+ cout << saved_error_count << ") ..." << endl;
+ td.Tests(args);
+ td.testErrors() = saved_error_count;
+ cout << "... (error count restored to ";
+ cout << saved_error_count << ") ..." << endl;
+ }
+ captured = cc.Release();
+ TEST(0 <= captured.Find("key 'cTestDriver_RegressionSubtest' not supported"));
+
TEST(!t1_called);
TEST(!t2_called);
TEST(!t3_called);
TEST(!t4_called);
}
- cAddTestSuite t(classname + "Regression_SomeTestSuitesNotProperlyMatched", test);
+ cAddTestSuite t("cTestDriver_Regression_SomeTestSuitesNotProperlyMatched", test);
}
namespace UnitTest_HelloWorld {
@@ -182,7 +200,7 @@
TEST(true);
TEST(false);
}
- cAddTestSuite t(classname + "UnitTest_HelloWorld", test);
+ cAddTestSuite t("cTestDriver_UnitTest_HelloWorld", test);
}
namespace UnitTest_RegisterAndUnregisterAndSupports {
@@ -190,36 +208,36 @@
void t3WithoutAttrs(){ }
void test(const cStringList &attrs){
TEST(!cTestLib::getLib().supports(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t1WithAttrs"));
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs"));
TEST(!cTestLib::getLib().supports(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t3WithoutAttrs"));
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs"));
/* Install subtests. */
cTestLib::getLib().reg(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t1WithAttrs",
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs",
t1WithAttrs
);
cTestLib::getLib().reg(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t3WithoutAttrs",
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs",
t3WithoutAttrs
);
TEST(cTestLib::getLib().supports(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t1WithAttrs"));
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs"));
TEST(cTestLib::getLib().supports(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t3WithoutAttrs"));
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs"));
cTestLib::getLib().unreg(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t1WithAttrs");
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs");
cTestLib::getLib().unreg(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t3WithoutAttrs");
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs");
TEST(!cTestLib::getLib().supports(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t1WithAttrs"));
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t1WithAttrs"));
TEST(!cTestLib::getLib().supports(
- classname + "UnitTest_RegisterAndUnregisterAndSupports_" + "t3WithoutAttrs"));
+ "cTestDriver_UnitTest_RegisterAndUnregisterAndSupports_t3WithoutAttrs"));
}
- cAddTestSuite t(classname + "RegisterAndUnregisterAndSupports", test);
+ cAddTestSuite t("cTestDriver_RegisterAndUnregisterAndSupports", test);
}
namespace UnitTest_TestErrors {
@@ -242,7 +260,7 @@
td.testErrors() = original_error_count;
TEST(new_error_count == 2);
}
- cAddTestSuite t(classname + "UnitTest_TestErrors", test);
+ cAddTestSuite t("cTestDriver_UnitTest_TestErrors", test);
}
namespace UnitTest_ResetTestErrors {
@@ -267,7 +285,7 @@
td.testErrors() = original_error_count;
TEST(new_error_count == 0);
}
- cAddTestSuite t(classname + "UnitTest_ResetTestErrors", test);
+ cAddTestSuite t("cTestDriver_UnitTest_ResetTestErrors", test);
}
/*
More information about the Avida-cvs
mailing list