aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/sarif-output/bad-pragma.py
blob: 140bb33819846d0d3c2d243c28cccf861a38e2c9 (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
from sarif import *

import pytest

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

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

    # We expect a single warning with a secondary location.
    #
    # The textual form of the diagnostic would look like this:
    #  . PATH/bad-pragma.c:7:32: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]
    #  .     7 | #pragma GCC diagnostic ignored "-Wmisleading-indenttion"
    #  .       |                                ^~~~~~~~~~~~~~~~~~~~~~~~~
    #  . PATH/bad-pragma.c:7:32: note: did you mean '-Wmisleading-indentation'?
    assert len(results) == 1
    
    result = results[0]
    assert result['ruleId'] == '-Wpragmas'
    assert result['level'] == 'warning'
    assert result['message']['text'] \
        == "unknown option after '[#pragma GCC diagnostic](https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html)' kind"
    # Note how we expect an embedded link in the above for the docs for #pragma GCC diagnostic
    
    # We expect one related location, for the note.
    relatedLocations = result['relatedLocations']
    assert len(relatedLocations) == 1

    rel_loc = relatedLocations[0]
    assert rel_loc['message']['text'] \
        == "did you mean '[-Wmisleading-indentation](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmisleading-indentation)'?"
    # Again, we expect an embedded link in the above, this time to the
    # docs for the suggested option