Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Nimble/Adapters/NMBExpectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private func from(objcMatcher: NMBMatcher) -> Matcher<NSObject> {

// Equivalent to Expectation, but for Nimble's Objective-C interface
public final class NMBExpectation: NSObject, Sendable {
internal let _actualBlock: @Sendable () -> NSObject?
internal let _actualBlock: @Sendable () -> sending NSObject?
internal let _negative: Bool
internal let _file: FileString
internal let _line: UInt
Expand Down
4 changes: 3 additions & 1 deletion Sources/Nimble/Matchers/AllPass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ extension NMBMatcher {
)
}

let expr = Expression(expression: ({ nsObjects }), location: location)
let immutableCollection = nsObjects

let expr = Expression(expression: ({ immutableCollection }), location: location)
let pred: Matcher<[NSObject]> = createMatcher(Matcher { expr in
return matcher.satisfies(({ try expr.evaluate() }), location: expr.location).toSwift()
})
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nimble/Matchers/BeCloseTo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private func beCloseTo(
}

#if canImport(Darwin)
public class NMBObjCBeCloseToMatcher: NMBMatcher {
public final class NMBObjCBeCloseToMatcher: NMBMatcher, @unchecked Sendable {
private let _expected: NSNumber

fileprivate init(expected: NSNumber, within: CDouble) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Nimble/Matchers/BeEmpty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ extension NMBMatcher {
let expr = Expression(expression: { value }, location: location)
return try beEmpty().satisfies(expr).toObjectiveC()
} else if let value = actualValue as? NSString {
let expr = Expression(expression: { value }, location: location)
let stringValue = String(value)
let expr = Expression(expression: { stringValue }, location: location)
return try beEmpty().satisfies(expr).toObjectiveC()
} else if let actualValue = actualValue {
let badTypeErrorMsg = "be empty (only works for NSArrays, NSSets, NSIndexSets, NSDictionaries, NSHashTables, and NSStrings)"
Expand Down
9 changes: 7 additions & 2 deletions Sources/Nimble/Matchers/Contain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ public func contain(_ substrings: NSString...) -> Matcher<NSString> {
}

public func contain(_ substrings: [NSString]) -> Matcher<NSString> {
let stringSubstrings = substrings.map { String($0) }
return Matcher.simple("contain <\(arrayAsString(substrings))>") { actualExpression in
guard let actual = try actualExpression.evaluate() else { return .fail }
let actualString = String(actual)

let matches = substrings.allSatisfy { actual.range(of: $0.description).length != 0 }
let matches = stringSubstrings.allSatisfy { string in
actualString.contains(string)
}
return MatcherStatus(bool: matches)
}
}
Expand Down Expand Up @@ -115,7 +119,8 @@ extension NMBMatcher {
let expectedOptionals: [Any?] = expected.map({ $0 as Any? })
return try contain(expectedOptionals).satisfies(expr).toObjectiveC()
} else if let value = actualValue as? NSString {
let expr = Expression(expression: ({ value as String }), location: location)
let stringValue = String(value)
let expr = Expression(expression: ({ stringValue }), location: location)
// swiftlint:disable:next force_cast
return try contain(expected as! [String]).satisfies(expr).toObjectiveC()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nimble/Matchers/Matcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public class NMBMatcher: NSObject, @unchecked Sendable {
self.init(matcher: predicate)
}

func satisfies(_ expression: @escaping @Sendable () throws -> NSObject?, location: SourceLocation) -> NMBMatcherResult {
func satisfies(_ expression: @escaping @Sendable () throws -> sending NSObject?, location: SourceLocation) -> NMBMatcherResult {
let expr = Expression(expression: expression, location: location)
do {
return try self.matcher(expr)
Expand Down
4 changes: 2 additions & 2 deletions Tests/NimbleTests/Matchers/BeAKindOfTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Nimble
import NimbleSharedTestHelpers
#endif

private class TestNull: NSNull {}
private final class TestNull: NSNull, @unchecked Sendable {}
private protocol TestProtocol {}
private class TestClassConformingToProtocol: TestProtocol {}
private final class TestClassConformingToProtocol: TestProtocol {}
private struct TestStructConformingToProtocol: TestProtocol {}

final class BeAKindOfSwiftTest: XCTestCase {
Expand Down
Loading