From: Szabolcs Nagy Date: Sat, 6 Jul 2013 16:23:34 +0000 (+0000) Subject: simplify test.h X-Git-Url: http://nsz.repo.hu/git/?p=libc-test;a=commitdiff_plain;h=7becfeb717e7994a6025d1901894c72d42a7c4fe simplify test.h --- diff --git a/src/functional/test.h b/src/functional/test.h index 4a7d3a5..fb0a7ae 100644 --- a/src/functional/test.h +++ b/src/functional/test.h @@ -5,34 +5,9 @@ /* TODO: not thread-safe nor fork-safe */ static volatile int test_status; -#define error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) - -static int test_error(const char *fn, int l, const char *s, ...) -{ - va_list ap; - char buf[512]; - int n, k; - - test_status = 1; - n = snprintf(buf, sizeof buf, "ERROR %s:%d: ", fn, l); - if (n < 0) - n = 0; - else if (n >= sizeof buf) - n = sizeof buf; - va_start(ap, s); - k = vsnprintf(buf + n, sizeof buf - n, s, ap); - va_end(ap); - if (k < 0) - k = 0; - else if (k >= sizeof buf - n) { - k = sizeof buf - n; - buf[n + k - 1] = '\n'; - buf[n + k - 2] = '.'; - buf[n + k - 3] = '.'; - buf[n + k - 4] = '.'; - } - return write(1, buf, n + k); -} +#define TEST_LOC2(l) __FILE__ ":" #l +#define TEST_LOC1(l) TEST_LOC2(l) +#define error(...) test_printf("ERROR " TEST_LOC1(__LINE__) ": " __VA_ARGS__) static int test_printf(const char *s, ...) {