From b6e100b94b12f3f92ec025dc2363eaf7c0ee6662 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 10 Apr 2007 16:02:07 +0000 Subject: Well, we've got the basis of a workable unit test harness thing. There should be a few more add-ons to it, but it works just fine, and eventually it should cover command line options and creating logs, and possibly even provide output functionality so that output from tests can be logged and kept track of well. --- src/unitsuite.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/unitsuite.cpp (limited to 'src/unitsuite.cpp') diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp new file mode 100644 index 0000000..2a28eb5 --- /dev/null +++ b/src/unitsuite.cpp @@ -0,0 +1,67 @@ +#include "unitsuite.h" + +Bu::UnitSuite::UnitSuite() +{ +} + +Bu::UnitSuite::~UnitSuite() +{ +} + +int Bu::UnitSuite::run( int argc, char *argv[] ) +{ + for( TestList::iterator i = lTests.begin(); i != lTests.end(); i++ ) + { + printf("%s: ", i->sName.getStr() ); + fflush( stdout ); + try + { + (this->*(i->fTest))(); + printf("passed.\n"); + } + catch( Failed &e ) + { + if( e.bFile ) + { + printf("unitTest(%s) failed. (%s:%d)\n", + e.str.getStr(), + e.sFile.getStr(), + e.nLine + ); + } + else + { + printf("unitTest(%s) failed.\n", + e.str.getStr() + ); + } + } + catch( ... ) + { + printf("failed with external exception.\n"); + } + } + + return 0; +} + +void Bu::UnitSuite::add( Test fTest, Bu::FString sName ) +{ + TestInfo ti; + ti.sName = sName; + long index = ti.sName.rfind("::"); + if( index != -1 ) + { + FString tmp = sSuiteName; + tmp += ti.sName.getStr()+index; + ti.sName = tmp; + } + ti.fTest = fTest; + lTests.push_back( ti ); +} + +void Bu::UnitSuite::setName( const FString &sName ) +{ + sSuiteName = sName; +} + -- cgit v1.2.3