Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-metadata-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 def test_sarif_output_metadata(sarif):
10 schema = sarif['$schema']
11 assert schema == 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json'
12
13 version = sarif['version']
14 assert version == '2.1.0'
15
16 runs = sarif['runs']
17 run = runs[0]
18
19 tool = run['tool']
20 assert tool['driver']['name'] == 'FooChecker'
21 assert tool['driver']['fullName'] == 'FooChecker 0.1 (en_US)'
22 assert tool['driver']['version'] == '0.1'
23 assert tool['driver']['informationUri'] == 'https://www.example.com/0.1/'
24
25 taxonomies = run["taxonomies"]
26 assert len(taxonomies) == 1
27
28 cwe = taxonomies[0]
29 assert cwe['name'] == 'CWE'
30 assert cwe['version'] == '4.7'
31 assert cwe['organization'] == 'MITRE'
32 assert cwe['shortDescription']['text'] \
33 == 'The MITRE Common Weakness Enumeration'
34 assert len(cwe['taxa']) == 1
35 assert cwe['taxa'][0]['id'] == '242'
36 assert cwe['taxa'][0]['helpUri'] \
37 == 'https://cwe.mitre.org/data/definitions/242.html'
38
39 results = run['results']
40 assert len(results) == 1
41
42 result = results[0]
43 assert result['ruleId'] == 'warning'
44 assert result['level'] == 'warning'
45 assert result['message']['text'] == "never use 'gets'"