From 9cba56ac0ae9d8e6d58b8d5d645dfbca58321e0b Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Fri, 20 Jan 2012 16:33:20 +0100
Subject: test/run-test.c: Support negative assertions

Sometimes, we might want to make negative assertions (tests where
expected and actual output are expected/known to be different). A test
can be marked negative by prefixing it with an exclamation mark ('!'):

    $ ./run-test !test-negative
    Running test-negative... ok

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
---
 test/run-test.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

(limited to 'test')

diff --git a/test/run-test.c b/test/run-test.c
index 31fda0c..be9f1ce 100644
--- a/test/run-test.c
+++ b/test/run-test.c
@@ -151,7 +151,7 @@ usage (void)
 
 /* Run test with a specific name. */
 static int
-run_test (const char *name)
+run_test (const char *name, int expect_failure)
 {
   char filename[BUFSIZ];
   char *arg1[3], *arg2[3];
@@ -210,6 +210,9 @@ run_test (const char *name)
   if (child_wait (&pin2, NULL, pid2) != 0)
     ret = 0;
 
+  if (expect_failure)
+    ret = 1 - ret;
+
   if (ret == 1)
     printf (" ok\n");
   else
@@ -233,8 +236,16 @@ main (int argc, char **argv)
 
   for (i = 1; i < argc; i++)
     {
-      if (!run_test (argv[i]))
-        return 1;
+      if (*argv[i] == '!')
+        {
+          if (!run_test (argv[i] + 1, 1))
+            return 1;
+        }
+      else
+        {
+          if (!run_test (argv[i], 0))
+            return 1;
+        }
     }
 
   return 0;
-- 
cgit v1.2.3-70-g09d2