| 1 |
/* Example of a warning with multiple locations in various source lines, |
| 2 |
with an insertion fix-it hint. |
| 3 |
|
| 4 |
Intended output is similar to: |
| 5 |
|
| 6 |
/PATH/test-multiple-lines.c:23:29: warning: missing comma |
| 7 |
22 | const char *strs[3] = {"foo", |
| 8 |
| ~~~~~ |
| 9 |
23 | "bar" |
| 10 |
| ~~~~~^ |
| 11 |
24 | "baz"}; |
| 12 |
| ~~~~~ |
| 13 |
|
| 14 |
along with the equivalent in SARIF. */ |
| 15 |
|
| 16 |
#include "libgdiagnostics.h" |
| 17 |
#include "test-helpers.h" |
| 18 |
|
| 19 |
/* Placeholder source (missing comma after "bar"): |
| 20 |
_________11111111112222222222 |
| 21 |
12345678901234567890123456789 |
| 22 |
const char *strs[3] = {"foo", |
| 23 |
"bar" |
| 24 |
"baz"}; |
| 25 |
*/ |
| 26 |
const int foo_line_num = __LINE__ - 4; |
| 27 |
|
| 28 |
int |
| 29 |
main () |
| 30 |
{ |
| 31 |
begin_test ("test-multiple-lines.c.exe", |
| 32 |
"test-multiple-lines.c.sarif", |
| 33 |
__FILE__, "c"); |
| 34 |
|
| 35 |
/* begin quoted source */ |
| 36 |
const diagnostic_physical_location *loc_comma |
| 37 |
= diagnostic_manager_new_location_from_file_line_column (diag_mgr, |
| 38 |
main_file, |
| 39 |
foo_line_num + 1, |
| 40 |
29); |
| 41 |
const diagnostic_physical_location *loc_foo |
| 42 |
= make_range (diag_mgr, main_file, foo_line_num, 24, 28); |
| 43 |
const diagnostic_physical_location *loc_bar |
| 44 |
= make_range (diag_mgr, main_file, foo_line_num + 1, 24, 28); |
| 45 |
const diagnostic_physical_location *loc_baz |
| 46 |
= make_range (diag_mgr, main_file, foo_line_num + 2, 24, 28); |
| 47 |
|
| 48 |
diagnostic *d = diagnostic_begin (diag_mgr, |
| 49 |
DIAGNOSTIC_LEVEL_WARNING); |
| 50 |
diagnostic_set_location (d, loc_comma); |
| 51 |
diagnostic_add_location (d, loc_foo); |
| 52 |
diagnostic_add_location (d, loc_bar); |
| 53 |
diagnostic_add_location (d, loc_baz); |
| 54 |
|
| 55 |
diagnostic_add_fix_it_hint_insert_after (d, loc_bar, ","); |
| 56 |
|
| 57 |
diagnostic_finish (d, "missing comma"); |
| 58 |
/* end quoted source */ |
| 59 |
|
| 60 |
return end_test (); |
| 61 |
}; |
| 62 |
|
| 63 |
/* { dg-regexp "\[^\n\r\]+test-multiple-lines.c:23:29: warning: missing comma" } */ |
| 64 |
/* { dg-begin-multiline-output "" } |
| 65 |
22 | const char *strs[3] = {"foo", |
| 66 |
| ~~~~~ |
| 67 |
23 | "bar" |
| 68 |
| ~~~~~^ |
| 69 |
24 | "baz"}; |
| 70 |
| ~~~~~ |
| 71 |
{ dg-end-multiline-output "" } */ |
| 72 |
|
| 73 |
/* Verify that some JSON was written to a file with the expected name: |
| 74 |
{ dg-final { verify-sarif-file } } */ |
| 75 |
|
| 76 |
/* Use a Python script to verify various properties about the generated |
| 77 |
.sarif file: |
| 78 |
{ dg-final { run-sarif-pytest test-multiple-lines.c "test-multiple-lines-c.py" } } */ |