34 #include "Verbosity.h"
36 #include "TestRunner.h"
37 #include "string_util.h"
45 TestRunner* TestRunner::getRunner() {
46 static TestRunner singletonRunner;
47 return &singletonRunner;
54 void TestRunner::setLifeCycleMatchingPattern(
const char* pattern,
60 hasBeenFiltered =
true;
62 size_t length = strlen(pattern);
63 if (length > 0 && pattern[length - 1] ==
'*') {
72 if ((*p)->getName().compareToN(pattern, length) == 0) {
73 (*p)->setLifeCycle(lifeCycle);
78 void TestRunner::setLifeCycleMatchingPattern(
const char* testClass,
79 const char* pattern, uint8_t lifeCycle) {
85 hasBeenFiltered =
true;
92 char fullPattern[kMaxPatternLength];
93 bool status = internal::string_join(fullPattern, kMaxPatternLength,
'_',
97 setLifeCycleMatchingPattern(fullPattern, lifeCycle);
100 void TestRunner::setLifeCycleMatchingSubstring(
101 const char* substring, uint8_t lifeCycle) {
107 hasBeenFiltered =
true;
110 if ((*p)->getName().hasSubstring(substring)) {
111 (*p)->setLifeCycle(lifeCycle);
116 void TestRunner::excludeAll() {
124 uint16_t TestRunner::countTests() {
139 void printSeconds(Print* printer,
unsigned long timeMillis) {
140 int s = timeMillis / 1000;
141 int ms = timeMillis % 1000;
144 if (ms < 100) printer->print(
'0');
145 if (ms < 10) printer->print(
'0');
151 void TestRunner::printStartRunner()
const {
155 printer->print(F(
"TestRunner started on "));
156 printer->print(mCount);
157 printer->println(F(
" test(s)."));
160 void TestRunner::resolveRun()
const {
164 unsigned long elapsedTime = mEndTime - mStartTime;
165 printer->print(F(
"TestRunner duration: "));
166 printSeconds(printer, elapsedTime);
167 printer->println(
" seconds.");
169 printer->print(F(
"TestRunner summary: "));
170 printer->print(mPassedCount);
171 printer->print(F(
" passed, "));
172 printer->print(mFailedCount);
173 printer->print(F(
" failed, "));
174 printer->print(mSkippedCount);
175 printer->print(F(
" skipped, "));
176 printer->print(mExpiredCount);
177 printer->print(F(
" timed out, out of "));
178 printer->print(mCount);
179 printer->println(F(
" test(s)."));
182 void TestRunner::setRunnerTimeout(TimeoutType timeout) {
191 static void shift(
int& argc,
const char*
const*& argv) {
196 static bool argEquals(
const char* s,
const char* t) {
197 return strcmp(s, t) == 0;
200 static void usageAndExit(
int status) {
203 "Usage: %s [--help|-h]\n"
204 " [--include pattern,...] [--exclude pattern,...]\n"
205 " [--includesub substring,...] [--excludesub substring,...]\n"
206 " [--] [substring ...]\n",
212 void TestRunner::processCommaList(
213 const char*
const commaList, FilterType filterType) {
215 const int kArgumentSize = 64;
216 const char*
list = commaList;
220 char argument[kArgumentSize];
221 while (*
list !=
'\0') {
222 const char* comma = strchr(
list,
',');
223 int length = (comma) ? (comma -
list) : strlen(
list);
226 if (length >= kArgumentSize - 1) {
227 length = kArgumentSize - 1;
229 memcpy(argument,
list, length);
230 argument[length] =
'\0';
232 switch (filterType) {
233 case FilterType::kInclude:
236 case FilterType::kExclude:
239 case FilterType::kIncludeSub:
242 case FilterType::kExcludeSub:
247 list += (comma) ? length + 1 : length;
255 int TestRunner::parseFlags(
int argc,
const char*
const* argv) {
256 int argc_original = argc;
259 if (argEquals(argv[0],
"--include")) {
261 if (argc == 0) usageAndExit(1);
262 processCommaList(argv[0], FilterType::kInclude);
263 }
else if (argEquals(argv[0],
"--exclude")) {
265 if (argc == 0) usageAndExit(1);
266 processCommaList(argv[0], FilterType::kExclude);
267 }
else if (argEquals(argv[0],
"--includesub")) {
269 if (argc == 0) usageAndExit(1);
270 processCommaList(argv[0], FilterType::kIncludeSub);
271 }
else if (argEquals(argv[0],
"--excludesub")) {
273 if (argc == 0) usageAndExit(1);
274 processCommaList(argv[0], FilterType::kExcludeSub);
275 }
else if (argEquals(argv[0],
"--")) {
278 }
else if (argEquals(argv[0],
"--help") || argEquals(argv[0],
"-h")) {
281 }
else if (argv[0][0] ==
'-') {
282 fprintf(stderr,
"Unknonwn flag '%s'\n", argv[0]);
290 return argc_original - argc;
293 void TestRunner::processCommandLine() {
294 int args = parseFlags(epoxy_argc, epoxy_argv);
297 for (
int i = args; i < epoxy_argc; i++) {
This file provides overloaded compareXxx(a, b) functions which are used by the various assertXxx(a,...
static void setPrinter(Print *printer)
Set the printer.
static Print * getPrinter()
Get the output printer used by the various assertion() methods and the TestRunner.
static void include(const char *pattern)
Include the tests which match the pattern.
static bool isVerbosity(uint8_t verbosity)
Returns true if ANY of the bit flags of 'verbosity' is set.
static void includesub(const char *substring)
Include the tests which match the substring.
static void list()
Print out the known tests.
static void setPrinter(Print *printer)
Set the output printer.
static void excludesub(const char *substring)
Exclude the tests which match the substring.
static void exclude(const char *pattern)
Exclude the tests which match the pattern.
static const uint8_t kLifeCycleNew
Test is new, needs to be setup.
static Test ** getRoot()
Get the pointer to the root pointer.
static const uint8_t kLifeCycleExcluded
Test is Excluded by an exclude() method.
Test ** getNext()
Return the next pointer as a pointer to the pointer, similar to getRoot().
static const uint8_t kTestRunSummary
Print TestRunner summary message.