Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-note-with-fix-it-hint-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 expected_line_num = 21
10
11 def test_sarif_output_with_fixes(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 tool = run['tool']
22 assert tool['driver']['name'] == 'test-note-with-fix-it-hint.c.exe'
23
24 results = run['results']
25 assert len(results) == 1
26 result = results[0]
27 assert result['ruleId'] == 'error'
28 assert result['level'] == 'error'
29 assert result['message']['text'] == "unknown field 'colour'"
30 assert len(result['locations']) == 1
31 location = result['locations'][0]
32 phys_loc = location['physicalLocation']
33 assert phys_loc['artifactLocation']['uri'].endswith('test-note-with-fix-it-hint.c')
34 assert phys_loc['region']['startLine'] == expected_line_num
35 assert phys_loc['region']['startColumn'] == 13
36 assert phys_loc['region']['endColumn'] == 19
37 assert phys_loc['contextRegion']['startLine'] == expected_line_num
38 assert phys_loc['contextRegion']['snippet']['text'] \
39 == ' return p->colour;\n'
40
41 assert len(result['relatedLocations']) == 1
42 note = result['relatedLocations'][0]
43 phys_loc = note['physicalLocation']
44 assert phys_loc['artifactLocation']['uri'].endswith('test-note-with-fix-it-hint.c')
45 assert phys_loc['region']['startLine'] == expected_line_num
46 assert phys_loc['region']['startColumn'] == 13
47 assert phys_loc['region']['endColumn'] == 19
48 assert phys_loc['contextRegion']['startLine'] == expected_line_num
49 assert phys_loc['contextRegion']['snippet']['text'] \
50 == ' return p->colour;\n'
51 assert note['message']['text'] == "did you mean 'color'"
52
53 # TODO: we don't yet capture fix-it hints on notes (PR other/116164)
54 assert 'fixes' not in result