aboutsummaryrefslogtreecommitdiff
path: root/src/tools/mkunit.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2023-08-08 16:33:38 -0700
committerMike Buland <eichlan@xagasoft.com>2023-08-08 16:33:38 -0700
commitc7e1277ecaf40c6d8ee945418a306f5b15189b97 (patch)
tree05a04473ffe90a76a4e7dd170c221141fea87b7e /src/tools/mkunit.cpp
parent7c36f58654f1b238d1b416927c9485a151216b1b (diff)
downloadlibbu++-c7e1277ecaf40c6d8ee945418a306f5b15189b97.tar.gz
libbu++-c7e1277ecaf40c6d8ee945418a306f5b15189b97.tar.bz2
libbu++-c7e1277ecaf40c6d8ee945418a306f5b15189b97.tar.xz
libbu++-c7e1277ecaf40c6d8ee945418a306f5b15189b97.zip
Unit test augmentations and harness.
Added some features to the mkunit program, including cleanup routine support. Added reporting modes for the UnitSuite class, and it can now generate machine readable reports. Added a new program, rununits that runs all unit tests and generates a synopsis of what you really care about at the end, issues!
Diffstat (limited to '')
-rw-r--r--src/tools/mkunit.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/tools/mkunit.cpp b/src/tools/mkunit.cpp
index f6ea669..5711c42 100644
--- a/src/tools/mkunit.cpp
+++ b/src/tools/mkunit.cpp
@@ -42,6 +42,7 @@ enum TokType
42 tokTest, 42 tokTest,
43 tokChar, 43 tokChar,
44 tokBlock, 44 tokBlock,
45 tokCleanup,
45 tokEof 46 tokEof
46}; 47};
47 48
@@ -54,6 +55,7 @@ Bu::Formatter &operator<<( Bu::Formatter &f, TokType t )
54 case tokTest: return f << "tokTest"; 55 case tokTest: return f << "tokTest";
55 case tokChar: return f << "tokChar"; 56 case tokChar: return f << "tokChar";
56 case tokBlock: return f << "tokBlock"; 57 case tokBlock: return f << "tokBlock";
58 case tokCleanup: return f << "tokCleanup";
57 case tokEof: return f << "tokEof"; 59 case tokEof: return f << "tokEof";
58 } 60 }
59 61
@@ -193,6 +195,8 @@ public:
193 { 195 {
194 if( sTok == "test" ) 196 if( sTok == "test" )
195 return tokTest; 197 return tokTest;
198 else if( sTok == "cleanup" )
199 return tokCleanup;
196 else 200 else
197 { 201 {
198 v = sTok; 202 v = sTok;
@@ -361,6 +365,15 @@ public:
361 s.lTest.append( t ); 365 s.lTest.append( t );
362 } 366 }
363 break; 367 break;
368
369 case tokCleanup:
370 {
371 if( nextToken( v, sWs, iL, iC ) != tokBlock )
372 throw Bu::ExceptionBase("%d:%d: Expected "
373 "{...} block.",
374 iL, iC );
375 }
376 break;
364 377
365 case tokChar: 378 case tokChar:
366 if( v.get<char>() == '}' ) 379 if( v.get<char>() == '}' )
@@ -438,7 +451,7 @@ public:
438 for( TestList::iterator i = s.lTest.begin(); i; i++ ) 451 for( TestList::iterator i = s.lTest.begin(); i; i++ )
439 { 452 {
440 f << "\t\tadd( static_cast<Bu::UnitSuite::Test>(" 453 f << "\t\tadd( static_cast<Bu::UnitSuite::Test>("
441 "&" << sClass << "::" << (*i).sName << "), \"" 454 "&" << sClass << "::_test_" << (*i).sName << "), \""
442 << (*i).sName << "\", Bu::UnitSuite::" 455 << (*i).sName << "\", Bu::UnitSuite::"
443 "expectPass );" << f.nl; 456 "expectPass );" << f.nl;
444 } 457 }
@@ -481,9 +494,24 @@ public:
481 "{...} block.", 494 "{...} block.",
482 iL, iC ); 495 iL, iC );
483 496
484 f << "\tvoid " << t.sName << "()" 497 f << "void _test_" << t.sName << "()"
498 << f.nl << "#line " << iL
499 << " \"" << sIn << "\"" << f.nl << " "
500 << v << f.nl;
501 }
502 break;
503
504 case tokCleanup:
505 {
506 fOut.write( sWs );
507 if( nextToken( v, sWs, iL, iC ) != tokBlock )
508 throw Bu::ExceptionBase("%d:%d: Expected "
509 "{...} block.",
510 iL, iC );
511
512 f << "void cleanup()"
485 << f.nl << "#line " << iL 513 << f.nl << "#line " << iL
486 << " \"" << sIn << "\"" << f.nl 514 << " \"" << sIn << "\"" << f.nl << " "
487 << v << f.nl; 515 << v << f.nl;
488 } 516 }
489 break; 517 break;