Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-sarif.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_basics(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 def test_nested_result(sarif):
17 runs = sarif['runs']
18 run = runs[0]
19 results = run['results']
20
21 assert len(results) == 1
22
23 result = results[0]
24 assert result['level'] == 'error'
25 assert result['message']['text'] == "top-level error"
26
27 relatedLocations = result['relatedLocations']
28 assert len(relatedLocations) == 12
29
30 for i in range(12):
31 note = relatedLocations[i]
32 text = note['message']['text']
33 nestingLevel = note['properties']['nestingLevel']
34 if i % 4 == 0:
35 assert text == 'child %i' % (i / 4)
36 assert nestingLevel == 1
37 else:
38 assert text == 'grandchild %i %i' % ((i / 4), (i % 4) - 1)
39 assert nestingLevel == 2