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()) {
107 (*mCurrent)->enableVerbosity(mVerbosity);
109 (*mCurrent)->setup();
125 unsigned long now = millis();
126 if (mTimeout > 0 && now >= mStartTime + 1000L * mTimeout) {
127 (*mCurrent)->expire();
137 mCurrent = (*mCurrent)->
getNext();
144 (*mCurrent)->resolve();
146 *mCurrent = *(*mCurrent)->
getNext();
150 (*mCurrent)->resolve();
152 *mCurrent = *(*mCurrent)->
getNext();
156 (*mCurrent)->resolve();
158 *mCurrent = *(*mCurrent)->
getNext();
162 (*mCurrent)->resolve();
164 *mCurrent = *(*mCurrent)->
getNext();
169 void TestRunner::setupRunner() {
172 mCount = countTests();
174 mStartTime = millis();
180 uint16_t TestRunner::countTests() {
188 void TestRunner::printStartRunner() {
192 printer->print(F(
"TestRunner started on "));
193 printer->print(mCount);
194 printer->println(F(
" test(s)."));
197 void TestRunner::resolveRun() {
201 printer->print(F(
"TestRunner summary: "));
202 printer->print(mPassedCount);
203 printer->print(F(
" passed, "));
204 printer->print(mFailedCount);
205 printer->print(F(
" failed, "));
206 printer->print(mSkippedCount);
207 printer->print(F(
" skipped, "));
208 printer->print(mExpiredCount);
209 printer->print(F(
" timed out, out of "));
210 printer->print(mCount);
211 printer->println(F(
" test(s)."));
216 void TestRunner::listTests() {
220 printer->print(F(
"TestRunner test count: "));
221 printer->println(mCount);
223 printer->print(F(
"Test "));
225 printer->print(F(
"; status: "));
226 printer->println((*p)->getStatus());
230 void TestRunner::setRunnerTimeout(TimeoutType 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.
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 bool isVerbosity(uint8_t verbosity)
Returns true if ANY of the bit flags of 'verbosity' is set.