:(before "End Types")
typedef void (*test_fn)(void);
:(before "End Globals")
const test_fn Tests[] = {
#include "test_list"
};
bool Run_tests = false;
bool Passed = true;
long Num_failures = 0;
#define CHECK(X) \
if (!(X)) { \
++Num_failures; \
cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << '\n'; \
Passed = false; \
return; \
}
#define CHECK_EQ(X, Y) \
if ((X) != (Y)) { \
++Num_failures; \
cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << " == " << #Y << '\n'; \
cerr << " got " << (X) << '\n'; \
Passed = false; \
return; \
}
:(before "End Setup")
Passed = true;
:(before "End Commandline Parsing")
if (argc > 1 && is_equal(argv[1], "test")) {
Run_tests = true; --argc; ++argv;
}
:(before "End Main")
if (Run_tests) {
time_t t; time(&t);
cerr << "C tests: " << ctime(&t);
for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
run_test(i);
}
cerr << '\n';
if (Num_failures > 0) {
cerr << Num_failures << " failure"
<< (Num_failures > 1 ? "s" : "")
<< '\n';
return 1;
}
return 0;
}
:(code)
void run_test(size_t i) {
if (i >= sizeof(Tests)/sizeof(Tests[0])) {
cerr << "no test " << i << '\n';
return;
}
setup();
(*Tests[i])();
teardown();
if (Passed) cerr << ".";
}
bool is_integer(const string& s) {
return s.find_first_not_of("0123456789-") == string::npos
&& s.find('-', 1) == string::npos
&& s.find_first_of("0123456789") != string::npos;
}
long long int to_integer(string n) {
char* end = NULL;
long long int result = strtoll(n.c_str(), &end, 0);
if (*end != '\0') cerr << "tried to { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: