| 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_file_name = 'test-no-diagnostics.c' |
| 10 |
|
| 11 |
def test_sarif_output(sarif): |
| 12 |
schema = sarif['$schema'] |
| 13 |
assert schema == 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json' |
| 14 |
|
| 15 |
version = sarif['version'] |
| 16 |
assert version == '2.1.0' |
| 17 |
|
| 18 |
runs = sarif['runs'] |
| 19 |
run = runs[0] |
| 20 |
|
| 21 |
tool = run['tool'] |
| 22 |
assert tool['driver']['name'] == expected_file_name + '.exe' |
| 23 |
|
| 24 |
invocations = run['invocations'] |
| 25 |
assert len(invocations) == 1 |
| 26 |
assert 'workingDirectory' in invocations[0] |
| 27 |
assert 'startTimeUtc' in invocations[0] |
| 28 |
assert invocations[0]['executionSuccessful'] == True |
| 29 |
assert invocations[0]['toolExecutionNotifications'] == [] |
| 30 |
assert 'endTimeUtc' in invocations[0] |
| 31 |
|
| 32 |
artifacts = run['artifacts'] |
| 33 |
assert len(artifacts) == 1 |
| 34 |
assert artifacts[0]['location']['uri'].endswith(expected_file_name) |
| 35 |
assert artifacts[0]['sourceLanguage'] == 'c' |
| 36 |
# We don't bother capturing the contents if there are |
| 37 |
# no diagnostics to display |
| 38 |
assert 'contents' not in artifacts[0] |
| 39 |
assert artifacts[0]['roles'] == ["analysisTarget"] |
| 40 |
|
| 41 |
results = run['results'] |
| 42 |
assert len(results) == 0 |