| 1 |
/* Example of emitting a warning. |
| 2 |
|
| 3 |
Intended output is similar to: |
| 4 |
|
| 5 |
/PATH/test-warning.c:17:8: warning: this is a warning |
| 6 |
17 | PRINT "hello world!"; |
| 7 |
| ^~~~~~~~~~~~ |
| 8 |
|
| 9 |
along with the equivalent in SARIF. */ |
| 10 |
|
| 11 |
#include "libgdiagnostics.h" |
| 12 |
#include "test-helpers.h" |
| 13 |
|
| 14 |
/* |
| 15 |
_________111111111122 |
| 16 |
123456789012345678901 |
| 17 |
PRINT "hello world!"; |
| 18 |
*/ |
| 19 |
const int line_num = __LINE__ - 2; |
| 20 |
|
| 21 |
int |
| 22 |
main () |
| 23 |
{ |
| 24 |
begin_test ("test-warning.c.exe", |
| 25 |
"test-warning.c.sarif", |
| 26 |
__FILE__, "c"); |
| 27 |
|
| 28 |
const diagnostic_physical_location *loc_start |
| 29 |
= diagnostic_manager_new_location_from_file_line_column (diag_mgr, |
| 30 |
main_file, |
| 31 |
line_num, |
| 32 |
8); |
| 33 |
const diagnostic_physical_location *loc_end |
| 34 |
= diagnostic_manager_new_location_from_file_line_column (diag_mgr, |
| 35 |
main_file, |
| 36 |
line_num, |
| 37 |
19); |
| 38 |
const diagnostic_physical_location *loc_range |
| 39 |
= diagnostic_manager_new_location_from_range (diag_mgr, |
| 40 |
loc_start, |
| 41 |
loc_start, |
| 42 |
loc_end); |
| 43 |
|
| 44 |
/* begin quoted source */ |
| 45 |
diagnostic *d = diagnostic_begin (diag_mgr, |
| 46 |
DIAGNOSTIC_LEVEL_WARNING); |
| 47 |
diagnostic_set_location (d, loc_range); |
| 48 |
|
| 49 |
diagnostic_finish (d, "this is a warning"); |
| 50 |
/* end quoted source */ |
| 51 |
|
| 52 |
return end_test (); |
| 53 |
} |
| 54 |
|
| 55 |
/* Verify the output from the text sink. |
| 56 |
{ dg-regexp "\[^\n\r\]+test-warning.c:17:8: warning: this is a warning" } |
| 57 |
{ dg-begin-multiline-output "" } |
| 58 |
17 | PRINT "hello world!"; |
| 59 |
| ^~~~~~~~~~~~ |
| 60 |
{ dg-end-multiline-output "" } */ |
| 61 |
|
| 62 |
/* Verify that some JSON was written to a file with the expected name: |
| 63 |
{ dg-final { verify-sarif-file } } */ |
| 64 |
|
| 65 |
/* Use a Python script to verify various properties about the generated |
| 66 |
.sarif file: |
| 67 |
{ dg-final { run-sarif-pytest test-warning.c "test-warning-c.py" } } */ |