}
-static const char *pathstrip(const char *filename)
-{
- const char *cptr;
- cptr = strrchr(filename, '/');
- if (cptr) filename = cptr + 1;
- cptr = strrchr(filename, '\\');
- if (cptr) filename = cptr + 1;
- return filename;
-}
-
static bool prefix_match(const char *s, char * const *prefixes)
{
char *const *prefix;
// the test is done and we can output it all at once.
//
// Yes, this is probably the worst API of all time.
-static void print_result_str(bool start, const char *_file, int _line,
- const char *_condstr, const char *result)
+static void print_result_str(const char *file, int line,
+ const char *condstr, const char *result)
{
- static char *file;
- static char *condstr;
- static int line;
- char *cptr;
-
- if (start)
- {
- if (file)
- free(file);
- if (condstr)
- free(condstr);
- file = strdup(pathstrip(_file));
- condstr = strdup(_condstr);
- line = _line;
-
- for (cptr = condstr; *cptr; cptr++)
- {
- if (!isprint((unsigned char)*cptr))
- *cptr = '!';
- }
- }
-
- if (!start)
- printf(TEST_START_FORMAT "%s\n", file, line, condstr, result);
+ printf(TEST_START_FORMAT "%s\n", file, line, condstr, result);
fflush(stdout);
-
- if (!start)
- {
- if (file)
- free(file);
- if (condstr)
- free(condstr);
- file = condstr = NULL;
- }
+
}
static inline void
-print_result(bool start, const char *file, int line,
+print_result(const char *file, int line,
const char *condstr, bool result)
{
- print_result_str(start, file, line, condstr, result ? "ok" : "FAILED");
+ print_result_str(file, line, condstr, result ? "ok" : "FAILED");
}
-void wvtest_start(const char *file, int line, const char *condstr)
-{
- // Either print the file, line, and condstr, or save them for later.
- print_result(true, file, line, condstr, false);
-}
-
-
-void wvtest_check(bool cond, const char *reason)
+void wvtest_check(const char *file, int line, const char *condstr, bool cond, const char *reason)
{
#ifndef _WIN32
alarm(MAX_TEST_TIME); // restart per-test timeout
runs++;
- print_result_str(false, NULL, 0, NULL, cond ? "ok" : (reason ? reason : "FAILED"));
+ print_result_str(file, line, condstr, cond ? "ok" : (reason ? reason : "FAILED"));
if (!cond)
{
b_str = b_op = "";
asprintf(&str, "%s%s%d %s %s%s%d", a_str, a_op, a, expect_pass ? "==" : "!=",
b_str, b_op, b);
-
- wvtest_start(file, line, str);
- free(str);
-
bool cond = (a == b);
if (!expect_pass)
cond = !cond;
- wvtest_check(cond, NULL);
+ wvtest_check(file, line, str, cond, NULL);
+ free(str);
+
return cond;
}
char *str = malloc(len);
sprintf(str, "%p %s %p", a, expect_pass ? "==" : "!=", b);
- wvtest_start(file, line, str);
- free(str);
-
bool cond = (a == b);
if (!expect_pass)
cond = !cond;
- wvtest_check(cond, NULL);
+ wvtest_check(file, line, str, cond, NULL);
+ free(str);
return cond;
}
char *str = malloc(len);
sprintf(str, "%d < %d", a, b);
- wvtest_start(file, line, str);
- free(str);
-
bool cond = (a < b);
- wvtest_check(cond, NULL);
+ wvtest_check(file, line, str, cond, NULL);
+ free(str);
return cond;
}
bool wvtest_start_check_eq_str(const char *file, int line,
char *str = malloc(len);
sprintf(str, "[%s] %s [%s]", a, expect_pass ? "==" : "!=", b);
- wvtest_start(file, line, str);
-
bool cond = !strcmp(a, b);
if (!expect_pass)
cond = !cond;
- wvtest_check(cond, NULL);
+ wvtest_check(file, line, str, cond, NULL);
return cond;
}
char *str = malloc(len);
sprintf(str, "[%s] < [%s]", a, b);
- wvtest_start(file, line, str);
- free(str);
-
bool cond = strcmp(a, b) < 0;
- wvtest_check(cond, NULL);
+ wvtest_check(file, line, str, cond, NULL);
+ free(str);
return cond;
}
int wvtest_start_check_errno(const char *file, int line,
const char *condstr, int retval)
{
- wvtest_start(file, line, condstr);
if (retval == -1)
perror(condstr);
- wvtest_check(retval != -1, NULL);
+ wvtest_check(file, line, condstr, retval != -1, NULL);
return retval;
}
void wvtest_register(struct WvTest *ptr);
int wvtest_run_all(char * const *prefixes);
-void wvtest_start(const char *file, int line, const char *condstr);
-void wvtest_check(bool cond, const char *reason);
+void wvtest_check(const char *file, int line, const char *condstr, bool cond, const char *reason);
static inline bool wvtest_start_check(const char *file, int line,
const char *condstr, bool cond)
-{ wvtest_start(file, line, condstr); wvtest_check(cond, NULL); return cond; }
+{ wvtest_check(file, line, condstr, cond, NULL); return cond; }
bool wvtest_start_check_eq(const char *file, int line,
int a, int b, bool expect_pass,
const char *a_str, const char *b_str);