[PATCH] D62952: [analyzer][tests] Use normalize_sarif in place of diff_sarif

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 19 07:38:24 PDT 2019


hubert.reinterpretcast updated this revision to Diff 205590.
hubert.reinterpretcast added a comment.

Update based on review comments from D62949 <https://reviews.llvm.org/D62949> as confirmed in D62952 <https://reviews.llvm.org/D62952>

Normalized versions of the reference expected SARIF output files were
checked in under r363788. The patch has been updated with that revision
as the base. Made the SARIF output generation produce a newline at the
end of the file, and modified the RUN lines in the manner discussed.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62952/new/

https://reviews.llvm.org/D62952

Files:
  lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
  test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
  test/Analysis/diagnostics/sarif-diagnostics-taint-test.c
  test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
  test/Analysis/lit.local.cfg


Index: test/Analysis/lit.local.cfg
===================================================================
--- test/Analysis/lit.local.cfg
+++ test/Analysis/lit.local.cfg
@@ -17,9 +17,12 @@
          '^[[:space:]]*<string>/.*</string>[[:space:]]*$',
          '^[[:space:]]*<string>.:.*</string>[[:space:]]*$')))
 
-# Diff command for testing SARIF output to reference output.
-config.substitutions.append(('%diff_sarif',
-    '''diff -U1 -w -I ".*file:.*%basename_t" -I '"version":' -I "2\.0\.0\-csd\.[0-9]*\.beta\."'''))
+# Filtering command for testing SARIF output against reference output.
+config.substitutions.append(('%normalize_sarif',
+    "grep -Ev '^[[:space:]]*(%s|%s|%s)[[:space:]]*$'" %
+        ('"uri": "file:.*%basename_t"',
+         '"version": ".* version .*"',
+         '"version": "2\.0\.0-csd\.[0-9]*\.beta\.[0-9-]{10}"')))
 
 if not config.root.clang_staticanalyzer:
     config.unsupported = True
Index: test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
===================================================================
--- test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
+++ test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %diff_sarif %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
 #include "../Inputs/system-header-simulator.h"
 
 int atoi(const char *nptr);
Index: test/Analysis/diagnostics/sarif-diagnostics-taint-test.c
===================================================================
--- test/Analysis/diagnostics/sarif-diagnostics-taint-test.c
+++ test/Analysis/diagnostics/sarif-diagnostics-taint-test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %diff_sarif %S/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif -
 #include "../Inputs/system-header-simulator.h"
 
 int atoi(const char *nptr);
Index: test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
===================================================================
--- test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
+++ test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
@@ -6,7 +6,7 @@
         {
           "fileLocation": {
           },
-          "length": 667,
+          "length": 686,
           "mimeType": "text/plain",
           "roles": [
             "resultFile"
Index: test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
===================================================================
--- test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
+++ test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
@@ -6,7 +6,7 @@
         {
           "fileLocation": {
           },
-          "length": 415,
+          "length": 434,
           "mimeType": "text/plain",
           "roles": [
             "resultFile"
Index: lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===================================================================
--- lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -345,5 +345,5 @@
        "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-11-28"},
       {"version", "2.0.0-csd.2.beta.2018-11-28"},
       {"runs", json::Array{createRun(Diags)}}};
-  OS << llvm::formatv("{0:2}", json::Value(std::move(Sarif)));
+  OS << llvm::formatv("{0:2}\n", json::Value(std::move(Sarif)));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62952.205590.patch
Type: text/x-patch
Size: 4093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190619/d89d3836/attachment.bin>


More information about the cfe-commits mailing list