]> rtime.felk.cvut.cz Git - omk.git/commitdiff
Some progress on testcases.
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 17 Jan 2007 18:48:00 +0000 (18:48 +0000)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 17 Jan 2007 18:48:00 +0000 (18:48 +0000)
darcs-hash:20070117184816-f2ef6-6d0371d6910e59727959c8b58299899140cf6ebc.gz

tests/README.tests
tests/programs/rules
tests/runtests.py
tests/test/all/rules [new file with mode: 0644]
tests/test/all/runtest [new file with mode: 0755]

index d8f0a8e4fd206becd165077c90050871e012c0dc..8a3b41475e9a12701320abb1e2b739e4668617b2 100644 (file)
@@ -13,14 +13,20 @@ files: Makefile.test, runtest.
 
 * Testcase Definition:
 
-  - Makefile.test: testcase commands are in the form of makefile. The
-    test is run by "make -f Makefile.test".
-
-  - runtest: executable file that runs the test(s).
+  - Testcase program: 
+    either Makefile.test, where the commands are in the form of makefile.
+    or runtest, which is the executable file that runs the test(s).
 
   - rules: Specifies the rules this testcase applies to. The syntax of
     this files is describes in section Rules description.
 
+* Testcase Execution:
+
+  If Makefile.test is found, make is executed as "make -k -f
+  Makefile.test". If no Makefile.test is found, runtest is
+  executed. Tests are executed with OMK_RULES environment variable set
+  to the name of the actual rules tested.
+
 * Testcase Output:
 
   Each execution of testcase should produce the following outputs:
index baa604443559156602ea097e44f6f77e588b3040..1263948fb882b8c4fd639b01e17969c825e79619 100644 (file)
@@ -1 +1 @@
-all
\ No newline at end of file
+all:
index 0055cde5d13c251e39927c0889487b7632d5e940..9f64ad01d9154e43ac648460f734dcb9538cf236 100755 (executable)
@@ -1,53 +1,87 @@
 #!/usr/bin/env python
 
+import os
 import os.path
 import sys
 import re
+import shutil
 
 sys.path.append("..")
 import rulesdef
 
 class TestCase:
     def __init__(self, directory):
-        self.directory = directory
+        self.directory = directory      # Absolute directory
         self._whichRules()
 
     def _whichRules(self):
+        """Reads the rules file and creates the self.rules list of all
+        rules to test"""
         self.rules = []
         try:
             f = open(os.path.join(self.directory, 'rules'))
         except IOError:
             self.rules = rulesdef.rules.keys()
             return
-        for line in f:
-            colonDef = re.search('([^:]*):(.*)', line)
-            if colonDef:
-                print colonDef.groups()
-                #todo s[nip[pet]]:...
-            elif re.search('^all', line):
+        line = f.readline()
+        colonMatch = re.search('([^:]*) *: *(.*)', line)
+        if colonMatch:
+            if colonMatch.group(1) == "all":
+                # all:
                 self.rules = rulesdef.rules.keys()
-            else:
-                #todo rule name
-                print "Neco jineho: ", line
+            elif colonMatch.group(1) == "snip":
+                # snip: ...
+                snip = colonMatch.group(2)
+                for r in rulesdef.rules:
+                    if snip in rulesdef.rules[r]:
+                        self.rules.append(r)
+            elif colonMatch.group(1) == "python":
+                # python: ...
+                expr = colonMatch.group(2)
+                for r in rulesdef.rules:
+                    if eval(expr, {'rules': r, 'snippets': rulesdef.rules[r]}):
+                        self.rules.append(r)
+        else:
+            # rule name
+            if line in rulesdef.rules: self.rules = [ line ]
+        #print self.rules
         
 
     def run(self):
-        print "Testing rules: ",
+        print "Testing %s:" % self.directory,
+        os.chdir(os.path.join(testsRoot, self.directory))
         for rules in self.rules:
-            print rules,
+            os.environ['OMK_RULES'] = rules
             self._copyRules(rules)
             self._doRun()
         print
+        # TODO remove makefile rules if sucessfull
 
     def _copyRules(self, rules):
-        pass
+        "Copies the rules to the current directory"
+        src = os.path.join(testsRoot, "..", "rules", rules, "Makefile.rules")
+        shutil.copy(src, ".")
     
     def _doRun(self):
-        pass
-
-x = TestCase("programs")
-x.run()
-x = TestCase("none")
-x.run()
-x = TestCase("colon")
-x.run()
+        "Runs the teset in current directory."
+        if os.path.exists("Makefile.test"):
+            ret = os.system("make -k -f Makefile.test")
+        elif os.path.exists("runtest"):
+            ret = os.system("./runtest")
+        print ret,
+
+
+testsRoot = os.path.dirname(os.path.abspath(__file__))
+if not os.path.exists(os.path.join(testsRoot, "runtests.py")): raise "Can't find tests root directory!"
+
+for dirpath, dirnames, filenames in os.walk(testsRoot):
+    if not ("Makefile.test" in filenames or \
+            "runtest" in filenames):
+        continue
+    print dirpath
+    t = TestCase(dirpath)
+    t.run()
+
+# Local Variables:
+# compile-command: "python runtests.py"
+# End:
diff --git a/tests/test/all/rules b/tests/test/all/rules
new file mode 100644 (file)
index 0000000..ff13f80
--- /dev/null
@@ -0,0 +1 @@
+all:
\ No newline at end of file
diff --git a/tests/test/all/runtest b/tests/test/all/runtest
new file mode 100755 (executable)
index 0000000..fc634cb
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+import os
+import sys
+
+sys.path.append("../../..")
+import rulesdef
+
+print "All test:",
+r = os.environ['OMK_RULES']
+if r: print os.environ['OMK_RULES']
+else: print "No environment variable"
+
+sys.exit(0)