Add some more test framework
This commit is contained in:
parent
2864ba5a43
commit
cdf0bfb16c
20
run_tests.py
20
run_tests.py
|
@ -3,10 +3,10 @@ import unittest, subprocess, filecmp, argparse, os.path, os, shutil
|
|||
|
||||
REFERENCE_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), "tests")
|
||||
|
||||
REGEXES_DATA = [ #TODO
|
||||
[r"[a-zA-Z0-9]*"],
|
||||
[r"a", r"a|b"],
|
||||
[r"a|b", r"a"],
|
||||
REGEXES_DATA = [ # (regexes, should be accepted)
|
||||
([r"[a-zA-Z0-9]*"], True),
|
||||
([r"a", r"a|b"], True),
|
||||
([r"a|b", r"a"], True),
|
||||
]
|
||||
|
||||
EXAMPLE_TESTS = { #Mapping from test name to executable and number of available test input files
|
||||
|
@ -14,11 +14,15 @@ EXAMPLE_TESTS = { #Mapping from test name to executable and number of availabl
|
|||
"highlighter": ("examples/SyntaxHighlighter/highlighter", 1),
|
||||
}
|
||||
|
||||
def make_pipeline_test(regexes, idx):
|
||||
def make_pipeline_test(regexes, should_accept, idx):
|
||||
def test(self):
|
||||
p = subprocess.Popen([os.path.join(args.builddir, "src", "Lexesis-test"), "test_%s" % idx, data_dir], stdin=subprocess.PIPE)
|
||||
p.communicate(bytes("\n".join(regexes), "utf-8"))
|
||||
self.assertEqual(0, p.returncode)
|
||||
|
||||
if should_accept:
|
||||
self.assertEqual(0, p.returncode)
|
||||
else:
|
||||
self.assertNotEqual(0, p.returncode)
|
||||
|
||||
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.re" % idx), os.path.join(data_dir, "test_%s.re" % idx)), "The regex for testcase %s is incorrect" % idx)
|
||||
self.assertTrue(filecmp.cmp(os.path.join(REFERENCE_DIR, "test_%s.enfa" % idx), os.path.join(data_dir, "test_%s.enfa" % idx)), "The eNFA for testcase %s is incorrect" % idx)
|
||||
|
@ -60,8 +64,8 @@ if __name__ == "__main__":
|
|||
pass
|
||||
os.mkdir(data_dir)
|
||||
|
||||
for i, regexes in enumerate(REGEXES_DATA):
|
||||
t = make_pipeline_test(regexes, i)
|
||||
for i, (regexes, should_accept) in enumerate(REGEXES_DATA):
|
||||
t = make_pipeline_test(regexes, should_accept, i)
|
||||
setattr(Tests, "test_%s" % i, t)
|
||||
|
||||
for test, (prog, num) in EXAMPLE_TESTS.items():
|
||||
|
|
Loading…
Reference in New Issue