| 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 = 18 |
| 10 |
|
| 11 |
def test_sarif_output_for_note(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-error-with-note.c.exe' |
| 23 |
|
| 24 |
results = run['results'] |
| 25 |
assert len(results) == 1 |
| 26 |
assert results[0]['ruleId'] == 'error' |
| 27 |
assert results[0]['level'] == 'error' |
| 28 |
assert results[0]['message']['text'] == "can't find 'foo.h'" |
| 29 |
assert len(results[0]['locations']) == 1 |
| 30 |
location = results[0]['locations'][0] |
| 31 |
phys_loc = location['physicalLocation'] |
| 32 |
assert phys_loc['artifactLocation']['uri'].endswith('test-error-with-note.c') |
| 33 |
assert phys_loc['region']['startLine'] == expected_line_num |
| 34 |
assert phys_loc['region']['startColumn'] == 11 |
| 35 |
assert phys_loc['region']['endColumn'] == 16 |
| 36 |
assert phys_loc['contextRegion']['startLine'] == expected_line_num |
| 37 |
assert phys_loc['contextRegion']['snippet']['text'] \ |
| 38 |
== '#include <foo.h>\n' |
| 39 |
|
| 40 |
assert len(results[0]['relatedLocations']) == 1 |
| 41 |
note = results[0]['relatedLocations'][0] |
| 42 |
phys_loc = note['physicalLocation'] |
| 43 |
assert phys_loc['artifactLocation']['uri'].endswith('test-error-with-note.c') |
| 44 |
assert phys_loc['region']['startLine'] == expected_line_num |
| 45 |
assert phys_loc['region']['startColumn'] == 11 |
| 46 |
assert phys_loc['region']['endColumn'] == 16 |
| 47 |
assert phys_loc['contextRegion']['startLine'] == expected_line_num |
| 48 |
assert phys_loc['contextRegion']['snippet']['text'] \ |
| 49 |
== '#include <foo.h>\n' |
| 50 |
assert note['message']['text'] == 'have you looked behind the couch?' |