| 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 = 16 |
| 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'] == 'test-no-column.c.exe' |
| 23 |
|
| 24 |
results = run['results'] |
| 25 |
assert len(results) == 1 |
| 26 |
location = results[0]['locations'][0] |
| 27 |
phys_loc = location['physicalLocation'] |
| 28 |
assert phys_loc['artifactLocation']['uri'].endswith('test-no-column.c') |
| 29 |
assert phys_loc['region']['startLine'] == expected_line_num |
| 30 |
# We should have no column properties: |
| 31 |
assert 'startColumn' not in phys_loc['region'] |
| 32 |
assert 'endColumn' not in phys_loc['region'] |
| 33 |
assert phys_loc['contextRegion']['startLine'] == expected_line_num |
| 34 |
assert phys_loc['contextRegion']['snippet']['text'] \ |
| 35 |
== '#include <foo.h>\n' |