aboutsummaryrefslogtreecommitdiff
path: root/src/unitsuite.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-07 16:48:35 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-07 16:48:35 +0000
commitaba7c45c2c69d402d1b6fc427cde5bfa4661a0e1 (patch)
tree5b3849a8190cdb8742b1f43f4b8bbb43c73ababe /src/unitsuite.cpp
parent45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (diff)
downloadlibbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.tar.gz
libbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.tar.bz2
libbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.tar.xz
libbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.zip
Corrected a couple of places where std:: classes were being used and shouldn't
have been. Also made the Unit tests actually use expected values, so you can mark a test as "expected fail" and it'll know. It also prints out cute reports at the end of each run.
Diffstat (limited to 'src/unitsuite.cpp')
-rw-r--r--src/unitsuite.cpp46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp
index b61baa5..7421496 100644
--- a/src/unitsuite.cpp
+++ b/src/unitsuite.cpp
@@ -24,6 +24,10 @@ Bu::UnitSuite::~UnitSuite()
24// Argument handling is coming soon, I promise. 24// Argument handling is coming soon, I promise.
25int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) 25int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
26{ 26{
27 int iEPass = 0;
28 int iEFail = 0;
29 int iUPass = 0;
30 int iUFail = 0;
27 for( TestList::iterator i = lTests.begin(); i != lTests.end(); i++ ) 31 for( TestList::iterator i = lTests.begin(); i != lTests.end(); i++ )
28 { 32 {
29 printf("%s: ", i->sName.getStr() ); 33 printf("%s: ", i->sName.getStr() );
@@ -31,13 +35,22 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
31 try 35 try
32 { 36 {
33 (this->*(i->fTest))(); 37 (this->*(i->fTest))();
34 printf("passed.\n"); 38 switch( i->eExpect )
39 {
40 case expectPass: printf("expected pass.\n"); iEPass++; break;
41 case expectFail: printf("unexpected pass.\n"); iUPass++; break;
42 }
35 } 43 }
36 catch( Failed &e ) 44 catch( Failed &e )
37 { 45 {
46 switch( i->eExpect )
47 {
48 case expectPass: printf("unexpected "); iUFail++; break;
49 case expectFail: printf("expected "); iEFail++; break;
50 }
38 if( e.bFile ) 51 if( e.bFile )
39 { 52 {
40 printf("unitTest(%s) failed. (%s:%d)\n", 53 printf("fail in unitTest(%s). (%s:%d)\n",
41 e.str.getStr(), 54 e.str.getStr(),
42 e.sFile.getStr(), 55 e.sFile.getStr(),
43 e.nLine 56 e.nLine
@@ -45,7 +58,7 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
45 } 58 }
46 else 59 else
47 { 60 {
48 printf("unitTest(%s) failed.\n", 61 printf("fail in unitTest(%s).\n",
49 e.str.getStr() 62 e.str.getStr()
50 ); 63 );
51 } 64 }
@@ -55,20 +68,40 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
55 } 68 }
56 catch( std::exception &e ) 69 catch( std::exception &e )
57 { 70 {
58 printf("failed with unknown exception. what: %s\n", e.what() ); 71 switch( i->eExpect )
72 {
73 case expectPass: printf("unexpected "); iUFail++; break;
74 case expectFail: printf("expected "); iEFail++; break;
75 }
76 printf("fail with unknown exception. what: %s\n", e.what() );
59 77
60 if( (iOptions & optStopOnError) ) 78 if( (iOptions & optStopOnError) )
61 return 0; 79 return 0;
62 } 80 }
63 catch( ... ) 81 catch( ... )
64 { 82 {
65 printf("failed with external exception.\n"); 83 switch( i->eExpect )
84 {
85 case expectPass: printf("unexpected "); iUFail++; break;
86 case expectFail: printf("expected "); iEFail++; break;
87 }
88 printf("fail with external exception.\n");
66 89
67 if( (iOptions & optStopOnError) ) 90 if( (iOptions & optStopOnError) )
68 return 0; 91 return 0;
69 } 92 }
70 } 93 }
71 94
95 printf("\nReport:\n"
96 "\tTotal tests run: %ld\n"
97 "\tExpected passes: %d\n"
98 "\tExpected failures: %d\n"
99 "\tUnexpected passes: %d\n"
100 "\tUnexpected failures: %d\n\n",
101 lTests.getSize(), iEPass, iEFail, iUPass, iUFail );
102 if( iUPass == 0 && iUFail == 0 )
103 printf("\tNothing unexpected.\n\n");
104
72 return 0; 105 return 0;
73} 106}
74 107
@@ -76,6 +109,7 @@ void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e )
76{ 109{
77 TestInfo ti; 110 TestInfo ti;
78 ti.sName = sName; 111 ti.sName = sName;
112 ti.eExpect = e;
79 long index = ti.sName.rfind("::"); 113 long index = ti.sName.rfind("::");
80 if( index != -1 ) 114 if( index != -1 )
81 { 115 {
@@ -84,7 +118,7 @@ void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e )
84 ti.sName = tmp; 118 ti.sName = tmp;
85 } 119 }
86 ti.fTest = fTest; 120 ti.fTest = fTest;
87 lTests.push_back( ti ); 121 lTests.append( ti );
88} 122}
89 123
90void Bu::UnitSuite::setName( const FString &sName ) 124void Bu::UnitSuite::setName( const FString &sName )