brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · f7806ff Raw
44 lines · python
1import os2 3from clang.cindex import Config, CursorKind, ExceptionSpecificationKind4 5if "CLANG_LIBRARY_PATH" in os.environ:6    Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])7 8import unittest9 10from .util import get_tu11 12 13def find_function_declarations(node, declarations=[]):14    if node.kind == CursorKind.FUNCTION_DECL:15        declarations.append(node)16    for child in node.get_children():17        declarations = find_function_declarations(child, declarations)18    return declarations19 20 21class TestExceptionSpecificationKind(unittest.TestCase):22    def test_exception_specification_kind(self):23        source = """int square1(int x);24                    int square2(int x) noexcept;25                    int square3(int x) noexcept(noexcept(x * x));"""26 27        tu = get_tu(source, lang="cpp", flags=["-std=c++14"])28 29        declarations = find_function_declarations(tu.cursor)30        expected = [31            ("square1", ExceptionSpecificationKind.NONE),32            ("square2", ExceptionSpecificationKind.BASIC_NOEXCEPT),33            ("square3", ExceptionSpecificationKind.COMPUTED_NOEXCEPT),34        ]35        from_cursor = [36            (node.spelling, node.exception_specification_kind) for node in declarations37        ]38        from_type = [39            (node.spelling, node.type.get_exception_specification_kind())40            for node in declarations41        ]42        self.assertListEqual(from_cursor, expected)43        self.assertListEqual(from_type, expected)44