• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import os
2from clang.cindex import Config
3if 'CLANG_LIBRARY_PATH' in os.environ:
4    Config.set_library_path(os.environ['CLANG_LIBRARY_PATH'])
5
6import clang.cindex
7from clang.cindex import ExceptionSpecificationKind
8from .util import get_tu
9
10import unittest
11
12
13def find_function_declarations(node, declarations=[]):
14    if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
15        declarations.append((node.spelling, node.exception_specification_kind))
16    for child in node.get_children():
17        declarations = find_function_declarations(child, declarations)
18    return declarations
19
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        self.assertListEqual(declarations, expected)
36