summaryrefslogtreecommitdiffstats
path: root/bindings/python/tests/cindex/test_diagnostics.py
blob: 85187652917b5eea7d4ec654a40e64420636633a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 == 30
    assert tu.diagnostics[0].fixits[0].value == '.f0 = '
OpenPOWER on IntegriCloud