+2010-05-05 Eric Blake <eblake@redhat.com>
+
+ verify: automate tests
+ * modules/verify-tests: New module.
+ * tests/test-verify.sh: New file.
+ * tests/test-verify.c: Guard each negative test with a unique id.
+ Also avoid warning about unused left hand of comma expressions.
+
2010-05-05 Paul Eggert <eggert@cs.ucla.edu>
Further improvements to verify.h, suggested by Eric Blake.
--- /dev/null
+Files:
+tests/test-verify.c
+tests/test-verify.sh
+tests/init.sh
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS_ENVIRONMENT += MAKE='$(MAKE)'
+TESTS += test-verify test-verify.sh
+check_PROGRAMS += test-verify
#include "verify.h"
+#ifndef EXP_FAIL
+# define EXP_FAIL 0
+#endif
+
int x;
enum { a, b, c };
+#if EXP_FAIL == 1
verify (x >= 0); /* should give ERROR: non-constant expression */
+#endif
verify (c == 2); /* should be ok */
+#if EXP_FAIL == 2
verify (1 + 1 == 3); /* should give ERROR */
+#endif
verify (1 == 1); verify (1 == 1); /* should be ok */
enum
int function (int n)
{
+#if EXP_FAIL == 3
verify (n >= 0); /* should give ERROR: non-constant expression */
+#endif
verify (c == 2); /* should be ok */
+#if EXP_FAIL == 4
verify (1 + 1 == 3); /* should give ERROR */
+#endif
verify (1 == 1); verify (1 == 1); /* should be ok */
if (n)
- return (verify_true (1 == 1), verify_true (1 == 1), 7); /* should be ok */
- else
- return (verify_true (1 == 2), 5); /* should give ERROR */
+ return ((void) verify_true (1 == 1), verify_true (1 == 1) + 7); /* should be ok */
+#if EXP_FAIL == 5
+ return (verify_true (1 == 2), 5); /* should give ERROR */
+#endif
+ return 0;
+}
+
+int
+main (void)
+{
+ return !(function (0) == 0 && function (1) == 8);
}
--- /dev/null
+#!/bin/sh
+. "${srcdir=.}/init.sh"
+
+# Rather than figure out how to invoke the compiler with the right
+# include path ourselves, we let make do it:
+(cd "$initial_cwd_" && rm -f test-verify.o \
+ && $MAKE test-verify.o >/dev/null 2>&1) \
+ || skip_ "cannot compile error-free"
+
+# Now, prove that we encounter all expected compilation failures:
+: >out
+: >err
+for i in 1 2 3 4 5; do
+ (cd "$initial_cwd_"
+ rm -f test-verify.o
+ $MAKE CFLAGS=-DEXP_FAIL=$i test-verify.o) >>out 2>>err \
+ && { warn_ "compiler didn't detect verification failure $i"; fail=1; }
+done
+
+Exit $fail