Skip to content

Commit fc87d84

Browse files
committed
D.R.Y. (again)
1 parent 1578299 commit fc87d84

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

Sources/TestingMacros/Support/Additions/FunctionDeclSyntaxAdditions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension FunctionDeclSyntax {
8787
var xcTestCompatibleSelector: ObjCSelectorPieceListSyntax? {
8888
// First, look for an @objc attribute with an explicit selector, and use
8989
// that if found.
90-
if objcAttribute = firstAttribute(named: "objc"),
90+
if let objcAttribute = attributes(named: "objc", inModuleNamed: "Swift").first,
9191
case let .objCName(objCName) = objcAttribute.arguments {
9292
if true == objCName.first?.name?.textWithoutBackticks.hasPrefix("test") {
9393
return objCName

Sources/TestingMacros/Support/Additions/WithAttributesSyntaxAdditions.swift

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,16 @@ extension WithAttributesSyntax {
102102
}
103103
}
104104

105-
/// Find the first attribute on this syntax node with the given name.
106-
///
107-
/// - Parameters:
108-
/// - name: The name of the attribute to search for.
109-
///
110-
/// - Returns: The first `AttributeSyntax` node on `self` with the given name,
111-
/// or `nil` if none was found.
112-
func firstAttribute(named name: String) -> AttributeSyntax? {
113-
attributes.lazy
114-
.compactMap { attribute in
115-
if case let .attribute(attribute) = attribute {
116-
return attribute
117-
}
118-
return nil
119-
}.first { $0.attributeNameText == name }
120-
}
121-
122105
/// The first `@available(*, noasync)` or `@_unavailableFromAsync` attribute
123106
/// on this instance, if any.
124107
var noasyncAttribute: AttributeSyntax? {
125108
availability(when: .noasync).first?.attribute
126-
?? firstAttribute(named: "_unavailableFromAsync")
109+
?? attributes(named: "_unavailableFromAsync", inModuleNamed: "Swift").first
127110
}
128111

129112
/// The first `@_unavailableInEmbedded` attribute on this instance, if any.
130113
var noembeddedAttribute: AttributeSyntax? {
131-
firstAttribute(named: "_unavailableInEmbedded")
114+
attributes(named: "_unavailableInEmbedded", inModuleNamed: "Swift").first
132115
}
133116

134117
/// Find all attributes on this node, if any, with the given name.

Tests/TestingTests/RunnerTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,11 @@ final class RunnerTests: XCTestCase {
827827

828828
func testUnavailableInEmbeddedAttribute() async throws {
829829
let testStarted = expectation(description: "Test started")
830+
#if !hasFeature(Embedded)
830831
testStarted.expectedFulfillmentCount = 3
832+
#else
833+
testStarted.isInverted = true
834+
#endif
831835
var configuration = Configuration()
832836
configuration.eventHandler = { event, _ in
833837
if case .testStarted = event.kind {

0 commit comments

Comments
 (0)