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() {}
86 void TestRunner::runTest() {
102 exit((mFailedCount || mExpiredCount) ? 1 : 0);
110 if (*mCurrent ==
nullptr) {
116 switch ((*mCurrent)->getLifeCycle()) {
119 (*mCurrent)->enableVerbosity(mVerbosity);
120 (*mCurrent)->setup();
132 (*mCurrent)->enableVerbosity(mVerbosity);
146 unsigned long now = millis();
147 if (mTimeout > 0 && now >= mStartTime + 1000L * mTimeout) {
148 (*mCurrent)->expire();
158 mCurrent = (*mCurrent)->
getNext();
164 switch ((*mCurrent)->getStatus()) {
182 (*mCurrent)->teardown();
186 (*mCurrent)->resolve();
188 *mCurrent = *(*mCurrent)->
getNext();
193 void TestRunner::setupRunner() {
196 mCount = countTests();
198 mStartTime = millis();
204 uint16_t TestRunner::countTests() {
219 void printSeconds(Print* printer,
unsigned long timeMillis) {
220 int s = timeMillis / 1000;
221 int ms = timeMillis % 1000;
224 if (ms < 100) printer->print(
'0');
225 if (ms < 10) printer->print(
'0');
231 void TestRunner::printStartRunner()
const {
235 printer->print(F(
"TestRunner started on "));
236 printer->print(mCount);
237 printer->println(F(
" test(s)."));
240 void TestRunner::resolveRun()
const {
244 unsigned long elapsedTime = mEndTime - mStartTime;
245 printer->print(F(
"TestRunner duration: "));
246 printSeconds(printer, elapsedTime);
247 printer->println(
" seconds.");
249 printer->print(F(
"TestRunner summary: "));
250 printer->print(mPassedCount);
251 printer->print(F(
" passed, "));
252 printer->print(mFailedCount);
253 printer->print(F(
" failed, "));
254 printer->print(mSkippedCount);
255 printer->print(F(
" skipped, "));
256 printer->print(mExpiredCount);
257 printer->print(F(
" timed out, out of "));
258 printer->print(mCount);
259 printer->println(F(
" test(s)."));
262 void TestRunner::listTests() {
266 printer->print(F(
"TestRunner test count: "));
267 printer->println(mCount);
269 printer->print(F(
"Test "));
270 (*p)->getName().print(printer);
271 printer->print(F(
"; lifeCycle: "));
272 printer->println((*p)->getLifeCycle());
276 void TestRunner::setRunnerTimeout(TimeoutType timeout) {