1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include "Framework.h"
template <>
void check_equal(float a, float b, const char *sa, const char *sb) {
if (a != b) throw BaseException("%s(%f) != %s(%f)", sa, a, sb, b);
}
template <>
void check_equal<const char *, const char *>(const char *a, const char *b, const char *sa, const char *sb) {
if (strcmp(a, b) != 0) { throw BaseException("%s(%s) != %s(%s)", sa, a, sb, b); }
}
bool TestRegistry::RunTests() {
char spinner[5] = "\\|/-";
unsigned long i = 0, s = 0;
size_t spinidx = 0;
for (std::vector<Test *>::iterator it = tests.begin(); it != tests.end(); ++it) {
Test *t = *it;
i++;
try {
t->Run();
s++;
} catch (std::exception &e) {
printf("Test %s failed with exception: %s\n", t->name.c_str(), e.what());
} catch (int e) {
printf("Test %s failed with error code: %d\n", t->name.c_str(), e);
} catch (...) {
printf("Test %s failed with ellipsis-caught error\n", t->name.c_str());
}
printf("%c\r", spinner[spinidx]);
spinidx = (spinidx + 1) % 4;
}
printf("%lu of %lu tests successful\n", s, i);
return !(s == i);
}
|