aboutsummaryrefslogtreecommitdiff
path: root/clang/bindings/python/tests/cindex/test_lib.py
blob: 5e88ebf9d844838027babc5d48071546297ac5c1 (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
25
26
27
28
29
30
31
import os

import clang.cindex

if "CLANG_LIBRARY_PATH" in os.environ:
    clang.cindex.Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])

import unittest
import ast


class TestLib(unittest.TestCase):
    def test_functions_registered(self):
        def get_function_spelling(node):
            # The call expressions we are interested in have
            # their spelling in .attr, not .id
            if hasattr(node, "attr"):
                return node.attr
            return ""

        filename = clang.cindex.__file__
        with open(filename) as file:
            root = ast.parse(file.read())
        functions = [
            get_function_spelling(node.func)
            for node in ast.walk(root)
            if isinstance(node, ast.Call)
        ]
        used_functions = set([func for func in functions if func.startswith("clang_")])
        registered_functions = set([item[0] for item in clang.cindex.FUNCTION_LIST])
        self.assertEqual(used_functions - registered_functions, set())