[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
Thu Jun 6 07:19:50 PDT 2019


hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty.
Herald added subscribers: jsji, Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

The `%diff_sarif` lit substitution invokes `diff` with a non-portable `-I` option. The intended effect can be achieved by normalizing the inputs to `diff` beforehand. Such normalization can be done with `grep -Ev`, which is also used by other tests.

This patch applies a change similar to the one described in http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html mechanically. `%diff_sarif` is then, being unused, removed.

The changes were applied via a script, except that the expected files required small updates for changes in the length of the test files.

Note that `grep` expects text files (ending with a newline) as input. The `echo` command is used to generate a newline for the test output files, which do not have such newlines.


Repository:
  rC Clang

https://reviews.llvm.org/D62952

Files:
  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
@@ -14,9 +14,12 @@
 config.substitutions.append(('%diff_plist',
     'diff -u -w -I "<string>/" -I "<string>.:" -I "version"'))
 
-# 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 '%s|%s|%s'" %
+        ('^[[:space:]]*"uri": "file:.*%basename_t"$',
+         '^[[:space:]]*"version": ".* version .*"$',
+         '^[[:space:]]*"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 %t && echo >>%t && %normalize_sarif <%S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif >%t.expected.sed.sarif && %normalize_sarif <%t | diff -U1 -b %t.expected.sed.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 %t && echo >>%t && %normalize_sarif <%S/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif >%t.expected.sed.sarif && %normalize_sarif <%t | diff -U1 -b %t.expected.sed.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
@@ -7,7 +7,7 @@
           "fileLocation": {
             "uri": "file:sarif-multi-diagnostic-test.c"
           },
-          "length": 667,
+          "length": 771,
           "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
@@ -7,7 +7,7 @@
           "fileLocation": {
             "uri": "file:sarif-diagnostics-taint-test.c"
           },
-          "length": 415,
+          "length": 519,
           "mimeType": "text/plain",
           "roles": [
             "resultFile"


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


More information about the cfe-commits mailing list