| 1 |
/* Example of a grouped error and note, with a fix-it hint on the note. |
| 2 |
|
| 3 |
Intended output is similar to: |
| 4 |
|
| 5 |
/PATH/test-note-with-fix-it-hint.c:21:13: error: unknown field 'colour' |
| 6 |
21 | return p->colour; |
| 7 |
| ^~~~~~ |
| 8 |
/PATH/test-note-with-fix-it-hint.c:21:13: note: did you mean 'color' |
| 9 |
21 | return p->colour; |
| 10 |
| ^~~~~~ |
| 11 |
| color |
| 12 |
|
| 13 |
along with the equivalent in SARIF. */ |
| 14 |
|
| 15 |
#include "libgdiagnostics.h" |
| 16 |
#include "test-helpers.h" |
| 17 |
|
| 18 |
/* Placeholder source: |
| 19 |
_________11111111112 |
| 20 |
12345678901234567890 |
| 21 |
return p->colour; |
| 22 |
*/ |
| 23 |
const int line_num = __LINE__ - 2; |
| 24 |
|
| 25 |
int |
| 26 |
main () |
| 27 |
{ |
| 28 |
begin_test ("test-note-with-fix-it-hint.c.exe", |
| 29 |
"test-note-with-fix-it-hint.c.sarif", |
| 30 |
__FILE__, "c"); |
| 31 |
|
| 32 |
const diagnostic_physical_location *loc_token |
| 33 |
= make_range (diag_mgr, main_file, line_num, 13, 18); |
| 34 |
|
| 35 |
diagnostic_manager_begin_group (diag_mgr); |
| 36 |
|
| 37 |
diagnostic *err = diagnostic_begin (diag_mgr, DIAGNOSTIC_LEVEL_ERROR); |
| 38 |
diagnostic_set_location (err, loc_token); |
| 39 |
diagnostic_finish (err, "unknown field %qs", "colour"); |
| 40 |
|
| 41 |
diagnostic *n = diagnostic_begin (diag_mgr, DIAGNOSTIC_LEVEL_NOTE); |
| 42 |
diagnostic_set_location (n, loc_token); |
| 43 |
diagnostic_add_fix_it_hint_replace (n, loc_token, "color"); |
| 44 |
diagnostic_finish (n, "did you mean %qs", "color"); |
| 45 |
|
| 46 |
diagnostic_manager_end_group (diag_mgr); |
| 47 |
|
| 48 |
return end_test (); |
| 49 |
} |
| 50 |
|
| 51 |
/* Verify the output from the text sink. |
| 52 |
{ dg-regexp "\[^\n\r\]+test-note-with-fix-it-hint.c:21:13: error: unknown field 'colour'" } |
| 53 |
{ dg-begin-multiline-output "" } |
| 54 |
21 | return p->colour; |
| 55 |
| ^~~~~~ |
| 56 |
{ dg-end-multiline-output "" } |
| 57 |
{ dg-regexp "\[^\n\r\]+test-note-with-fix-it-hint.c:21:13: note: did you mean 'color'" } |
| 58 |
{ dg-begin-multiline-output "" } |
| 59 |
21 | return p->colour; |
| 60 |
| ^~~~~~ |
| 61 |
| color |
| 62 |
{ dg-end-multiline-output "" } */ |
| 63 |
|
| 64 |
/* Verify that some JSON was written to a file with the expected name: |
| 65 |
{ dg-final { verify-sarif-file } } */ |
| 66 |
|
| 67 |
/* Use a Python script to verify various properties about the generated |
| 68 |
.sarif file: |
| 69 |
{ dg-final { run-sarif-pytest test-note-with-fix-it-hint.c "test-note-with-fix-it-hint-c.py" } } */ |