sdcc-cf:
[fw/sdcc] / support / regression / generate-cases.py
index 917213d6d0589f02d0391ba97b6d7418103e07de..d30a62d0d02408e04400a7dfd9f202f169a7b210 100644 (file)
@@ -9,27 +9,21 @@ outdir = sys.argv[2]
 
 # Start of the test function table definition
 testfuntableheader = """
-static TESTFUNP _tests[] = {
+void
+__runSuite(void)
+{
 """
 
-
 # End of the test function table definition
-testfuntablefooter = """\tNULL
-};
+testfuntablefooter = """}
 """
 
 # Code to generate the suite function
 testfunsuite = """
-TESTFUNP *
-suite(void)
-{
-    return _tests;
-}
-
-const char *
-getSuiteName(void)
+code const char *
+__getSuiteName(void)
 {
-    return "{testcase}";
+  return "{testcase}";
 }
 """ 
 
@@ -68,8 +62,8 @@ class InstanceGenerator:
         self.functions = []
         # Emit the suite wrapper into a temporary file
         self.tmpname = tempfile.mktemp()
-        (self.basename, self.ext) = re.split(r'\.', self.inname)
-        self.ext = '.' + self.ext
+        (self.dirname, self.filename) = os.path.split(self.inname)
+        (self.basename, self.ext) = os.path.splitext (self.filename)
 
     def permute(self, basepath, keys, trans = {}):
         """Permutes across all of the names.  For each value, recursivly creates
@@ -80,7 +74,7 @@ class InstanceGenerator:
         if len(keys) == 0:
             # End of the recursion.
             # Set the runtime substitutions.
-            trans['testcase'] = basepath
+            trans['testcase'] = re.sub(r'\\', r'\\\\', basepath)
             # Create the instance from the template
             T = TemplateDocument(self.tmpname)
             T.substitutions = trans
@@ -111,12 +105,16 @@ class InstanceGenerator:
         # Emmit the suite table
         fout.write(testfuntableheader)
 
+        n = 0;
         for fun in self.functions:
             # Turn the function definition into a pointer
             fun = re.sub(r'\(\w+\)', '', fun)
-            fout.write("\t" + fun + ",\n")
+            fout.write("  __prints(\"Running " + fun + "\\n\");\n");
+            fout.write('  ' + fun + "();\n")
+            n += 1;
 
         fout.write(testfuntablefooter)
+        fout.write("\nconst int __numCases = " + str(n) + ";\n")
         fout.write(testfunsuite);
         
         fout.close()
@@ -158,7 +156,7 @@ class InstanceGenerator:
                     None
             else:
                 # Pull out any test function names
-                if re.search(r'^test\w+\(\w+\)', line) != None:
+                if re.search(r'^\W*test\w*\W*\(\W*void\W*\)', line) != None:
                     self.functions.append(line)
 
     def generate(self):
@@ -171,7 +169,7 @@ class InstanceGenerator:
         createdir(outdir)
 
         # Generate
-        self.permute(os.path.join(outdir, os.path.basename(self.basename)), self.replacements.keys())
+        self.permute(os.path.join(outdir, self.basename), self.replacements.keys())
 
         # Remove the temporary file
         os.remove(self.tmpname)
@@ -189,4 +187,3 @@ def main():
 
 if __name__ == '__main__':
     main()
-