changeset 13319:71829b55c10f

verify: automate tests 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>
author Eric Blake <eblake@redhat.com>
date Wed, 05 May 2010 16:19:18 -0600
parents a69ddb2f39de
children 4e283fd1efe9
files ChangeLog modules/verify-tests tests/test-verify.c tests/test-verify.sh
diffstat 4 files changed, 64 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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.
new file mode 100644
--- /dev/null
+++ b/modules/verify-tests
@@ -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
--- a/tests/test-verify.c
+++ b/tests/test-verify.c
@@ -21,12 +21,20 @@
 
 #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 @@
 
 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);
+}
new file mode 100755
--- /dev/null
+++ b/tests/test-verify.sh
@@ -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