From: Michal Sojka Date: Sun, 20 Feb 2011 08:31:58 +0000 (+0100) Subject: wvtest: WVFAIL(cond) returns cond X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/frsh-forb.git/commitdiff_plain/08b4d459286baffd4b1e7be79cfd2a1881e06fd5?hp=7e7b0cac4783f176181b361bbc5866092f23f44e wvtest: WVFAIL(cond) returns cond Previously WVFAIL returned !cond. In my optinion it was confusing because the statements if (cond) print_error(); and if (WVFAIL(cond)) print_error(); behaved differently. Now, they are functionally equivalent. In the implementation we use C extensions typeof() and "statement expression" to avoid duplication of side-effects caused by cond evaluation. --- diff --git a/src/wvtest/c/wvtest.h b/src/wvtest/c/wvtest.h index 0f0bb8ac..8530ba53 100644 --- a/src/wvtest/c/wvtest.h +++ b/src/wvtest/c/wvtest.h @@ -60,9 +60,11 @@ int wvtest_start_check_frsh(const char *file, int line, wvtest_start_check_eq_str(__FILE__, __LINE__, (a), (b), true) #define WVPASSLTSTR(a, b) \ wvtest_start_check_lt_str(__FILE__, __LINE__, (a), (b)) -#define WVFAIL(cond) \ - wvtest_start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond)) -#define WVFAILEQ(a, b) \ +#define WVFAIL(cond) \ + ({ typeof (cond) cond_ = (cond); \ + wvtest_start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond_)); \ + cond_; }) +#define WVFAILEQ(a, b) \ wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), false, #a, #b) #define WVFAILEQSTR(a, b) \ wvtest_start_check_eq_str(__FILE__, __LINE__, (a), (b), false)