Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-labelled-ranges.py

raw
1 # Verify the SARIF output of test-labelled-ranges.{c,cc}
2
3 from sarif import *
4
5 import pytest
6
7 @pytest.fixture(scope='function', autouse=True)
8 def sarif():
9 return sarif_from_env()
10
11 def test_sarif_output(sarif):
12 schema = sarif['$schema']
13 assert schema == 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json'
14
15 version = sarif['version']
16 assert version == '2.1.0'
17
18 runs = sarif['runs']
19 run = runs[0]
20
21 results = run['results']
22 assert len(results) == 1
23 assert results[0]['ruleId'] == 'error'
24 assert results[0]['level'] == 'error'
25 assert results[0]['message']['text'] \
26 == "mismatching types: 'int' and 'const char *'"
27 assert len(results[0]['locations']) == 1
28 location = results[0]['locations'][0]
29 phys_loc = location['physicalLocation']
30 assert phys_loc['region']['startLine'] == 19
31 assert phys_loc['region']['startColumn'] == 6
32 assert phys_loc['region']['endColumn'] == 7
33 assert phys_loc['contextRegion']['startLine'] == 19
34 assert phys_loc['contextRegion']['snippet']['text'] \
35 == ' 42 + "foo"\n'
36
37 annotations = location['annotations']
38 assert len(annotations) == 2
39
40 assert annotations[0]['startLine'] == 19
41 assert annotations[0]['startColumn'] == 3
42 assert annotations[0]['endColumn'] == 5
43 assert annotations[0]['message']['text'] == 'int'
44
45 assert annotations[1]['startLine'] == 19
46 assert annotations[1]['startColumn'] == 8
47 assert annotations[1]['endColumn'] == 13
48 assert annotations[1]['message']['text'] == 'const char *'