31 #include "Verbosity.h" 33 #include "TestRunner.h" 41 TestRunner* TestRunner::getRunner() {
42 static TestRunner singletonRunner;
43 return &singletonRunner;
50 void TestRunner::setLifeCycleMatchingPattern(
const char* pattern,
52 size_t length = strlen(pattern);
53 if (length > 0 && pattern[length - 1] ==
'*') {
62 if ((*p)->getName().compareToN(pattern, length) == 0) {
63 (*p)->setLifeCycle(lifeCycle);
68 void TestRunner::setLifeCycleMatchingPattern(
const char* testClass,
69 const char* pattern, uint8_t lifeCycle) {
73 String fullPattern(testClass);
74 fullPattern.concat(
'_');
75 fullPattern.concat(pattern);
77 setLifeCycleMatchingPattern(fullPattern.c_str(), lifeCycle);
80 TestRunner::TestRunner():
91 mTimeout(kTimeoutDefault) {}
93 void TestRunner::runTest() {
114 if (*mCurrent ==
nullptr) {
120 switch ((*mCurrent)->getLifeCycle()) {
123 (*mCurrent)->enableVerbosity(mVerbosity);
124 (*mCurrent)->setup();
136 (*mCurrent)->enableVerbosity(mVerbosity);
150 unsigned long now = millis();
151 if (mTimeout > 0 && now >= mStartTime + 1000L * mTimeout) {
152 (*mCurrent)->expire();
162 mCurrent = (*mCurrent)->
getNext();
168 switch ((*mCurrent)->getStatus()) {
186 (*mCurrent)->teardown();
190 (*mCurrent)->resolve();
192 *mCurrent = *(*mCurrent)->
getNext();
197 void TestRunner::setupRunner() {
200 mCount = countTests();
202 mStartTime = millis();
208 uint16_t TestRunner::countTests() {
223 void printSeconds(Print* printer,
unsigned long timeMillis) {
224 int s = timeMillis / 1000;
225 int ms = timeMillis % 1000;
228 if (ms < 100) printer->print(
'0');
229 if (ms < 10) printer->print(
'0');
235 void TestRunner::printStartRunner() {
239 printer->print(F(
"TestRunner started on "));
240 printer->print(mCount);
241 printer->println(F(
" test(s)."));
244 void TestRunner::resolveRun() {
248 unsigned long elapsedTime = mEndTime - mStartTime;
249 printer->print(F(
"TestRunner duration: "));
250 printSeconds(printer, elapsedTime);
251 printer->println(
" seconds.");
253 printer->print(F(
"TestRunner summary: "));
254 printer->print(mPassedCount);
255 printer->print(F(
" passed, "));
256 printer->print(mFailedCount);
257 printer->print(F(
" failed, "));
258 printer->print(mSkippedCount);
259 printer->print(F(
" skipped, "));
260 printer->print(mExpiredCount);
261 printer->print(F(
" timed out, out of "));
262 printer->print(mCount);
263 printer->println(F(
" test(s)."));
266 void TestRunner::listTests() {
270 printer->print(F(
"TestRunner test count: "));
271 printer->println(mCount);
273 printer->print(F(
"Test "));
274 (*p)->getName().print(printer);
275 printer->print(F(
"; lifeCycle: "));
276 printer->println((*p)->getLifeCycle());
280 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.