32 lines · python
1import os2 3import clang.cindex4 5if "CLANG_LIBRARY_PATH" in os.environ:6 clang.cindex.Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])7 8import unittest9import ast10 11 12class TestLib(unittest.TestCase):13 def test_functions_registered(self):14 def get_function_spelling(node):15 # The call expressions we are interested in have16 # their spelling in .attr, not .id17 if hasattr(node, "attr"):18 return node.attr19 return ""20 21 filename = clang.cindex.__file__22 with open(filename) as file:23 root = ast.parse(file.read())24 functions = [25 get_function_spelling(node.func)26 for node in ast.walk(root)27 if isinstance(node, ast.Call)28 ]29 used_functions = set([func for func in functions if func.startswith("clang_")])30 registered_functions = set([item[0] for item in clang.cindex.FUNCTION_LIST])31 self.assertEqual(used_functions - registered_functions, set())32