| 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_with_fixes(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'] == 'test-fix-it-hint.c.exe' |
| 21 |
|
| 22 |
results = run['results'] |
| 23 |
assert len(results) == 1 |
| 24 |
assert results[0]['ruleId'] == 'error' |
| 25 |
assert results[0]['level'] == 'error' |
| 26 |
assert results[0]['message']['text'] == "unknown field 'colour'; did you mean 'color'" |
| 27 |
assert len(results[0]['locations']) == 1 |
| 28 |
location = results[0]['locations'][0] |
| 29 |
phys_loc = location['physicalLocation'] |
| 30 |
assert phys_loc['artifactLocation']['uri'].endswith('test-fix-it-hint.c') |
| 31 |
assert phys_loc['region']['startLine'] == 19 |
| 32 |
assert phys_loc['region']['startColumn'] == 13 |
| 33 |
assert phys_loc['region']['endColumn'] == 19 |
| 34 |
assert phys_loc['contextRegion']['startLine'] == 19 |
| 35 |
assert phys_loc['contextRegion']['snippet']['text'] \ |
| 36 |
== ' return p->colour;\n' |
| 37 |
|
| 38 |
assert len(results[0]['fixes']) == 1 |
| 39 |
fix = results[0]['fixes'][0] |
| 40 |
assert len(fix['artifactChanges']) == 1 |
| 41 |
change = fix['artifactChanges'][0] |
| 42 |
assert change['artifactLocation']['uri'].endswith('test-fix-it-hint.c') |
| 43 |
assert len(change['replacements']) == 1 |
| 44 |
replacement = change['replacements'][0] |
| 45 |
assert replacement['deletedRegion'] == phys_loc['region'] |
| 46 |
assert replacement['insertedContent']['text'] == 'color' |