aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/libgdiagnostics.dg/test-nested-logical-locations-json-c.py
blob: 39cc1a9cb0b933460a590934038c4c259de38a01 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from sarif import *

import pytest

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

def test_sarif_output_with_logical_location(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'

    runs = sarif['runs']
    run = runs[0]

    tool = run['tool']
    assert tool['driver']['name'] == 'test-nested-logical-locations-json.c.exe'

    results = run['results']
    assert len(results) == 2

    result = results[0]
    assert result['ruleId'] == 'warning'
    assert result['level'] == 'warning'
    assert result['message']['text'] == "product ID is blank"
    assert len(result['locations']) == 1
    location = result['locations'][0]
    assert len(location['logicalLocations']) == 1
    logical_loc = location['logicalLocations'][0]
    assert logical_loc['index'] == 3
    assert logical_loc['fullyQualifiedName'] == '/orders/0/productIds/1'

    result = results[1]
    assert result['ruleId'] == 'warning'
    assert result['level'] == 'warning'
    assert result['message']['text'] == "value is negative"
    assert len(result['locations']) == 1
    location = result['locations'][0]
    assert len(location['logicalLocations']) == 1
    logical_loc = location['logicalLocations'][0]
    assert logical_loc['index'] == 4
    assert logical_loc['fullyQualifiedName'] == '/orders/0/total'

    # Check theRun.logicalLocations
    assert 'logicalLocations' in run
    assert len(run['logicalLocations']) == 5
    logical_loc = run['logicalLocations'][0]
    assert logical_loc['name'] == 'orders'
    assert logical_loc['fullyQualifiedName'] == '/orders'
    assert logical_loc['kind'] == 'array'
    assert logical_loc['index'] == 0
    logical_loc = run['logicalLocations'][1]
    assert logical_loc['name'] == '0'
    assert logical_loc['fullyQualifiedName'] == '/orders/0'
    assert logical_loc['kind'] == 'object'
    assert logical_loc['parentIndex'] == 0
    assert logical_loc['index'] == 1
    logical_loc = run['logicalLocations'][2]
    assert logical_loc['name'] == 'productIds'
    assert logical_loc['fullyQualifiedName'] == '/orders/0/productIds'
    assert logical_loc['kind'] == 'array'
    assert logical_loc['parentIndex'] == 1
    assert logical_loc['index'] == 2
    logical_loc = run['logicalLocations'][3]
    assert logical_loc['name'] == '1'
    assert logical_loc['fullyQualifiedName'] == '/orders/0/productIds/1'
    assert logical_loc['kind'] == 'value'
    assert logical_loc['parentIndex'] == 2
    assert logical_loc['index'] == 3
    logical_loc = run['logicalLocations'][4]
    assert logical_loc['name'] == 'total'
    assert logical_loc['fullyQualifiedName'] == '/orders/0/total'
    assert logical_loc['kind'] == 'property'
    assert logical_loc['parentIndex'] == 1
    assert logical_loc['index'] == 4