Debian Codegraph @

gcc/testsuite/gcc.dg/sarif-output/multiple-outputs.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_execution_unsuccessful(sarif):
10 runs = sarif['runs']
11 run = runs[0]
12
13 invocations = run['invocations']
14 assert len(invocations) == 1
15 invocation = invocations[0]
16
17 # We expect the 'error' to make executionSuccessful be false
18 assert invocation['executionSuccessful'] == False
19
20 def test_result(sarif):
21 runs = sarif['runs']
22 run = runs[0]
23 results = run['results']
24
25 # We expect a single error with a secondary location and a fix-it hint.
26 #
27 # The textual form of the diagnostic would look like this:
28 # . PATH/missing-semicolon.c: In function 'missing_semicolon':
29 # . PATH/missing-semicolon.c:19:12: error: expected ';' before '}' token
30 # . 19 | return 42
31 # . | ^
32 # . | ;
33 # . 20 | }
34 # . | ~
35 assert len(results) == 1
36
37 result = results[0]
38 assert result['level'] == 'error'
39 assert result['message']['text'] == "expected ';' before '}}' token"
40 locations = result['locations']
41 assert len(locations) == 1
42
43 assert len(result['fixes']) == 1
44 assert len(result['fixes'][0]['artifactChanges']) == 1
45 change = result['fixes'][0]['artifactChanges'][0]
46 assert len(change['replacements']) == 1
47 replacement = change['replacements'][0]
48 assert replacement['deletedRegion']['startColumn'] == 12
49 assert replacement['deletedRegion']['endColumn'] == 12
50 assert replacement['insertedContent']['text'] == ';'