| 1 |
import os |
| 2 |
import sys |
| 3 |
import unittest |
| 4 |
|
| 5 |
sys.path.insert(0, ".") |
| 6 |
from tests.test_util import run_exe, cpp_supported |
| 7 |
|
| 8 |
|
| 9 |
# Runs all pycparser examples with no command-line arguments and makes sure they |
| 10 |
# run successfully (return code = 0), without actually verifying their output. |
| 11 |
class TestExamplesSucceed(unittest.TestCase): |
| 12 |
@unittest.skipUnless(cpp_supported(), "cpp only works on Unix") |
| 13 |
def test_all_examples(self): |
| 14 |
root = "./examples" |
| 15 |
for filename in os.listdir(root): |
| 16 |
if os.path.splitext(filename)[1] == ".py": |
| 17 |
with self.subTest(name=filename): |
| 18 |
path = os.path.join(root, filename) |
| 19 |
rc, stdout, stderr = run_exe(path) |
| 20 |
self.assertEqual( |
| 21 |
rc, |
| 22 |
0, |
| 23 |
f'example "{filename}" failed with stdout =\n{stdout}\nstderr =\n{stderr}', |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
if __name__ == "__main__": |
| 28 |
unittest.main() |