31 #include "Verbosity.h" 33 #include "TestRunner.h" 41 TestRunner* TestRunner::getRunner() {
42 static TestRunner singletonRunner;
43 return &singletonRunner;
50 void TestRunner::setStatusMatchingPattern(
const char* pattern, uint8_t status) {
51 size_t length = strlen(pattern);
52 if (length > 0 && pattern[length - 1] ==
'*') {
61 if (compareStringN((*p)->getName(), pattern, length) == 0) {
62 (*p)->setStatus(status);
67 TestRunner::TestRunner():
72 mVerbosity(Verbosity::kDefault),
77 mTimeout(kTimeoutDefault) {}
79 void TestRunner::runTest() {
98 if (*mCurrent ==
nullptr) {
104 switch ((*mCurrent)->getStatus()) {
106 (*mCurrent)->setup();
122 unsigned long now = millis();
123 if (mTimeout > 0 && now >= mStartTime + mTimeout) {
124 (*mCurrent)->expire();
134 mCurrent = (*mCurrent)->
getNext();
141 resolveTest((*mCurrent));
143 *mCurrent = *(*mCurrent)->
getNext();
147 resolveTest((*mCurrent));
149 *mCurrent = *(*mCurrent)->
getNext();
153 resolveTest((*mCurrent));
155 *mCurrent = *(*mCurrent)->
getNext();
159 resolveTest((*mCurrent));
161 *mCurrent = *(*mCurrent)->
getNext();
166 void TestRunner::setupRunner() {
169 mCount = countTests();
171 mStartTime = millis();
177 uint16_t TestRunner::countTests() {
185 void TestRunner::printStartRunner() {
189 printer->print(F(
"TestRunner started on "));
190 printer->print(mCount);
191 printer->println(F(
" test(s)."));
194 void TestRunner::resolveTest(Test* testCase) {
198 printer->print(F(
"Test "));
201 printer->println(F(
" skipped."));
203 printer->println(F(
" failed."));
205 printer->println(F(
" passed."));
207 printer->println(F(
" timed out."));
211 void TestRunner::resolveRun() {
215 printer->print(F(
"TestRunner summary: "));
216 printer->print(mPassedCount);
217 printer->print(F(
" passed, "));
218 printer->print(mFailedCount);
219 printer->print(F(
" failed, "));
220 printer->print(mSkippedCount);
221 printer->print(F(
" skipped, "));
222 printer->print(mExpiredCount);
223 printer->print(F(
" timed out, out of "));
224 printer->print(mCount);
225 printer->println(F(
" test(s)."));
230 void TestRunner::listTests() {
234 printer->print(F(
"TestRunner test count: "));
235 printer->print(mCount);
236 printer->println(
'.');
238 printer->print(F(
"Test "));
240 printer->println(F(
" found."));
244 void TestRunner::setRunnerTimeout(
unsigned long timeout) {
static const uint8_t kStatusFailed
Test has failed, or failed() was called.
static const uint8_t kStatusNew
Test is new, needs to be setup.
static void print(const FCString &s)
Convenience method for printing an FCString.
Various macros (test(), testing(), externTest(), externTesting()) are defined in this header...
static void setPrinter(Print *printer)
Set the printer.
static const uint8_t kStatusPassed
Test has passed, or pass() was called.
Test ** getNext()
Return the next pointer as a pointer to the pointer, similar to getRoot().
static const uint8_t kStatusSkipped
Test is skipped, through the exclude() method or skip() was called.
static Test ** getRoot()
Get the pointer to the root pointer.
static void setPrinter(Print *printer)
Set the output printer.
static Print * getPrinter()
Get the output printer used by the various assertion() methods and the TestRunner.
static const uint8_t kTestRunSummary
Print TestRunner summary message.
static const uint8_t kStatusSetup
Test is set up.
static const uint8_t kStatusExpired
Test has timed out, or expire() called.
static const uint8_t kTestAll
Print all test status messages.
static bool isVerbosity(uint8_t verbosity)
Returns true if ANY of the bit flags of 'verbosity' is set.