-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
##### Enhancements | ||
|
||
- None. | ||
- Added support for Swift Testing. | ||
|
||
##### Bug Fixes | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Configuration | ||
import Foundation | ||
import Shared | ||
|
||
/// Retains Swift Testing declarations. | ||
/// https://developer.apple.com/xcode/swift-testing/ | ||
final class SwiftTestingRetainer: SourceGraphMutator { | ||
private let graph: SourceGraph | ||
|
||
required init(graph: SourceGraph, configuration _: Configuration, swiftVersion _: SwiftVersion) { | ||
self.graph = graph | ||
} | ||
|
||
func mutate() { | ||
for decl in graph.declarations(ofKinds: [.class, .struct]) { | ||
guard decl.location.file.importsSwiftTesting else { continue } | ||
|
||
if decl.attributes.contains("Suite") { | ||
graph.markRetained(decl) | ||
} | ||
} | ||
|
||
for decl in graph.declarations(ofKinds: [.functionFree, .functionMethodInstance, .functionMethodClass, .functionMethodStatic]) { | ||
guard decl.location.file.importsSwiftTesting else { continue } | ||
|
||
if decl.attributes.contains("Test") { | ||
graph.markRetained(decl) | ||
|
||
if let parent = decl.parent { | ||
graph.markRetained(parent) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Tests/Fixtures/Sources/RetentionFixtures/testRetainsSwiftTestingDeclarations.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#if canImport(Testing) | ||
import Testing | ||
|
||
@Test func swiftTestingFreeFunction() {} | ||
|
||
class SwiftTestingClass { | ||
@Test("displayName") func instanceMethod() {} | ||
@Test class func classMethod() {} | ||
@Test static func staticMethod() {} | ||
} | ||
|
||
@Suite struct SwiftTestingStructWithSuite { | ||
@Test func instanceMethod() {} | ||
@Test("displayName") static func staticMethod() {} | ||
} | ||
|
||
@Suite("displayName") class SwiftTestingClassWithSuite { | ||
@Test func instanceMethod() {} | ||
@Test("displayName") class func classMethod() {} | ||
@Test static func staticMethod() {} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters