Skip to content

Commit

Permalink
Fix ObjC-interop logic in the isTestCandidate indexing method
Browse files Browse the repository at this point in the history
A compile-time conditional had previously been introduced to prevent
`private` test methods from being considered test candidates. This
conditional was not working as intended, however, because the header
providing the required preprocessor flag was not being included.

Several number of issues with the non-Objc-interop test case have also
been fixed.
  • Loading branch information
briancroom committed Jun 20, 2016
1 parent 2e9f13e commit 29af9f8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
12 changes: 6 additions & 6 deletions lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,10 @@ static bool isTestCandidate(ValueDecl *D) {
return false;

// 2. ...on a class or extension (not a struct)...
auto NTD = getNominalParent(D);
if (!NTD)
auto parentNTD = getNominalParent(D);
if (!parentNTD)
return false;
if (!isa<ClassDecl>(NTD))
if (!isa<ClassDecl>(parentNTD))
return false;

// 3. ...that returns void...
Expand All @@ -825,10 +825,10 @@ static bool isTestCandidate(ValueDecl *D) {

// 5. ...is of at least 'internal' accessibility (unless we can use
// Objective-C reflection)...
#if SWIFT_OBJC_INTEROP
if (D->getFormalAccess() < Accessibility::Internal)
if (!D->getASTContext().LangOpts.EnableObjCInterop &&
(D->getFormalAccess() < Accessibility::Internal ||
parentNTD->getFormalAccess() < Accessibility::Internal))
return false;
#endif

// 6. ...and starts with "test".
if (FD->getName().str().startswith("test"))
Expand Down
2 changes: 1 addition & 1 deletion test/SourceKit/Indexing/index_is_test_candidate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct MyStruct {
func test_startsWithTest_takesNoParams_returnsVoid_butIsDefinedOnAStruct() {}
}

private class MyPrivateClass() {
private class MyPrivateClass {
func test_startsWithTest_takesNoParams_returnsVoid_butIsPrivate() {}
}

Expand Down
51 changes: 38 additions & 13 deletions test/SourceKit/Indexing/index_is_test_candidate.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,67 @@
key.kind: source.lang.swift.decl.function.free,
key.name: "test_takesNoParams_andReturnsVoid_butIsNotAnInstanceMethod()",
key.usr: "s:F23index_is_test_candidate58test_takesNoParams_andReturnsVoid_butIsNotAnInstanceMethodFT_T_",
key.line: 4,
key.line: 10,
key.column: 6
},
{
key.kind: source.lang.swift.decl.struct,
key.name: "MyStruct",
key.usr: "s:V23index_is_test_candidate8MyStruct",
key.line: 12,
key.column: 8,
key.entities: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_takesNoParams_returnsVoid_butIsDefinedOnAStruct()",
key.usr: "s:FV23index_is_test_candidate8MyStruct67test_startsWithTest_takesNoParams_returnsVoid_butIsDefinedOnAStructFT_T_",
key.line: 13,
key.column: 8
}
]
},
{
key.kind: source.lang.swift.decl.class,
key.name: "MyPrivateClass",
key.usr: "s:C23index_is_test_candidateP33_E06F4E7BC5F577AB6E2EC6D3ECA1C8B914MyPrivateClass",
key.line: 6,
key.column: 15
key.line: 16,
key.column: 15,
key.entities: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_takesNoParams_returnsVoid_butIsPrivate()",
key.usr: "s:FC23index_is_test_candidateP33_E06F4E7BC5F577AB6E2EC6D3ECA1C8B914MyPrivateClass58test_startsWithTest_takesNoParams_returnsVoid_butIsPrivateFT_T_",
key.line: 17,
key.column: 8
}
]
},
{
key.kind: source.lang.swift.decl.class,
key.name: "MyClass",
key.usr: "s:C23index_is_test_candidate7MyClass",
key.line: 10,
key.line: 20,
key.column: 14,
key.entities: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "doesNotStartWithTest()",
key.usr: "s:FC23index_is_test_candidate7MyClass20doesNotStartWithTestFT_T_",
key.line: 11,
key.line: 21,
key.column: 8
},
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_butTakesAParam(param:)",
key.usr: "s:FC23index_is_test_candidate7MyClass34test_startsWithTest_butTakesAParamFT5paramSi_T_",
key.line: 12,
key.line: 22,
key.column: 8,
key.entities: [
{
key.kind: source.lang.swift.ref.struct,
key.name: "Int",
key.usr: "s:Si",
key.line: 12,
key.line: 22,
key.column: 50
}
]
Expand All @@ -58,14 +83,14 @@
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_andTakesNoParams_butReturnsNonVoid()",
key.usr: "s:FC23index_is_test_candidate7MyClass54test_startsWithTest_andTakesNoParams_butReturnsNonVoidFT_Si",
key.line: 13,
key.line: 23,
key.column: 8,
key.entities: [
{
key.kind: source.lang.swift.ref.struct,
key.name: "Int",
key.usr: "s:Si",
key.line: 13,
key.line: 23,
key.column: 68
}
]
Expand All @@ -74,22 +99,22 @@
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_takesNoParams_andReturnsVoid_butIsPrivate()",
key.usr: "s:FC23index_is_test_candidate7MyClassP33_E06F4E7BC5F577AB6E2EC6D3ECA1C8B961test_startsWithTest_takesNoParams_andReturnsVoid_butIsPrivateFT_T_",
key.line: 14,
key.column: 16,
key.line: 24,
key.column: 16
},
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_takesNoParams_returnsVoid()",
key.usr: "s:FC23index_is_test_candidate7MyClass45test_startsWithTest_takesNoParams_returnsVoidFT_T_",
key.line: 15,
key.line: 25,
key.column: 8,
key.is_test_candidate: 1
},
{
key.kind: source.lang.swift.decl.function.method.instance,
key.name: "test_startsWithTest_takesNoParams_returnsVoid_andThrows()",
key.usr: "s:FC23index_is_test_candidate7MyClass55test_startsWithTest_takesNoParams_returnsVoid_andThrowsFzT_T_",
key.line: 16,
key.line: 26,
key.column: 8,
key.is_test_candidate: 1
}
Expand Down

0 comments on commit 29af9f8

Please sign in to comment.