diff --git a/clang/test/Frontend/sarif-diagnostics.cpp b/clang/test/Frontend/sarif-diagnostics.cpp --- a/clang/test/Frontend/sarif-diagnostics.cpp +++ b/clang/test/Frontend/sarif-diagnostics.cpp @@ -1,6 +1,3 @@ -// RUN: %clang -fsyntax-only -Wall -Wextra -fdiagnostics-format=sarif %s > %t 2>&1 || true -// RUN: FileCheck -dump-input=always %s --input-file=%t - // FIXME: this test is incredibly fragile because the `main()` function // must be on line 12 in order for the CHECK lines to get the correct line // number values. @@ -9,6 +6,9 @@ // to work properly for the test coverage, which as you can imagine, is not // the best way to structure the test. We really need to introduce a better // tool than FileCheck for diff'ing JSON output like SARIF. +// +// In order to add more tests over time, we've put the RUN lines **underneath** +// the code. void main() { int i = hello; @@ -27,42 +27,386 @@ x + y; } -// CHECK: warning: diagnostic formatting in SARIF mode is currently unstable [-Wsarif-format-unstable] -// CHECK: {"$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json","runs":[{"artifacts":[{"length": -// Omit exact length of this file -// CHECK: ,"location":{"index":0,"uri":"file:// -// Omit filepath to llvm project directory -// CHECK: test/Frontend/sarif-diagnostics.cpp"},"mimeType":"text/plain","roles":["resultFile"]}],"columnKind":"unicodeCodePoints","results": -// CHECK: [{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:// -// CHECK: {"endColumn":1,"startColumn":1,"startLine":12}}}],"message":{"text":"'main' must return 'int'"},"ruleId":"{{[0-9]+}}","ruleIndex":0}, -// CHECK: {"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:// -// CHECK: {"endColumn":11,"startColumn":11,"startLine":13}}}],"message":{"text":"use of undeclared identifier -// CHECK: 'hello'"},"ruleId":"{{[0-9]+}}","ruleIndex":1},{"level":"error","locations":[{"physicalLocation":{"artifactLocation": -// CHECK: {"index":0,"uri":"file://{{.+}}"},"region":{"endColumn":17,"startColumn":17,"startLine":15}}}],"message":{"text":"invalid digit 'a' in decimal -// CHECK: constant"},"ruleId":"{{[0-9]+}}","ruleIndex":2},{"level":"warning","locations":[{"physicalLocation":{"artifactLocation": -// CHECK: {"index":0,"uri":"file://{{.+}}"},"region":{"endColumn":5,"startColumn":5,"startLine":19}}}],"message":{"text":"misleading indentation; statement is not part -// CHECK: of the previous 'if'"},"ruleId":"{{[0-9]+}}","ruleIndex":3},{"level":"note","locations":[{"physicalLocation":{"artifactLocation": -// CHECK: {"index":0,"uri":"file://{{.+}}"},"region":{"endColumn":3,"startColumn":3,"startLine":17}}}],"message":{"text":"previous statement is -// CHECK: here"},"ruleId":"{{[0-9]+}}","ruleIndex":4},{"level":"warning","locations":[{"physicalLocation":{"artifactLocation": -// CHECK: {"index":0,"uri":"file://{{.+}}"},"region":{"endColumn":10,"startColumn":10,"startLine":18}}}],"message":{"text":"unused variable -// CHECK: 'Yes'"},"ruleId":"{{[0-9]+}}","ruleIndex":5},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:// -// CHECK: {"endColumn":12,"startColumn":12,"startLine":21}}}],"message":{"text":"use of undeclared identifier -// CHECK: 'hi'"},"ruleId":"{{[0-9]+}}","ruleIndex":6},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:// -// CHECK: {"endColumn":1,"startColumn":1,"startLine":23}}}],"message":{"text":"extraneous closing brace -// CHECK: ('}')"},"ruleId":"{{[0-9]+}}","ruleIndex":7},{"level":"error","locations":[{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:// -// CHECK: {"endColumn":6,"endLine":27,"startColumn":5,"startLine":27}}},{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:// -// CHECK: {"endColumn":10,"endLine":27,"startColumn":9,"startLine":27}}},{"physicalLocation":{"artifactLocation":{"index":0,"uri":"file:// -// CHECK: {"endColumn":7,"startColumn":7,"startLine":27}}}],"message":{"text":"invalid operands to binary expression ('t1' and -// CHECK: 't1')"},"ruleId":"{{[0-9]+}}","ruleIndex":8}],"tool":{"driver":{"fullName":"","informationUri":"https://clang.llvm.org/docs/ -// CHECK: UsersManual.html","language":"en-US","name":"clang","rules":[{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"warning","rank":-1},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"note","rank":-1},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"warning","rank":-1},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription":{"text":""},"id":"{{[0-9]+}}","name":""},{"defaultConfiguration": -// CHECK: {"enabled":true,"level":"error","rank":50},"fullDescription": -// CHECK: {"text":""},"id":"{{[0-9]+}}","name":""}],"version":"{{[0-9]+\.[0-9]+\.[0-9]+}}"}}}],"version":"2.1.0"} -// CHECK: 2 warnings and 6 errors generated. \ No newline at end of file +// RUN: %clang -fsyntax-only -Wall -Wextra -fdiagnostics-format=sarif-stderr %s > %t.txt 2>&1 || true +// RUN: FileCheck -dump-input=always %s --input-file=%t.txt --check-prefixes=CHECK,COMMON + +// COMMON: warning: diagnostic formatting in SARIF mode is currently unstable [-Wsarif-format-unstable] +// CHECK: { +// CHECK: "$schema":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/sarif-schema-2.1.0.json", +// CHECK: "runs":[ +// CHECK: { +// CHECK: "artifacts":[ +// CHECK: { +// CHECK: "length":{{[0-9]+}}, +// CHECK: "location":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "mimeType":"text/plain", +// CHECK: "roles":[ +// CHECK: "resultFile" +// CHECK: ] +// CHECK: } +// CHECK: ], +// CHECK: "columnKind":"unicodeCodePoints", +// CHECK: "results":[ +// CHECK: { +// CHECK: "level":"error", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":1, +// CHECK: "startColumn":1, +// CHECK: "startLine":12 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"'main' must return 'int'" +// CHECK: }, +// CHECK: "ruleId":"3485", +// CHECK: "ruleIndex":0 +// CHECK: }, +// CHECK: { +// CHECK: "level":"error", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":11, +// CHECK: "startColumn":11, +// CHECK: "startLine":13 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"use of undeclared identifier 'hello'" +// CHECK: }, +// CHECK: "ruleId":"4632", +// CHECK: "ruleIndex":1 +// CHECK: }, +// CHECK: { +// CHECK: "level":"error", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":17, +// CHECK: "startColumn":17, +// CHECK: "startLine":15 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"invalid digit 'a' in decimal constant" +// CHECK: }, +// CHECK: "ruleId":"898", +// CHECK: "ruleIndex":2 +// CHECK: }, +// CHECK: { +// CHECK: "level":"warning", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":5, +// CHECK: "startColumn":5, +// CHECK: "startLine":19 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"misleading indentation; statement is not part of the previous 'if'" +// CHECK: }, +// CHECK: "ruleId":"1826", +// CHECK: "ruleIndex":3 +// CHECK: }, +// CHECK: { +// CHECK: "level":"note", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":3, +// CHECK: "startColumn":3, +// CHECK: "startLine":17 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"previous statement is here" +// CHECK: }, +// CHECK: "ruleId":"1746", +// CHECK: "ruleIndex":4 +// CHECK: }, +// CHECK: { +// CHECK: "level":"warning", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":10, +// CHECK: "startColumn":10, +// CHECK: "startLine":18 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"unused variable 'Yes'" +// CHECK: }, +// CHECK: "ruleId":"6593", +// CHECK: "ruleIndex":5 +// CHECK: }, +// CHECK: { +// CHECK: "level":"error", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":12, +// CHECK: "startColumn":12, +// CHECK: "startLine":21 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"use of undeclared identifier 'hi'" +// CHECK: }, +// CHECK: "ruleId":"4632", +// CHECK: "ruleIndex":6 +// CHECK: }, +// CHECK: { +// CHECK: "level":"error", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":1, +// CHECK: "startColumn":1, +// CHECK: "startLine":23 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"extraneous closing brace ('}')" +// CHECK: }, +// CHECK: "ruleId":"1400", +// CHECK: "ruleIndex":7 +// CHECK: }, +// CHECK: { +// CHECK: "level":"error", +// CHECK: "locations":[ +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":6, +// CHECK: "endLine":27, +// CHECK: "startColumn":5, +// CHECK: "startLine":27 +// CHECK: } +// CHECK: } +// CHECK: }, +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":10, +// CHECK: "endLine":27, +// CHECK: "startColumn":9, +// CHECK: "startLine":27 +// CHECK: } +// CHECK: } +// CHECK: }, +// CHECK: { +// CHECK: "physicalLocation":{ +// CHECK: "artifactLocation":{ +// CHECK: "index":0, +// CHECK: "uri":{{"file://[^"]+/clang/test/Frontend/sarif-diagnostics.cpp"}} +// CHECK: }, +// CHECK: "region":{ +// CHECK: "endColumn":7, +// CHECK: "startColumn":7, +// CHECK: "startLine":27 +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "message":{ +// CHECK: "text":"invalid operands to binary expression ('t1' and 't1')" +// CHECK: }, +// CHECK: "ruleId":"4567", +// CHECK: "ruleIndex":8 +// CHECK: } +// CHECK: ], +// CHECK: "tool":{ +// CHECK: "driver":{ +// CHECK: "fullName":"", +// CHECK: "informationUri":"https://clang.llvm.org/docs/UsersManual.html", +// CHECK: "language":"en-US", +// CHECK: "name":"clang", +// CHECK: "rules":[ +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"error", +// CHECK: "rank":50 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"3485", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"error", +// CHECK: "rank":50 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"4632", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"error", +// CHECK: "rank":50 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"898", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"warning", +// CHECK: "rank":-1 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"1826", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"note", +// CHECK: "rank":-1 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"1746", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"warning", +// CHECK: "rank":-1 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"6593", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"error", +// CHECK: "rank":50 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"4632", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"error", +// CHECK: "rank":50 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"1400", +// CHECK: "name":"" +// CHECK: }, +// CHECK: { +// CHECK: "defaultConfiguration":{ +// CHECK: "enabled":true, +// CHECK: "level":"error", +// CHECK: "rank":50 +// CHECK: }, +// CHECK: "fullDescription":{ +// CHECK: "text":"" +// CHECK: }, +// CHECK: "id":"4567", +// CHECK: "name":"" +// CHECK: } +// CHECK: ], +// CHECK: "version":"17.0.0" +// CHECK: } +// CHECK: } +// CHECK: } +// CHECK: ], +// CHECK: "version":"2.1.0" +// CHECK: } +// COMMON: 2 warnings and 6 errors generated.