summaryrefslogtreecommitdiffstats
path: root/bindings/python/tests
diff options
context:
space:
mode:
authorTobias Grosser <grosser@fim.uni-passau.de>2012-02-05 11:41:58 +0000
committerTobias Grosser <grosser@fim.uni-passau.de>2012-02-05 11:41:58 +0000
commitea403825faa5b8780a9b44277e6a2c68d7849146 (patch)
treef482c45407acfd00e3c13da957d71cf2a2cb1bab /bindings/python/tests
parent74858335a1a5205b3e1c89ecf9221cea839c0b0b (diff)
[clang.py] Expose diagnostic category and option info to Python binding
Contributed by: Gregory Szorc <gregory.szorc@gmail.com> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149825 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/tests')
-rw-r--r--bindings/python/tests/cindex/test_diagnostics.py34
1 files changed, 31 insertions, 3 deletions
diff --git a/bindings/python/tests/cindex/test_diagnostics.py b/bindings/python/tests/cindex/test_diagnostics.py
index 98f97d3bd3..b9872d9ce9 100644
--- a/bindings/python/tests/cindex/test_diagnostics.py
+++ b/bindings/python/tests/cindex/test_diagnostics.py
@@ -1,8 +1,13 @@
from clang.cindex import *
-def tu_from_source(source):
+def tu_from_source(source, all_warnings=False):
+ args = []
+ if all_warnings:
+ args = ['-Wall', '-Wextra']
+
index = Index.create()
- tu = index.parse('INPUT.c', unsaved_files = [('INPUT.c', source)])
+ tu = index.parse('INPUT.c', args=args,
+ unsaved_files = [('INPUT.c', source)])
return tu
# FIXME: We need support for invalid translation units to test better.
@@ -65,5 +70,28 @@ def test_diagnostic_range():
assert True
else:
assert False
-
+
+def test_diagnostic_category():
+ # Ensure that category properties work.
+ index = Index.create()
+ tu = tu_from_source("""int f(int i) { return 7; }""", all_warnings=True)
+ assert len(tu.diagnostics) == 1
+ d = tu.diagnostics[0]
+
+ assert d.severity == Diagnostic.Warning
+ assert d.location.line == 1
+ assert d.location.column == 11
+
+ assert d.category_number == 2
+ assert d.category_name == 'Semantic Issue'
+
+def test_diagnostic_option():
+ # Ensure that category option properties work.
+ index = Index.create()
+ tu = tu_from_source("""int f(int i) { return 7; }""", all_warnings=True)
+ assert len(tu.diagnostics) == 1
+ d = tu.diagnostics[0]
+
+ assert d.option == '-Wunused-parameter'
+ assert d.disable_option == '-Wno-unused-parameter'