31 #include "Verbosity.h" 33 #include "TestRunner.h" 34 #include "string_util.h" 42 TestRunner* TestRunner::getRunner() {
43 static TestRunner singletonRunner;
44 return &singletonRunner;
51 void TestRunner::setLifeCycleMatchingPattern(
const char* pattern,
53 size_t length = strlen(pattern);
54 if (length > 0 && pattern[length - 1] ==
'*') {
63 if ((*p)->getName().compareToN(pattern, length) == 0) {
64 (*p)->setLifeCycle(lifeCycle);
69 void TestRunner::setLifeCycleMatchingPattern(
const char* testClass,
70 const char* pattern, uint8_t lifeCycle) {
76 char fullPattern[kMaxPatternLength];
77 bool status = internal::string_join(fullPattern, kMaxPatternLength,
'_',
81 setLifeCycleMatchingPattern(fullPattern, lifeCycle);
84 TestRunner::TestRunner():
95 mTimeout(kTimeoutDefault) {}
97 void TestRunner::runTest() {
121 if (*mCurrent ==
nullptr) {
127 switch ((*mCurrent)->getLifeCycle()) {
130 (*mCurrent)->enableVerbosity(mVerbosity);
131 (*mCurrent)->setup();
143 (*mCurrent)->enableVerbosity(mVerbosity);
157 unsigned long now = millis();
158 if (mTimeout > 0 && now >= mStartTime + 1000L * mTimeout) {
159 (*mCurrent)->expire();
169 mCurrent = (*mCurrent)->
getNext();
175 switch ((*mCurrent)->getStatus()) {
193 (*mCurrent)->teardown();
197 (*mCurrent)->resolve();
199 *mCurrent = *(*mCurrent)->
getNext();
204 void TestRunner::setupRunner() {
207 mCount = countTests();
209 mStartTime = millis();
215 uint16_t TestRunner::countTests() {
230 void printSeconds(Print* printer,
unsigned long timeMillis) {
231 int s = timeMillis / 1000;
232 int ms = timeMillis % 1000;
235 if (ms < 100) printer->print(
'0');
236 if (ms < 10) printer->print(
'0');
242 void TestRunner::printStartRunner()
const {
246 printer->print(F(
"TestRunner started on "));
247 printer->print(mCount);
248 printer->println(F(
" test(s)."));
251 void TestRunner::resolveRun()
const {
255 unsigned long elapsedTime = mEndTime - mStartTime;
256 printer->print(F(
"TestRunner duration: "));
257 printSeconds(printer, elapsedTime);
258 printer->println(
" seconds.");
260 printer->print(F(
"TestRunner summary: "));
261 printer->print(mPassedCount);
262 printer->print(F(
" passed, "));
263 printer->print(mFailedCount);
264 printer->print(F(
" failed, "));
265 printer->print(mSkippedCount);
266 printer->print(F(
" skipped, "));
267 printer->print(mExpiredCount);
268 printer->print(F(
" timed out, out of "));
269 printer->print(mCount);
270 printer->println(F(
" test(s)."));
273 void TestRunner::listTests() {
277 printer->print(F(
"TestRunner test count: "));
278 printer->println(mCount);
280 printer->print(F(
"Test "));
281 (*p)->getName().print(printer);
282 printer->print(F(
"; lifeCycle: "));
283 printer->println((*p)->getLifeCycle());
287 void TestRunner::setRunnerTimeout(
TimeoutType timeout) {
Base class of all test cases.
static const uint8_t kStatusFailed
Test has failed, or fail() was called.
static const uint8_t kLifeCycleAsserted
Test is asserted (using pass(), fail(), expired() or skipped()) and the getStatus() has been determin...
static void setPrinter(Print *printer)
Set the printer.
static const uint8_t kStatusPassed
Test has passed, or pass() was called.
uint8_t TimeoutType
Integer type of the timeout parameter.
Test ** getNext()
Return the next pointer as a pointer to the pointer, similar to getRoot().
static const uint8_t kDefault
The default verbosity.
static const uint8_t kStatusSkipped
Test is skipped through the exclude() method or skip() was called.
This file provides overloaded compareXxx(a, b) functions which are used by the various assertXxx(a...
static const uint8_t kLifeCycleExcluded
Test is Excluded by an exclude() method.
static Test ** getRoot()
Get the pointer to the root pointer.
static const uint8_t kLifeCycleFinished
The test has completed its life cycle.
static void setPrinter(Print *printer)
Set the output printer.
static const uint8_t kLifeCycleNew
Test is new, needs to be setup.
static Print * getPrinter()
Get the output printer used by the various assertion() methods and the TestRunner.
static const uint8_t kLifeCycleSetup
Test has been set up by calling setup() and ready to execute the test code.
static const uint8_t kTestRunSummary
Print TestRunner summary message.
static const uint8_t kStatusExpired
Test has timed out, or expire() called.
static bool isVerbosity(uint8_t verbosity)
Returns true if ANY of the bit flags of 'verbosity' is set.