From c7e1277ecaf40c6d8ee945418a306f5b15189b97 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 8 Aug 2023 16:33:38 -0700 Subject: 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! --- src/stable/unitsuite.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'src/stable/unitsuite.h') diff --git a/src/stable/unitsuite.h b/src/stable/unitsuite.h index ea5e389..b1e2953 100644 --- a/src/stable/unitsuite.h +++ b/src/stable/unitsuite.h @@ -17,6 +17,7 @@ namespace Bu { + class Json; /** * Provides a unit testing framework. This is pretty easy to use, probably * the best way to get started is to use ch to generate a template, or use @@ -96,6 +97,8 @@ namespace Bu protected: void add( Test fTest, const Bu::String &sName, Expect e=expectPass ); void setName( const String &sName ); + String getName() const; + virtual void cleanup(); void dispProgress(); void setStepCount( int iSteps ); @@ -104,6 +107,7 @@ namespace Bu private: int onListCases( Bu::Array aParam ); + int onPrintName( Bu::Array aParam ); int onAddTest( Bu::Array aParam ); private: @@ -128,6 +132,75 @@ namespace Bu time_t tLastUpdate; Bu::Hash hSelTests; + + public: + class Report + { + public: + Report(); + virtual ~Report(); + + virtual void suiteStarting( const UnitSuite &rSuite, + const TestList &lTests )=0; + virtual void testStarting( const TestInfo &rTest )=0; + virtual void updateProgress( int iProgress, int iStepCount )=0; + virtual void testEnded( const TestInfo &rTest )=0; + virtual void testEnded( const TestInfo &rTest, + const Failed &rFail )=0; + virtual void testException( const TestInfo &rTest, + std::exception &e )=0; + virtual void suiteEnded()=0; + }; + + class ReportConsole : public Report + { + public: + ReportConsole(); + virtual ~ReportConsole(); + + virtual void suiteStarting( const UnitSuite &rSuite, + const TestList &lTests ); + virtual void testStarting( const TestInfo &rTest ); + virtual void updateProgress( int iProgress, int iStepCount ); + virtual void testEnded( const TestInfo &rTest ); + virtual void testEnded( const TestInfo &rTest, + const Failed &rFail ); + virtual void testException( const TestInfo &rTest, + std::exception &e ); + virtual void suiteEnded(); + + private: + int iTestCount; + int iNameWidth; + int iEPass; + int iEFail; + int iUPass; + int iUFail; + }; + + class ReportJson : public Report + { + public: + ReportJson(); + virtual ~ReportJson(); + + virtual void suiteStarting( const UnitSuite &rSuite, + const TestList &lTests ); + virtual void testStarting( const TestInfo &rTest ); + virtual void updateProgress( int iProgress, int iStepCount ); + virtual void testEnded( const TestInfo &rTest ); + virtual void testEnded( const TestInfo &rTest, + const Failed &rFail ); + virtual void testException( const TestInfo &rTest, + std::exception &e ); + virtual void suiteEnded(); + + private: + class Bu::Json *pReport; + }; + + private: + Report *pReport; }; Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ); -- cgit v1.2.3