diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-01-30 23:59:02 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-01-30 23:59:02 +0000 |
commit | 532fc63b51cd0eb795df36d3fe306645b8b980e4 (patch) | |
tree | 442a5688b6613e09f83e3c7bd743e3d0f71224ba /bindings/python/tests | |
parent | e32af4213eb499fc5b6db15a9da9712148fcf8b5 (diff) |
cindex/Python: Add full support for Diagnostic and FixIt objects, available via TranslationUnit.diagnostics.
Several important FIXMEs remain:
- We aren't getting all the notes?
- There is still no way to get diagnostics for invalid inputs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94933 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/tests')
-rw-r--r-- | bindings/python/tests/cindex/test_diagnostics.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bindings/python/tests/cindex/test_diagnostics.py b/bindings/python/tests/cindex/test_diagnostics.py new file mode 100644 index 0000000000..58fd9e5384 --- /dev/null +++ b/bindings/python/tests/cindex/test_diagnostics.py @@ -0,0 +1,48 @@ +from clang.cindex import * + +def tu_from_source(source): + index = Index.create() + tu = index.parse('INPUT.c', unsaved_files = [('INPUT.c', source)]) + # FIXME: Remove the need for this. + tu.index = index + return tu + +# FIXME: We need support for invalid translation units to test better. + +def test_diagnostic_warning(): + tu = tu_from_source("""int f0() {}\n""") + assert len(tu.diagnostics) == 1 + assert tu.diagnostics[0].severity == Diagnostic.Warning + assert tu.diagnostics[0].location.line == 1 + assert tu.diagnostics[0].location.column == 11 + assert (tu.diagnostics[0].spelling == + 'control reaches end of non-void function') + +def test_diagnostic_note(): + # FIXME: We aren't getting notes here for some reason. + index = Index.create() + tu = tu_from_source("""#define A x\nvoid *A = 1;\n""") + assert len(tu.diagnostics) == 1 + assert tu.diagnostics[0].severity == Diagnostic.Warning + assert tu.diagnostics[0].location.line == 2 + assert tu.diagnostics[0].location.column == 7 + assert 'incompatible' in tu.diagnostics[0].spelling +# assert tu.diagnostics[1].severity == Diagnostic.Note +# assert tu.diagnostics[1].location.line == 1 +# assert tu.diagnostics[1].location.column == 11 +# assert tu.diagnostics[1].spelling == 'instantiated from' + +def test_diagnostic_fixit(): + index = Index.create() + tu = tu_from_source("""struct { int f0; } x = { f0 : 1 };""") + assert len(tu.diagnostics) == 1 + assert tu.diagnostics[0].severity == Diagnostic.Warning + assert tu.diagnostics[0].location.line == 1 + assert tu.diagnostics[0].location.column == 31 + assert tu.diagnostics[0].spelling.startswith('use of GNU old-style') + assert len(tu.diagnostics[0].fixits) == 1 + assert tu.diagnostics[0].fixits[0].range.start.line == 1 + assert tu.diagnostics[0].fixits[0].range.start.column == 26 + assert tu.diagnostics[0].fixits[0].range.end.line == 1 + assert tu.diagnostics[0].fixits[0].range.end.column == 29 + assert tu.diagnostics[0].fixits[0].value == '.f0 = ' |