Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-labelled-ranges.c

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