blob: 85187652917b5eea7d4ec654a40e64420636633a [file] [log] [blame]
Daniel Dunbara7a354e2010-01-30 23:59:02 +00001from clang.cindex import *
2
3def tu_from_source(source):
4 index = Index.create()
5 tu = index.parse('INPUT.c', unsaved_files = [('INPUT.c', source)])
6 # FIXME: Remove the need for this.
7 tu.index = index
8 return tu
9
10# FIXME: We need support for invalid translation units to test better.
11
12def test_diagnostic_warning():
13 tu = tu_from_source("""int f0() {}\n""")
14 assert len(tu.diagnostics) == 1
15 assert tu.diagnostics[0].severity == Diagnostic.Warning
16 assert tu.diagnostics[0].location.line == 1
17 assert tu.diagnostics[0].location.column == 11
18 assert (tu.diagnostics[0].spelling ==
19 'control reaches end of non-void function')
20
21def test_diagnostic_note():
22 # FIXME: We aren't getting notes here for some reason.
23 index = Index.create()
24 tu = tu_from_source("""#define A x\nvoid *A = 1;\n""")
25 assert len(tu.diagnostics) == 1
26 assert tu.diagnostics[0].severity == Diagnostic.Warning
27 assert tu.diagnostics[0].location.line == 2
28 assert tu.diagnostics[0].location.column == 7
29 assert 'incompatible' in tu.diagnostics[0].spelling
30# assert tu.diagnostics[1].severity == Diagnostic.Note
31# assert tu.diagnostics[1].location.line == 1
32# assert tu.diagnostics[1].location.column == 11
33# assert tu.diagnostics[1].spelling == 'instantiated from'
34
35def test_diagnostic_fixit():
36 index = Index.create()
37 tu = tu_from_source("""struct { int f0; } x = { f0 : 1 };""")
38 assert len(tu.diagnostics) == 1
39 assert tu.diagnostics[0].severity == Diagnostic.Warning
40 assert tu.diagnostics[0].location.line == 1
41 assert tu.diagnostics[0].location.column == 31
42 assert tu.diagnostics[0].spelling.startswith('use of GNU old-style')
43 assert len(tu.diagnostics[0].fixits) == 1
44 assert tu.diagnostics[0].fixits[0].range.start.line == 1
45 assert tu.diagnostics[0].fixits[0].range.start.column == 26
46 assert tu.diagnostics[0].fixits[0].range.end.line == 1
Daniel Dunbar02968e52010-02-14 10:02:57 +000047 assert tu.diagnostics[0].fixits[0].range.end.column == 30
Daniel Dunbara7a354e2010-01-30 23:59:02 +000048 assert tu.diagnostics[0].fixits[0].value == '.f0 = '