X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftesting.h;h=1bc966c82e8a47c46b680fb08b0cab578d8bb150;hb=0a8741b9061f8df4a78a448c021612db06e17425;hp=2e4bf054b3855ea9717a6e08d8e3d1aa08b2991c;hpb=43aca8ed8b22a7a5a14f8c740948d6ce06efbc95;p=collectd.git diff --git a/src/testing.h b/src/testing.h index 2e4bf054..1bc966c8 100644 --- a/src/testing.h +++ b/src/testing.h @@ -48,20 +48,25 @@ static int check_count__ = 0; #define END_TEST exit ((fail_count__ == 0) ? 0 : 1); +#define LOG(result, text) \ + printf ("%s %i - %s\n", result ? "ok" : "not ok", ++check_count__, text) + #define OK1(cond, text) do { \ _Bool result = (cond); \ - printf ("%s %i - %s\n", result ? "ok" : "not ok", ++check_count__, text); \ + LOG (result, text); \ if (!result) { return -1; } \ } while (0) #define OK(cond) OK1(cond, #cond) #define EXPECT_EQ_STR(expect, actual) do { \ - if (strcmp (expect, actual) != 0) { \ + /* Evaluate 'actual' only once. */ \ + const char *got__ = actual; \ + if (strcmp (expect, got__) != 0) { \ printf ("not ok %i - %s = \"%s\", want \"%s\"\n", \ - ++check_count__, #actual, actual, expect); \ + ++check_count__, #actual, got__, expect); \ return (-1); \ } \ - printf ("ok %i - %s = \"%s\"\n", ++check_count__, #actual, actual); \ + printf ("ok %i - %s = \"%s\"\n", ++check_count__, #actual, got__); \ } while (0) #define EXPECT_EQ_INT(expect, actual) do { \