verify: automate tests
authorEric Blake <eblake@redhat.com>
Wed, 5 May 2010 22:19:18 +0000 (16:19 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 5 May 2010 23:23:39 +0000 (17:23 -0600)
Had we automated this sooner, we would have caught the issue
with gcc -Werror -Wredundant-decls sooner.

* 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.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
modules/verify-tests [new file with mode: 0644]
tests/test-verify.c
tests/test-verify.sh [new file with mode: 0755]

index 4897fb8..b92862f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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.
diff --git a/modules/verify-tests b/modules/verify-tests
new file mode 100644 (file)
index 0000000..936ed56
--- /dev/null
@@ -0,0 +1,13 @@
+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
index 890762f..47eae2b 100644 (file)
 
 #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
@@ -36,13 +44,25 @@ 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);
 }
diff --git a/tests/test-verify.sh b/tests/test-verify.sh
new file mode 100755 (executable)
index 0000000..11b7311
--- /dev/null
@@ -0,0 +1,20 @@
+#!/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