Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / bindings / python / tests / cindex / test_exception_specification_kind.py
blob8e2a6b5c50223334cb180dd0237c6300c6c74ead
1 import os
2 from clang.cindex import Config
4 if "CLANG_LIBRARY_PATH" in os.environ:
5 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
7 import clang.cindex
8 from clang.cindex import ExceptionSpecificationKind
9 from .util import get_tu
11 import unittest
14 def find_function_declarations(node, declarations=[]):
15 if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
16 declarations.append((node.spelling, node.exception_specification_kind))
17 for child in node.get_children():
18 declarations = find_function_declarations(child, declarations)
19 return declarations
22 class TestExceptionSpecificationKind(unittest.TestCase):
23 def test_exception_specification_kind(self):
24 source = """int square1(int x);
25 int square2(int x) noexcept;
26 int square3(int x) noexcept(noexcept(x * x));"""
28 tu = get_tu(source, lang="cpp", flags=["-std=c++14"])
30 declarations = find_function_declarations(tu.cursor)
31 expected = [
32 ("square1", ExceptionSpecificationKind.NONE),
33 ("square2", ExceptionSpecificationKind.BASIC_NOEXCEPT),
34 ("square3", ExceptionSpecificationKind.COMPUTED_NOEXCEPT),
36 self.assertListEqual(declarations, expected)