aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-sarif.py
blob: 7791147de3d68046b0625c047512968597750a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from sarif import *

import pytest

@pytest.fixture(scope='function', autouse=True)
def sarif():
    return sarif_from_env()

def test_basics(sarif):
    schema = sarif['$schema']
    assert schema == "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json"

    version = sarif['version']
    assert version == "2.1.0"

def test_nested_result(sarif):
    runs = sarif['runs']
    run = runs[0]
    results = run['results']

    assert len(results) == 1

    result = results[0]
    assert result['level'] == 'error'
    assert result['message']['text'] == "top-level error"

    relatedLocations = result['relatedLocations']
    assert len(relatedLocations) == 12

    for i in range(12):
        note = relatedLocations[i]
        text = note['message']['text']
        nestingLevel = note['properties']['nestingLevel']
        if i % 4 == 0:
            assert text == 'child %i' % (i / 4)
            assert nestingLevel == 1
        else:
            assert text == 'grandchild %i %i' % ((i / 4), (i % 4) - 1)
            assert nestingLevel == 2