From da1de5cdb5c42ce811a66d377789e585042b98c7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 14 Apr 2012 18:04:52 +0000 Subject: Added support for running subsets of unit tests to Bu::UnitSuite, now just list the names of the tests you want to run on the command line. Also, fixed some minor issues in two of the test suites. --- src/stable/unitsuite.cpp | 20 +++++++++++++++++++- src/stable/unitsuite.h | 4 ++++ src/unit/file.unit | 4 ++++ src/unit/variant.unit | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/stable/unitsuite.cpp b/src/stable/unitsuite.cpp index db930a4..e508c6f 100644 --- a/src/stable/unitsuite.cpp +++ b/src/stable/unitsuite.cpp @@ -32,7 +32,6 @@ Bu::UnitSuite::~UnitSuite() { } -// Argument handling is coming soon, I promise. int Bu::UnitSuite::run( int argc, char *argv[] ) { bool bCleanup = true; @@ -41,9 +40,22 @@ int Bu::UnitSuite::run( int argc, char *argv[] ) "List available test cases." ); p.addOption( bCleanup, "no-cleanup", "Don't erase temp files."); p.setOverride( "no-cleanup", false ); + p.setNonOption( Bu::slot( this, &Bu::UnitSuite::onAddTest ) ); p.addHelpOption(); p.parse( argc, argv ); + if( !hSelTests.isEmpty() ) + { + TestList lSub; + for( TestList::iterator i = lTests.begin(); i != lTests.end(); i++ ) + { + if( hSelTests.has( (*i).sName ) ) + lSub.append( *i ); + } + + lTests = lSub; + } + int iEPass = 0; int iEFail = 0; int iUPass = 0; @@ -239,6 +251,12 @@ int Bu::UnitSuite::onListCases( StrArray ) return 0; } +int Bu::UnitSuite::onAddTest( StrArray aParam ) +{ + hSelTests.insert( aParam[0], true ); + return 0; +} + Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ) { switch( e ) diff --git a/src/stable/unitsuite.h b/src/stable/unitsuite.h index 2250a4d..6915fb4 100644 --- a/src/stable/unitsuite.h +++ b/src/stable/unitsuite.h @@ -13,6 +13,7 @@ #include "bu/string.h" #include "bu/file.h" #include "bu/array.h" +#include "bu/hash.h" namespace Bu { @@ -103,6 +104,7 @@ namespace Bu private: int onListCases( Bu::Array aParam ); + int onAddTest( Bu::Array aParam ); private: typedef struct TestInfo @@ -124,6 +126,8 @@ namespace Bu int iStepCount; int iProgress; time_t tLastUpdate; + + Bu::Hash hSelTests; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ); diff --git a/src/unit/file.unit b/src/unit/file.unit index fb04e57..efca4f1 100644 --- a/src/unit/file.unit +++ b/src/unit/file.unit @@ -48,7 +48,11 @@ suite File if( s < 50 ) { unitTest( total == 256 ); + unitTest( sf.isEos() == false ); + unitTest( sf.read( buf, 1 ) == 0 ); unitTest( sf.isEos() == true ); + // EOS is only set when an attempt to read past the end of + // the stream is made, not when a short block is returned. break; } } diff --git a/src/unit/variant.unit b/src/unit/variant.unit index 4fd5e26..53abdc0 100644 --- a/src/unit/variant.unit +++ b/src/unit/variant.unit @@ -55,7 +55,7 @@ suite Variant arg( mkastring().getStr() ). arg( i1, Fmt(2).fill('0') ). arg( i2, Fmt(2).fill('0') ); - sio << sio.nl << out << sio.nl; + // sio << sio.nl << out << sio.nl; unitTest( out == "hello-stuff-32-00.odp" ); } } -- cgit v1.2.3