Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-multiple-lines-c.py

raw
1 from sarif import *
2
3 import pytest
4
5 @pytest.fixture(scope='function', autouse=True)
6 def sarif():
7 return sarif_from_env()
8
9 def test_sarif_output(sarif):
10 schema = sarif['$schema']
11 assert schema == 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json'
12
13 version = sarif['version']
14 assert version == '2.1.0'
15
16 runs = sarif['runs']
17 run = runs[0]
18
19 tool = run['tool']
20 assert tool['driver']['name'] == 'test-multiple-lines.c.exe'
21
22 results = run['results']
23 assert len(results) == 1
24 result = results[0]
25 assert result['ruleId'] == 'warning'
26 assert result['level'] == 'warning'
27 assert result['message']['text'] == "missing comma"
28 assert len(result['locations']) == 1
29
30 # The primary location should be that of the missing comma
31 location = result['locations'][0]
32 phys_loc = location['physicalLocation']
33 assert phys_loc['artifactLocation']['uri'].endswith('test-multiple-lines.c')
34 assert phys_loc['region']['startLine'] == 23
35 assert phys_loc['region']['startColumn'] == 29
36 assert phys_loc['region']['endColumn'] == 30
37 assert phys_loc['contextRegion']['startLine'] == 23
38 assert phys_loc['contextRegion']['snippet']['text'] \
39 == ' "bar"\n'
40
41 assert len(location['relationships']) == 3
42 location['relationships'][0]['target'] == 0
43 location['relationships'][0]['kinds'] == ['relevant']
44 location['relationships'][1]['target'] == 1
45 location['relationships'][1]['kinds'] == ['relevant']
46 location['relationships'][2]['target'] == 2
47 location['relationships'][2]['kinds'] == ['relevant']
48
49 # We should be capturing the secondary locations in relatedLocations
50 assert len(result['relatedLocations']) == 3
51
52 rel_loc_0 = result['relatedLocations'][0]
53 assert get_location_artifact_uri(rel_loc_0) \
54 .endswith('test-multiple-lines.c')
55 assert get_location_snippet_text(rel_loc_0) \
56 == 'const char *strs[3] = {"foo",\n'
57 assert get_location_physical_region(rel_loc_0)['startLine'] == 22
58 assert get_location_physical_region(rel_loc_0)['startColumn'] == 24
59 assert get_location_physical_region(rel_loc_0)['endColumn'] == 29
60 assert rel_loc_0['id'] == 0
61 assert 'relationships' not in rel_loc_0
62
63 rel_loc_1 = result['relatedLocations'][1]
64 assert get_location_artifact_uri(rel_loc_1) \
65 .endswith('test-multiple-lines.c')
66 assert get_location_snippet_text(rel_loc_1) \
67 == ' "bar"\n'
68 assert get_location_physical_region(rel_loc_1)['startLine'] == 23
69 assert get_location_physical_region(rel_loc_1)['startColumn'] == 24
70 assert get_location_physical_region(rel_loc_1)['endColumn'] == 29
71 assert rel_loc_1['id'] == 1
72 assert 'relationships' not in rel_loc_1
73
74 rel_loc_2 = result['relatedLocations'][2]
75 assert get_location_artifact_uri(rel_loc_2) \
76 .endswith('test-multiple-lines.c')
77 assert get_location_snippet_text(rel_loc_2) \
78 == ' "baz"};\n'
79 assert get_location_physical_region(rel_loc_2)['startLine'] == 24
80 assert get_location_physical_region(rel_loc_2)['startColumn'] == 24
81 assert get_location_physical_region(rel_loc_2)['endColumn'] == 29
82 assert rel_loc_2['id'] == 2
83 assert 'relationships' not in rel_loc_2