summaryrefslogtreecommitdiff
path: root/tests/test_examples.py
blob: b6f36dbc6b02e536c56dc373e0c2e982a7e3ff4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import sys
import time
import unittest

sys.path.insert(0, '.')
from tests.test_util import run_exe, cpp_supported

# Runs all pycparser examples with no command-line arguments and makes sure they
# run successfully (return code = 0), without actually verifying their output.
class TestExamplesSucceed(unittest.TestCase):
    @unittest.skipUnless(cpp_supported(), 'cpp only works on Unix')
    def test_all_examples(self):
        root = './examples'
        for filename in os.listdir(root):
            if os.path.splitext(filename)[1] == '.py':
                with self.subTest(name=filename):
                    path = os.path.join(root, filename)
                    rc, stdout, stderr = run_exe(path)
                    self.assertEqual(
                        rc, 0, f'example "{filename}" failed with stdout =\n{stdout}\nstderr =\n{stderr}')

if __name__ == '__main__':
    unittest.main()