From da7b7543eb32855880c528fc0bb1de894fbcf8fe Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 17 Jan 2007 18:48:00 +0000 Subject: [PATCH] Some progress on testcases. darcs-hash:20070117184816-f2ef6-6d0371d6910e59727959c8b58299899140cf6ebc.gz --- tests/README.tests | 14 +++++--- tests/programs/rules | 2 +- tests/runtests.py | 76 ++++++++++++++++++++++++++++++------------ tests/test/all/rules | 1 + tests/test/all/runtest | 14 ++++++++ 5 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 tests/test/all/rules create mode 100755 tests/test/all/runtest diff --git a/tests/README.tests b/tests/README.tests index d8f0a8e..8a3b414 100644 --- a/tests/README.tests +++ b/tests/README.tests @@ -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: diff --git a/tests/programs/rules b/tests/programs/rules index baa6044..1263948 100644 --- a/tests/programs/rules +++ b/tests/programs/rules @@ -1 +1 @@ -all \ No newline at end of file +all: diff --git a/tests/runtests.py b/tests/runtests.py index 0055cde..9f64ad0 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -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 index 0000000..ff13f80 --- /dev/null +++ b/tests/test/all/rules @@ -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 index 0000000..fc634cb --- /dev/null +++ b/tests/test/all/runtest @@ -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) -- 2.39.2