Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-no-column.c

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