]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
wvtest: WVFAIL(cond) returns cond
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 20 Feb 2011 08:31:58 +0000 (09:31 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 20 Feb 2011 08:31:58 +0000 (09:31 +0100)
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.

src/wvtest/c/wvtest.h

index 0f0bb8acabef5163783333db609fe158a9025d66..8530ba533d8641d3f9c7253a9a489b9fe49b5ee1 100644 (file)
@@ -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)