diff options
author | Efimov Vasily <real@ispras.ru> | 2017-10-30 18:03:23 +0300 |
---|---|---|
committer | Efimov Vasily <real@ispras.ru> | 2017-10-30 19:31:07 +0300 |
commit | 1fd7e1222c6c93678b9dee56cac972b51b5abc97 (patch) | |
tree | 888402b9f649ee709f1f6580ee3bcb6a4f7a3641 /test/testcpp.py | |
parent | 15d42d9d17b41cac7c0937bc858ec9407f0c2d03 (diff) | |
download | ply-1fd7e1222c6c93678b9dee56cac972b51b5abc97.tar.gz |
test: add a framework for C preprocessor testing
Signed-off-by: Efimov Vasily <real@ispras.ru>
Diffstat (limited to 'test/testcpp.py')
-rw-r--r-- | test/testcpp.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/testcpp.py b/test/testcpp.py new file mode 100644 index 0000000..2582c03 --- /dev/null +++ b/test/testcpp.py @@ -0,0 +1,48 @@ +from unittest import TestCase, main + +from multiprocessing import Process, Queue +from six.moves.queue import Empty + +import sys + +if ".." not in sys.path: + sys.path.insert(0, "..") + +from ply.lex import lex +from ply.cpp import * + + +def preprocessing(in_, out_queue): + out = None + + try: + p = Preprocessor(lex()) + p.parse(in_) + tokens = [t.value for t in p.parser] + out = "".join(tokens) + finally: + out_queue.put(out) + +class CPPTests(TestCase): + "Tests related to ANSI-C style lexical preprocessor." + + def __test_preprocessing(self, in_, expected, time_limit = 1.0): + out_queue = Queue() + + preprocessor = Process( + name = "PLY`s C preprocessor", + target = preprocessing, + args = (in_, out_queue) + ) + + preprocessor.start() + + try: + out = out_queue.get(timeout = time_limit) + except Empty: + preprocessor.terminate() + raise RuntimeError("Time limit exceeded!") + else: + self.assertMultiLineEqual(out, expected) + +main() |