From 77f008b3fc024a2b542f2fe95823234afd65e34c Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 28 Sep 2017 17:22:56 +0000 Subject: Merging r312622: ------------------------------------------------------------------------ r312622 | jbcoe | 2017-09-06 00:33:32 -0700 (Wed, 06 Sep 2017) | 13 lines Fix __repr__ for Diagnostic in clang.cindex Summary: Also move misplaced tests for exception specification to fix failing Python tests. Reviewers: hans, compnerd Reviewed By: compnerd Subscribers: cfe-commits Tags: #clang-c Differential Revision: https://reviews.llvm.org/D37490 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_50@314434 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/clang/cindex.py | 8 +++---- bindings/python/tests/cindex/test_diagnostics.py | 8 +++++++ .../cindex/test_exception_specification_kind.py | 27 ++++++++++++++++++++++ .../tests/test_exception_specification_kind.py | 27 ---------------------- 4 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 bindings/python/tests/cindex/test_exception_specification_kind.py delete mode 100644 bindings/python/tests/test_exception_specification_kind.py diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 236803a9ab..4069ab8650 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -207,7 +207,7 @@ class _CXString(Structure): conf.lib.clang_disposeString(self) @staticmethod - def from_result(res, fn, args): + def from_result(res, fn=None, args=None): assert isinstance(res, _CXString) return conf.lib.clang_getCString(res) @@ -459,8 +459,7 @@ class Diagnostic(object): """The command-line option that disables this diagnostic.""" disable = _CXString() conf.lib.clang_getDiagnosticOption(self, byref(disable)) - - return conf.lib.clang_getCString(disable) + return _CXString.from_result(disable) def format(self, options=None): """ @@ -473,8 +472,7 @@ class Diagnostic(object): options = conf.lib.clang_defaultDiagnosticDisplayOptions() if options & ~Diagnostic._FormatOptionsMask: raise ValueError('Invalid format options') - formatted = conf.lib.clang_formatDiagnostic(self, options) - return conf.lib.clang_getCString(formatted) + return conf.lib.clang_formatDiagnostic(self, options) def __repr__(self): return "" % ( diff --git a/bindings/python/tests/cindex/test_diagnostics.py b/bindings/python/tests/cindex/test_diagnostics.py index ba6e545e8b..23cbe89f65 100644 --- a/bindings/python/tests/cindex/test_diagnostics.py +++ b/bindings/python/tests/cindex/test_diagnostics.py @@ -92,3 +92,11 @@ def test_diagnostic_children(): assert children[0].spelling.endswith('declared here') assert children[0].location.line == 1 assert children[0].location.column == 1 + +def test_diagnostic_string_repr(): + tu = get_tu('struct MissingSemicolon{}') + assert len(tu.diagnostics) == 1 + d = tu.diagnostics[0] + + assert repr(d) == ', spelling "expected \';\' after struct">' + diff --git a/bindings/python/tests/cindex/test_exception_specification_kind.py b/bindings/python/tests/cindex/test_exception_specification_kind.py new file mode 100644 index 0000000000..543d47f7db --- /dev/null +++ b/bindings/python/tests/cindex/test_exception_specification_kind.py @@ -0,0 +1,27 @@ +import clang.cindex +from clang.cindex import ExceptionSpecificationKind +from .util import get_tu + + +def find_function_declarations(node, declarations=[]): + if node.kind == clang.cindex.CursorKind.FUNCTION_DECL: + declarations.append((node.spelling, node.exception_specification_kind)) + for child in node.get_children(): + declarations = find_function_declarations(child, declarations) + return declarations + + +def test_exception_specification_kind(): + source = """int square1(int x); + int square2(int x) noexcept; + int square3(int x) noexcept(noexcept(x * x));""" + + tu = get_tu(source, lang='cpp', flags=['-std=c++14']) + + declarations = find_function_declarations(tu.cursor) + expected = [ + ('square1', ExceptionSpecificationKind.NONE), + ('square2', ExceptionSpecificationKind.BASIC_NOEXCEPT), + ('square3', ExceptionSpecificationKind.COMPUTED_NOEXCEPT) + ] + assert declarations == expected diff --git a/bindings/python/tests/test_exception_specification_kind.py b/bindings/python/tests/test_exception_specification_kind.py deleted file mode 100644 index 543d47f7db..0000000000 --- a/bindings/python/tests/test_exception_specification_kind.py +++ /dev/null @@ -1,27 +0,0 @@ -import clang.cindex -from clang.cindex import ExceptionSpecificationKind -from .util import get_tu - - -def find_function_declarations(node, declarations=[]): - if node.kind == clang.cindex.CursorKind.FUNCTION_DECL: - declarations.append((node.spelling, node.exception_specification_kind)) - for child in node.get_children(): - declarations = find_function_declarations(child, declarations) - return declarations - - -def test_exception_specification_kind(): - source = """int square1(int x); - int square2(int x) noexcept; - int square3(int x) noexcept(noexcept(x * x));""" - - tu = get_tu(source, lang='cpp', flags=['-std=c++14']) - - declarations = find_function_declarations(tu.cursor) - expected = [ - ('square1', ExceptionSpecificationKind.NONE), - ('square2', ExceptionSpecificationKind.BASIC_NOEXCEPT), - ('square3', ExceptionSpecificationKind.COMPUTED_NOEXCEPT) - ] - assert declarations == expected -- cgit v1.2.3