1import clang.cindex 2from clang.cindex import ExceptionSpecificationKind 3from .util import get_tu 4 5 6def find_function_declarations(node, declarations=[]): 7 if node.kind == clang.cindex.CursorKind.FUNCTION_DECL: 8 declarations.append((node.spelling, node.exception_specification_kind)) 9 for child in node.get_children(): 10 declarations = find_function_declarations(child, declarations) 11 return declarations 12 13 14def test_exception_specification_kind(): 15 source = """int square1(int x); 16 int square2(int x) noexcept; 17 int square3(int x) noexcept(noexcept(x * x));""" 18 19 tu = get_tu(source, lang='cpp', flags=['-std=c++14']) 20 21 declarations = find_function_declarations(tu.cursor) 22 expected = [ 23 ('square1', ExceptionSpecificationKind.NONE), 24 ('square2', ExceptionSpecificationKind.BASIC_NOEXCEPT), 25 ('square3', ExceptionSpecificationKind.COMPUTED_NOEXCEPT) 26 ] 27 assert declarations == expected 28