[libclang] c-index-test: Make the printing of the overrides list of a cursor in

a deterministic order, to avoid random test failures.

llvm-svn: 162408
This commit is contained in:
Argyrios Kyrtzidis 2012-08-22 23:15:52 +00:00
parent 107618a6cb
commit 079ff5c6da
2 changed files with 24 additions and 3 deletions

View File

@ -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]

View File

@ -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);