aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unitsuite.cpp47
-rw-r--r--src/unitsuite.h8
2 files changed, 51 insertions, 4 deletions
diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp
index 711b9b5..7d8cc2a 100644
--- a/src/unitsuite.cpp
+++ b/src/unitsuite.cpp
@@ -8,6 +8,8 @@
8#include "bu/unitsuite.h" 8#include "bu/unitsuite.h"
9#include "bu/file.h" 9#include "bu/file.h"
10#include "bu/sio.h" 10#include "bu/sio.h"
11#include "bu/optparser.h"
12#include <stdlib.h>
11 13
12using namespace Bu; 14using namespace Bu;
13 15
@@ -30,8 +32,17 @@ Bu::UnitSuite::~UnitSuite()
30} 32}
31 33
32// Argument handling is coming soon, I promise. 34// Argument handling is coming soon, I promise.
33int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) 35int Bu::UnitSuite::run( int argc, char *argv[] )
34{ 36{
37 bool bCleanup = true;
38 OptParser p;
39 p.addOption( Bu::slot( this, &Bu::UnitSuite::onListCases ), 'l', "list",
40 "List available test cases." );
41 p.addOption( bCleanup, "no-cleanup", "Don't erase temp files.");
42 p.setOverride( "no-cleanup", "false" );
43 p.addHelpOption();
44 p.parse( argc, argv );
45
35 int iEPass = 0; 46 int iEPass = 0;
36 int iEFail = 0; 47 int iEFail = 0;
37 int iUPass = 0; 48 int iUPass = 0;
@@ -133,9 +144,12 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
133 if( iUPass == 0 && iUFail == 0 ) 144 if( iUPass == 0 && iUFail == 0 )
134 sio << "\tNothing unexpected." << sio.nl << sio.nl; 145 sio << "\tNothing unexpected." << sio.nl << sio.nl;
135 146
136 for( StrList::iterator i = lFileCleanup.begin(); i; i++ ) 147 if( bCleanup )
137 { 148 {
138 unlink( (*i).getStr() ); 149 for( StrList::iterator i = lFileCleanup.begin(); i; i++ )
150 {
151 unlink( (*i).getStr() );
152 }
139 } 153 }
140 154
141 return 0; 155 return 0;
@@ -171,3 +185,30 @@ void Bu::UnitSuite::setName( const FString &sName )
171 sSuiteName = sName; 185 sSuiteName = sName;
172} 186}
173 187
188int Bu::UnitSuite::onListCases( StrArray aParam )
189{
190 sio << "Test cases:" << sio.nl;
191 for( TestList::iterator i = lTests.begin(); i; i++ )
192 {
193 sio << "\t- " << Fmt( iNameWidth, 10, Fmt::Left ) << (*i).sName << " "
194 << (*i).eExpect << sio.nl;
195 }
196 sio << sio.nl;
197 exit( 0 );
198 return 0;
199}
200
201Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e )
202{
203 switch( e )
204 {
205 case Bu::UnitSuite::expectPass:
206 return f << "expect pass";
207
208 case Bu::UnitSuite::expectFail:
209 return f << "expect fail";
210 }
211
212 return f << "**error**";
213}
214
diff --git a/src/unitsuite.h b/src/unitsuite.h
index 74aac6f..ddd3835 100644
--- a/src/unitsuite.h
+++ b/src/unitsuite.h
@@ -10,8 +10,9 @@
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include "bu/list.h" 12#include "bu/list.h"
13#include "fstring.h" 13#include "bu/fstring.h"
14#include "bu/file.h" 14#include "bu/file.h"
15#include "bu/array.h"
15 16
16namespace Bu 17namespace Bu
17{ 18{
@@ -96,6 +97,9 @@ namespace Bu
96 void setName( const FString &sName ); 97 void setName( const FString &sName );
97 98
98 private: 99 private:
100 int onListCases( Bu::Array<Bu::FString> aParam );
101
102 private:
99 typedef struct TestInfo 103 typedef struct TestInfo
100 { 104 {
101 FString sName; 105 FString sName;
@@ -113,6 +117,8 @@ namespace Bu
113 StrList lFileCleanup; 117 StrList lFileCleanup;
114 int iNameWidth; 118 int iNameWidth;
115 }; 119 };
120
121Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e );
116} 122}
117 123
118#define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn ) 124#define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn )