blob: 27c6da9e1f597ee88a4785a01c0497a2e00a4eaf (
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
|
# We expect a warning with this textual form:
#
# | In file included from PATH/crash-test-ice-header-sarif-2.2.c:5:
# | PATH/crash-test-ice-in-header-sarif-2.2.c: In function 'test_inject_ice':
# | PATH/crash-test-ice-in-header.h:3:22: internal compiler error: I'm sorry Dave, I'm afraid I can't do that
# | 3 | #define INJECT_ICE() inject_ice ()
# | | ^~~~~~~~~~~~~
# | PATH/crash-test-ice-in-header-sarif-2.2.c:9:3: note: in expansion of macro 'INJECT_ICE'
# | 9 | INJECT_ICE (); /* { dg-ice "" } */
# | | ^~~~~~~~~~
from sarif import *
import pytest
@pytest.fixture(scope='function', autouse=True)
def sarif():
return sarif_from_env()
def test_basics(sarif):
# We expect SARIF 2.2
schema = sarif['$schema']
assert schema == "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/refs/tags/2.2-prerelease-2024-08-08/sarif-2.2/schema/sarif-2-2.schema.json"
version = sarif['version']
assert version == "2.2"
def test_no_result(sarif):
# We expect no results in the run
runs = sarif['runs']
run = runs[0]
results = run['results']
assert len(results) == 0
def test_notification(sarif):
# We expect an execution notification for the ICE in the invocation
runs = sarif['runs']
run = runs[0]
invocations = run['invocations']
assert len(invocations) == 1
invocation = invocations[0]
assert invocation['executionSuccessful'] == False
notifications = invocation['toolExecutionNotifications']
assert len(notifications) == 1
notification = notifications[0]
assert notification['message']['text'] == "I'm sorry Dave, I'm afraid I can't do that"
assert notification['level'] == 'error'
loc0 = notification['locations'][0]
assert get_location_artifact_uri(loc0).endswith('crash-test-ice-in-header.h')
assert 'inject_ice ();' in get_location_snippet_text(loc0)
# In SARIF 2.2 onwards we should be able to capture the include path
# as a related location within the notification
assert len(loc0['relationships']) == 1
assert loc0['relationships'][0]['kinds'] == ['isIncludedBy']
assert len(notification['relatedLocations']) == 1
rel_loc = notification['relatedLocations'][0]
assert get_location_artifact_uri(rel_loc).endswith('crash-test-ice-in-header-sarif-2.2.c')
assert '#include "crash-test-ice-in-header.h"' in get_location_snippet_text(rel_loc)
assert len(rel_loc['relationships']) == 1
assert rel_loc['relationships'][0]['kinds'] == ['includes']
|