aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/sarif-output/include-chain-1.c
blob: 442c1377b43c7843a688922c92731983cb689f94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* { dg-do compile } */
/* { dg-options "-fdiagnostics-format=sarif-file" } */

/* Verify that SARIF output can capture chains of include files in
   result locations.

   Generate two warning/note pairs, using a chain of header files.
   In textual form, we'd expect something like:

In file included from PATH/include-chain-1.h:5,
                 from PATH/include-chain-1.c:9:
PATH/include-chain-1-2.h:1:6: error: conflicting types for 'p'; have 'char'
    1 | char p;
      |      ^
In file included from PATH/include-chain-1.h:2:
PATH/include-chain-1-1.h:1:5: note: previous declaration of 'p' with type 'int'
    1 | int p;
      |     ^
PATH/include-chain-1-2.h:2:6: error: conflicting types for 'q'; have 'char'
    2 | char q;
      |      ^
PATH/include-chain-1-1.h:2:5: note: previous declaration of 'q' with type 'int'
    2 | int q;
      |     ^

    We should have two result objects (for each of 'p' and 'q'), each with
    a related location for its note, and additional related locations describing
    the include chains.  */

#include "include-chain-1.h"

/* We expect a failing compile due to the errors, but the use of 
   -fdiagnostics-format=sarif-file means there should be no output to stderr.
   DejaGnu injects this message; ignore it:
   { dg-prune-output "exit status is 1" } */

/* Verify that some JSON was written to a file with the expected name:
   { dg-final { verify-sarif-file } } */

/* Use a Python script to verify various properties about the generated
   .sarif file:
   { dg-final { run-sarif-pytest include-chain-1.c "include-chain-1.py" } } */