Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-error-c.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 expected_line_num = 17
10 expected_file_name = 'test-error.c'
11
12 def test_sarif_output(sarif):
13 schema = sarif['$schema']
14 assert schema == 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json'
15
16 version = sarif['version']
17 assert version == '2.1.0'
18
19 runs = sarif['runs']
20 run = runs[0]
21
22 tool = run['tool']
23 assert tool['driver']['name'] == expected_file_name + '.exe'
24
25 invocations = run['invocations']
26 assert len(invocations) == 1
27 assert 'workingDirectory' in invocations[0]
28 assert 'startTimeUtc' in invocations[0]
29 assert invocations[0]['executionSuccessful'] == False
30 assert invocations[0]['toolExecutionNotifications'] == []
31 assert 'endTimeUtc' in invocations[0]
32
33 artifacts = run['artifacts']
34 assert len(artifacts) == 1
35 assert artifacts[0]['location']['uri'].endswith(expected_file_name)
36 assert artifacts[0]['sourceLanguage'] == 'c'
37 assert '#include <foo.h>' in artifacts[0]['contents']['text']
38 assert artifacts[0]['roles'] == ["analysisTarget"]
39
40 results = run['results']
41 assert len(results) == 1
42 assert results[0]['ruleId'] == 'error'
43 assert results[0]['level'] == 'error'
44 assert results[0]['message']['text'] == "can't find 'foo.h'"
45 assert len(results[0]['locations']) == 1
46 location = results[0]['locations'][0]
47 phys_loc = location['physicalLocation']
48 assert phys_loc['artifactLocation']['uri'].endswith(expected_file_name)
49 assert phys_loc['region']['startLine'] == expected_line_num
50 assert phys_loc['region']['startColumn'] == 11
51 assert phys_loc['region']['endColumn'] == 16
52 assert phys_loc['contextRegion']['startLine'] == expected_line_num
53 assert phys_loc['contextRegion']['snippet']['text'] \
54 == '#include <foo.h>\n'