| 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_messages_have_embedded_urls(sarif): |
| 10 |
runs = sarif['runs'] |
| 11 |
run = runs[0] |
| 12 |
results = run['results'] |
| 13 |
|
| 14 |
# We expect a single warning with a secondary location. |
| 15 |
# |
| 16 |
# The textual form of the diagnostic would look like this: |
| 17 |
# . PATH/bad-pragma.c:7:32: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas] |
| 18 |
# . 7 | #pragma GCC diagnostic ignored "-Wmisleading-indenttion" |
| 19 |
# . | ^~~~~~~~~~~~~~~~~~~~~~~~~ |
| 20 |
# . PATH/bad-pragma.c:7:32: note: did you mean '-Wmisleading-indentation'? |
| 21 |
assert len(results) == 1 |
| 22 |
|
| 23 |
result = results[0] |
| 24 |
assert result['ruleId'] == '-Wpragmas' |
| 25 |
assert result['level'] == 'warning' |
| 26 |
assert result['message']['text'] \ |
| 27 |
== "unknown option after '[#pragma GCC diagnostic](https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html)' kind" |
| 28 |
# Note how we expect an embedded link in the above for the docs for #pragma GCC diagnostic |
| 29 |
|
| 30 |
# We expect one related location, for the note. |
| 31 |
relatedLocations = result['relatedLocations'] |
| 32 |
assert len(relatedLocations) == 1 |
| 33 |
|
| 34 |
rel_loc = relatedLocations[0] |
| 35 |
assert rel_loc['message']['text'] \ |
| 36 |
== "did you mean '[-Wmisleading-indentation](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmisleading-indentation)'?" |
| 37 |
# Again, we expect an embedded link in the above, this time to the |
| 38 |
# docs for the suggested option |