| 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_basics(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 |
def test_execution_unsuccessful(sarif): |
| 17 |
runs = sarif['runs'] |
| 18 |
run = runs[0] |
| 19 |
|
| 20 |
invocations = run['invocations'] |
| 21 |
assert len(invocations) == 1 |
| 22 |
invocation = invocations[0] |
| 23 |
|
| 24 |
# We expect the 'error' to make executionSuccessful be false |
| 25 |
assert invocation['executionSuccessful'] == False |
| 26 |
|
| 27 |
def test_error(sarif): |
| 28 |
runs = sarif['runs'] |
| 29 |
run = runs[0] |
| 30 |
results = run['results'] |
| 31 |
|
| 32 |
# We expect a single error |
| 33 |
# |
| 34 |
# . The textual form of the diagnostic would look like this: |
| 35 |
# . PATH/diagnostic-format-sarif-1.F90:4:2: |
| 36 |
# . |
| 37 |
# . 4 | #error message |
| 38 |
# . | 1~~~~ |
| 39 |
# . Error: #error message |
| 40 |
assert len(results) == 1 |
| 41 |
|
| 42 |
result = results[0] |
| 43 |
assert result['level'] == 'error' |
| 44 |
assert result['message']['text'] == "#error message" |
| 45 |
locations = result['locations'] |
| 46 |
assert len(locations) == 1 |
| 47 |
|
| 48 |
location = locations[0] |
| 49 |
assert get_location_artifact_uri(location).endswith('diagnostic-format-sarif-1.F90') |
| 50 |
assert get_location_snippet_text(location) == '#error message\n' |
| 51 |
assert get_location_physical_region(location)['startLine'] == 4 |
| 52 |
assert get_location_physical_region(location)['startColumn'] == 2 |
| 53 |
assert get_location_physical_region(location)['endColumn'] == 7 |