Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-error.c

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