aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-11-11 00:46:43 +0000
committerTed Kremenek <kremenek@apple.com>2011-11-11 00:46:43 +0000
commita7e8a8394ccaa7a1276d32d0c16515bf4e7b486e (patch)
treeb992fe9d9712e581a8988a91220ade15deb9564f
parent8e23806863721495f9e1f84aed614f7afba774a3 (diff)
[serialized diagnostics]: add test cases for serialized diagnostics, including a test case for no issues, multiple issues, and
a single issue. Along the way, tweak c-index-test -read-diagnostics output so it is easier to tell what diagnostics are child diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144349 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/Misc/serialized-diags-no-issue.c10
-rw-r--r--test/Misc/serialized-diags-single-issue.c16
-rw-r--r--test/Misc/serialized-diags.c23
-rw-r--r--tools/c-index-test/c-index-test.c10
4 files changed, 56 insertions, 3 deletions
diff --git a/test/Misc/serialized-diags-no-issue.c b/test/Misc/serialized-diags-no-issue.c
new file mode 100644
index 0000000000..5c7da8267d
--- /dev/null
+++ b/test/Misc/serialized-diags-no-issue.c
@@ -0,0 +1,10 @@
+void foo();
+
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t
+// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s
+// RUN: rm -f %t
+
+// NOTE: it is important that this test case contains no issues. It tests
+// that serialize diagnostics work in the absence of any issues.
+
+// CHECK: Number of diagnostics: 0
diff --git a/test/Misc/serialized-diags-single-issue.c b/test/Misc/serialized-diags-single-issue.c
new file mode 100644
index 0000000000..c24531617e
--- /dev/null
+++ b/test/Misc/serialized-diags-single-issue.c
@@ -0,0 +1,16 @@
+void foo() {
+ int voodoo;
+ voodoo = voodoo + 1;
+}
+
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t
+// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s
+// RUN: rm -f %t
+
+// NOTE: it is important that this test case only contain a single issue. This test case checks
+// if we can handle serialized diagnostics that contain only one diagnostic.
+
+// CHECK: {{.*}}serialized-diags-single-issue.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized]
+// CHECK: Range: {{.*}}serialized-diags-single-issue.c:3:12 {{.*}}serialized-diags-single-issue.c:3:18
+// CHECK: +-{{.*}}serialized-diags-single-issue.c:2:13: note: initialize the variable 'voodoo' to silence this warning []
+// CHECK: +-FIXIT: {{.*}}serialized-diags-single-issue.c:2:13 - {{.*}}serialized-diags-single-issue.c:2:13): " = 0" \ No newline at end of file
diff --git a/test/Misc/serialized-diags.c b/test/Misc/serialized-diags.c
new file mode 100644
index 0000000000..31f279180f
--- /dev/null
+++ b/test/Misc/serialized-diags.c
@@ -0,0 +1,23 @@
+void foo() {
+ int voodoo;
+ voodoo = voodoo + 1;
+}
+
+void bar() {
+ int dragon;
+ dragon = dragon + 1
+}
+
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t 2>&1 /dev/null || true
+// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s
+// RUN: rm -f %t
+
+// This test case tests that we can handle multiple diagnostics which contain
+// FIXITs at different levels (one at the note, another at the main diagnostic).
+
+// CHECK: {{.*}}/serialized-diags.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized]
+// CHECK: Range: {{.*}}/serialized-diags.c:3:12 {{.*}}/serialized-diags.c:3:18
+// CHECK: +-{{.*}}/serialized-diags.c:2:13: note: initialize the variable 'voodoo' to silence this warning []
+// CHECK: +-FIXIT: ({{.*}}/serialized-diags.c:2:13 - {{.*}}/serialized-diags.c:2:13): " = 0Parse Issueexpected ';' after expression"
+// CHECK: {{.*}}/serialized-diags.c:8:22: error: expected ';' after expression []
+// CHECK: FIXIT: ({{.*}}/serialized-diags.c:8:22 - {{.*}}/serialized-diags.c:8:22): ";" \ No newline at end of file
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index eb992395f2..0860f1891e 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -2307,8 +2307,12 @@ static const char *getSeverityString(enum CXDiagnosticSeverity severity) {
}
static void printIndent(unsigned indent) {
+ if (indent == 0)
+ return;
+ fprintf(stderr, "+");
+ --indent;
while (indent > 0) {
- fprintf(stderr, " ");
+ fprintf(stderr, "-");
--indent;
}
}
@@ -2366,8 +2370,6 @@ static void printDiagnosticSet(CXDiagnosticSet Diags, unsigned indent) {
if (!Diags)
return;
- fprintf(stderr, "\n");
-
n = clang_getNumDiagnosticsInSet(Diags);
for (i = 0; i < n; ++i) {
CXSourceLocation DiagLoc;
@@ -2427,6 +2429,8 @@ static int read_diagnostics(const char *filename) {
}
printDiagnosticSet(Diags, 0);
+ fprintf(stderr, "Number of diagnostics: %d\n",
+ clang_getNumDiagnosticsInSet(Diags));
clang_disposeDiagnosticSet(Diags);
return 0;
}