aboutsummaryrefslogtreecommitdiff
path: root/src/stable/unitsuite.h
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/stable/unitsuite.h
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 'src/stable/unitsuite.h')
-rw-r--r--src/stable/unitsuite.h73
1 files changed, 73 insertions, 0 deletions
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 @@
17 17
18namespace Bu 18namespace Bu
19{ 19{
20 class Json;
20 /** 21 /**
21 * Provides a unit testing framework. This is pretty easy to use, probably 22 * Provides a unit testing framework. This is pretty easy to use, probably
22 * the best way to get started is to use ch to generate a template, or use 23 * the best way to get started is to use ch to generate a template, or use
@@ -96,6 +97,8 @@ namespace Bu
96 protected: 97 protected:
97 void add( Test fTest, const Bu::String &sName, Expect e=expectPass ); 98 void add( Test fTest, const Bu::String &sName, Expect e=expectPass );
98 void setName( const String &sName ); 99 void setName( const String &sName );
100 String getName() const;
101 virtual void cleanup();
99 102
100 void dispProgress(); 103 void dispProgress();
101 void setStepCount( int iSteps ); 104 void setStepCount( int iSteps );
@@ -104,6 +107,7 @@ namespace Bu
104 107
105 private: 108 private:
106 int onListCases( Bu::Array<Bu::String> aParam ); 109 int onListCases( Bu::Array<Bu::String> aParam );
110 int onPrintName( Bu::Array<Bu::String> aParam );
107 int onAddTest( Bu::Array<Bu::String> aParam ); 111 int onAddTest( Bu::Array<Bu::String> aParam );
108 112
109 private: 113 private:
@@ -128,6 +132,75 @@ namespace Bu
128 time_t tLastUpdate; 132 time_t tLastUpdate;
129 133
130 Bu::Hash<Bu::String, bool> hSelTests; 134 Bu::Hash<Bu::String, bool> hSelTests;
135
136 public:
137 class Report
138 {
139 public:
140 Report();
141 virtual ~Report();
142
143 virtual void suiteStarting( const UnitSuite &rSuite,
144 const TestList &lTests )=0;
145 virtual void testStarting( const TestInfo &rTest )=0;
146 virtual void updateProgress( int iProgress, int iStepCount )=0;
147 virtual void testEnded( const TestInfo &rTest )=0;
148 virtual void testEnded( const TestInfo &rTest,
149 const Failed &rFail )=0;
150 virtual void testException( const TestInfo &rTest,
151 std::exception &e )=0;
152 virtual void suiteEnded()=0;
153 };
154
155 class ReportConsole : public Report
156 {
157 public:
158 ReportConsole();
159 virtual ~ReportConsole();
160
161 virtual void suiteStarting( const UnitSuite &rSuite,
162 const TestList &lTests );
163 virtual void testStarting( const TestInfo &rTest );
164 virtual void updateProgress( int iProgress, int iStepCount );
165 virtual void testEnded( const TestInfo &rTest );
166 virtual void testEnded( const TestInfo &rTest,
167 const Failed &rFail );
168 virtual void testException( const TestInfo &rTest,
169 std::exception &e );
170 virtual void suiteEnded();
171
172 private:
173 int iTestCount;
174 int iNameWidth;
175 int iEPass;
176 int iEFail;
177 int iUPass;
178 int iUFail;
179 };
180
181 class ReportJson : public Report
182 {
183 public:
184 ReportJson();
185 virtual ~ReportJson();
186
187 virtual void suiteStarting( const UnitSuite &rSuite,
188 const TestList &lTests );
189 virtual void testStarting( const TestInfo &rTest );
190 virtual void updateProgress( int iProgress, int iStepCount );
191 virtual void testEnded( const TestInfo &rTest );
192 virtual void testEnded( const TestInfo &rTest,
193 const Failed &rFail );
194 virtual void testException( const TestInfo &rTest,
195 std::exception &e );
196 virtual void suiteEnded();
197
198 private:
199 class Bu::Json *pReport;
200 };
201
202 private:
203 Report *pReport;
131 }; 204 };
132 205
133Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ); 206Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e );