* 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:
#!/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: