================ @@ -44,10 +34,70 @@ def test_from_id(self): with self.assertRaises(ValueError): enum.from_id(-1) - def test_duplicate_ids(self): - """Check that no two kinds have the same id""" - # for enum in self.enums: + def test_all_variants(self): + """Check that all libclang enum values are also defined in cindex.py""" + cenum_to_pythonenum = { + "CX_CXXAccessSpecifier": AccessSpecifier, + "CX_StorageClass": StorageClass, + "CXAvailabilityKind": AvailabilityKind, + "CXBinaryOperatorKind": BinaryOperator, + "CXCursorKind": CursorKind, + "CXCursor_ExceptionSpecificationKind": ExceptionSpecificationKind, + "CXLanguageKind": LanguageKind, + "CXLinkageKind": LinkageKind, + "CXPrintingPolicyProperty": PrintingPolicyProperty, + "CXRefQualifierKind": RefQualifierKind, + "CXTemplateArgumentKind": TemplateArgumentKind, + "CXTLSKind": TLSKind, + "CXTokenKind": TokenKind, + "CXTypeKind": TypeKind, + } + + indexheader = ( + Path(__file__).parent.parent.parent.parent.parent + / "include/clang-c/Index.h" + ) + # FIXME: Index.h is a C file, but we read it as a C++ file because we + # don't get ENUM_CONSTANT_DECL cursors otherwise, which we need here + # See bug report: https://github.com/llvm/llvm-project/issues/159075 + tu = TranslationUnit.from_source(indexheader, ["-x", "c++"]) + + enum_variant_map = {} + # For all enums in self.enums, extract all enum variants defined in Index.h + for cursor in tu.cursor.walk_preorder(): + python_enum = cenum_to_pythonenum.get(cursor.type.spelling) ---------------- Endilll wrote:
Can you move this one line below, closer to where `python_enum` is used? https://github.com/llvm/llvm-project/pull/143264 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits