#!/usr/bin/env python
import tempfile
import shutil
import sys
import os

class Testing:
    def __init__(self):
        self.failed_tests = { }
        self.succeeded_tests = { }

    def runCTest(self, cfile):
        (handle, path) = tempfile.mkstemp()
        temp_dir_path = tempfile.mkdtemp()
        try:
            os.close(handle)
            cmd = "cc %s -Wall --std=c99 -g3 %s -ltraildb -lJudy -o %s" %\
                  (os.getenv('CFLAGS', ''), cfile, path)
            if os.system(cmd) != 0:
                print("FAILED: %s" % cfile)
                self.failed_tests[cfile] = 1
                return

            os.system("chmod +x %s" % path)
            result = os.system("%s \"%s\"" % (path, temp_dir_path))
            if result != 0:
                print("FAILED: %s" % cfile)
                self.failed_tests[cfile] = 1
            else:
                print("SUCCEEDED: %s" % cfile)
                self.succeeded_tests[cfile] = 1
        finally:
            try:
                os.remove(path)
            except:
                pass
            try:
                shutil.rmtree(temp_dir_path)
            except:
                pass

    def runCTests(self):
        def walk(node):
            if os.path.isfile(node):
                if node.endswith(".c"):
                    self.runCTest(node)
            else:
                files = os.listdir(node)
                for f in files:
                    walk(os.path.join(node, f))

        return walk("c-tests")

    def runTests(self):
        self.runCTests()
        print("Number of failed tests: %d" % len(self.failed_tests))
        print("Number of succeeded tests: %d" % len(self.succeeded_tests))
        if self.failed_tests > 0:
            return -1
        return 0

if __name__ == '__main__':
    t = Testing()
    sys.exit(t.runTests())


@@ -134,19 +134,21 @@
 tests = 
-%7B %7D
+set()
 %0A       
@@ -175,11 +175,13 @@
 s = 
-%7B %7D
+set()
 %0A%0A  
@@ -579,35 +579,35 @@
 failed_tests
-%5Bcfile%5D = 1
+.add(cfile)
 %0A           
@@ -832,35 +832,35 @@
 failed_tests
-%5Bcfile%5D = 1
+.add(cfile)
 %0A           
@@ -953,19 +953,19 @@
 ests
-%5Bcfile%5D = 1
+.add(cfile)
 %0A   
@@ -1559,16 +1559,162 @@
 Tests()%0A
+%0A        if len(self.failed_tests) %3E 0:%0A            print(%22Tests that failed:%22)%0A            for s in self.failed_tests:%0A                print(s)%0A%0A
         
@@ -1860,16 +1860,20 @@
      if 
+len(
 self.fai
@@ -1881,16 +1881,17 @@
 ed_tests
+)
  %3E 0:%0A  
@@ -1910,16 +1910,17 @@
 turn -1%0A
+%0A
         

Fix test.py throwing exceptions.