Skip to content

Commit

Permalink
Use XCTExpectFailure from XCTestDynamicOverlay (#2721)
Browse files Browse the repository at this point in the history
The test store has dynamically loaded this helper for awhile now, but
now we can offload that work to another library.
  • Loading branch information
stephencelis authored Jan 23, 2024
1 parent 11184df commit 969b573
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
"revision" : "b58e6627149808b40634c4552fcf2f44d0b3ca87",
"version" : "1.1.0"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.1.0"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.1.0"),
],
targets: [
.target(
Expand Down
31 changes: 2 additions & 29 deletions Sources/ComposableArchitecture/TestStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ extension TestStore where State: Equatable {
{
var expectedWhenGivenPreviousState = current
if let updateStateToExpectedResult = updateStateToExpectedResult {
_XCTExpectFailure(strict: false) {
XCTExpectFailure(strict: false) {
do {
try Dependencies.withDependencies {
$0 = self.reducer.dependencies
Expand Down Expand Up @@ -2077,7 +2077,7 @@ extension TestStore {
case .on:
XCTFail(message, file: file, line: line)
case .off(showSkippedAssertions: true):
_XCTExpectFailure {
XCTExpectFailure {
XCTFail(
"""
Skipped assertions: …
Expand Down Expand Up @@ -2474,33 +2474,6 @@ public enum Exhaustivity: Equatable, Sendable {
public static let off = Self.off(showSkippedAssertions: false)
}

@_transparent
private func _XCTExpectFailure(
_ failureReason: String? = nil,
strict: Bool = true,
failingBlock: () -> Void
) {
#if DEBUG
guard
let XCTExpectedFailureOptions = NSClassFromString("XCTExpectedFailureOptions")
as Any as? NSObjectProtocol,
let options = strict
? XCTExpectedFailureOptions
.perform(NSSelectorFromString("alloc"))?.takeUnretainedValue()
.perform(NSSelectorFromString("init"))?.takeUnretainedValue()
: XCTExpectedFailureOptions
.perform(NSSelectorFromString("nonStrictOptions"))?.takeUnretainedValue()
else { return }

let XCTExpectFailureWithOptionsInBlock = unsafeBitCast(
dlsym(dlopen(nil, RTLD_LAZY), "XCTExpectFailureWithOptionsInBlock"),
to: (@convention(c) (String?, AnyObject, () -> Void) -> Void).self
)

XCTExpectFailureWithOptionsInBlock(failureReason, options, failingBlock)
#endif
}

extension TestStore {
@MainActor
@available(
Expand Down

0 comments on commit 969b573

Please sign in to comment.