aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-08-22 23:15:52 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-08-22 23:15:52 +0000
commitb3dd988abdd8d048ac999a5713239c95692e528c (patch)
tree22fc665b73435bbe6bd9bd57f6f3f79c7048ae8d
parent834a5bd311b4a32f89937ca5b6dd2b4111891859 (diff)
[libclang] c-index-test: Make the printing of the overrides list of a cursor in
a deterministic order, to avoid random test failures. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162408 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/Index/overrides.m4
-rw-r--r--tools/c-index-test/c-index-test.c23
2 files changed, 24 insertions, 3 deletions
diff --git a/test/Index/overrides.m b/test/Index/overrides.m
index d0447b7473..d2f1506fef 100644
--- a/test/Index/overrides.m
+++ b/test/Index/overrides.m
@@ -99,11 +99,11 @@
// RUN: c-index-test -test-load-source local %s | FileCheck %s
// CHECK: overrides.m:12:9: ObjCInstanceMethodDecl=protoMethod:12:9 [Overrides @3:9]
// CHECK: overrides.m:22:9: ObjCInstanceMethodDecl=method:22:9 [Overrides @16:9]
-// CHECK: overrides.m:23:9: ObjCInstanceMethodDecl=protoMethod:23:9 [Overrides @12:9, @8:9, @32:9, @17:9]
+// CHECK: overrides.m:23:9: ObjCInstanceMethodDecl=protoMethod:23:9 [Overrides @8:9, @12:9, @17:9, @32:9]
// CHECK: overrides.m:27:9: ObjCInstanceMethodDecl=method:27:9 (Definition) [Overrides @16:9]
// CHECK: overrides.m:28:9: ObjCClassMethodDecl=methodWithParam::28:9 (Definition) [Overrides @18:9]
// CHECK: overrides.m:32:9: ObjCInstanceMethodDecl=protoMethod:32:9 [Overrides @8:9]
-// CHECK: overrides.m:36:9: ObjCInstanceMethodDecl=protoMethod:36:9 [Overrides @12:9, @8:9, @32:9, @17:9]
+// CHECK: overrides.m:36:9: ObjCInstanceMethodDecl=protoMethod:36:9 [Overrides @8:9, @12:9, @17:9, @32:9]
// CHECK: overrides.m:50:8: ObjCInstanceMethodDecl=meth:50:8 (Definition) [Overrides @43:8]
// CHECK: overrides.m:55:8: ObjCInstanceMethodDecl=kol:55:8 Extent=[55:1 - 55:12]
// CHECK: overrides.m:65:26: ObjCInstanceMethodDecl=prop1:65:26 [Overrides @59:25] Extent=[65:26 - 65:31]
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 5df21ec2a8..2cbeadcaba 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -554,6 +554,19 @@ static void PrintCursorComments(CXTranslationUnit TU,
}
}
+typedef struct {
+ unsigned line;
+ unsigned col;
+} LineCol;
+
+static int lineCol_cmp(const void *p1, const void *p2) {
+ const LineCol *lhs = p1;
+ const LineCol *rhs = p2;
+ if (lhs->line != rhs->line)
+ return (int)lhs->line - (int)rhs->line;
+ return (int)lhs->col - (int)rhs->col;
+}
+
static void PrintCursor(CXCursor Cursor,
CommentXMLValidationData *ValidationData) {
CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
@@ -718,13 +731,21 @@ static void PrintCursor(CXCursor Cursor,
clang_getOverriddenCursors(Cursor, &overridden, &num_overridden);
if (num_overridden) {
unsigned I;
+ LineCol lineCols[50];
+ assert(num_overridden <= 50);
printf(" [Overrides ");
for (I = 0; I != num_overridden; ++I) {
CXSourceLocation Loc = clang_getCursorLocation(overridden[I]);
clang_getSpellingLocation(Loc, 0, &line, &column, 0);
+ lineCols[I].line = line;
+ lineCols[I].col = column;
+ }
+ // Make the order of the override list deterministic.
+ qsort(lineCols, num_overridden, sizeof(LineCol), lineCol_cmp);
+ for (I = 0; I != num_overridden; ++I) {
if (I)
printf(", ");
- printf("@%d:%d", line, column);
+ printf("@%d:%d", lineCols[I].line, lineCols[I].col);
}
printf("]");
clang_disposeOverriddenCursors(overridden);