New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge Test Support Module #71
Conversation
An attempt to fix #70.
@@ -1,16 +0,0 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting an old file.
@@ -24,6 +24,8 @@ | |||
CAF7FD82245C83B40081E4C3 /* IfLetSubscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAF7FD81245C83B40081E4C3 /* IfLetSubscript.swift */; }; | |||
DC07231724465D1E003A8B65 /* 02-Effects-TimersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC07231624465D1E003A8B65 /* 02-Effects-TimersTests.swift */; }; | |||
DC072322244663B1003A8B65 /* 03-Navigation-Sheet-LoadThenPresent.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC072321244663B1003A8B65 /* 03-Navigation-Sheet-LoadThenPresent.swift */; }; | |||
DC13940E2469E25C00EE1157 /* ComposableArchitecture in Frameworks */ = {isa = PBXBuildFile; productRef = DC13940D2469E25C00EE1157 /* ComposableArchitecture */; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of churn in every Xcode project since we have to remove the old, dynamic SPM library and use the new static one.
Makefile
Outdated
@@ -59,6 +59,6 @@ test-workspace: | |||
-quiet | |||
|
|||
format: | |||
swift format --in-place --recursive . | |||
swift format --ignore-unparsable-files --in-place --recursive . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift-format trips up on @convention(c)
.
private func _XCTFail(_ message: String = "", file: StaticString = #file, line: UInt = #line) { | ||
guard | ||
let _XCTest = NSClassFromString("XCTest") | ||
.flatMap(Bundle.init(for:)) | ||
.flatMap({ $0.executablePath }) | ||
.flatMap({ dlopen($0, RTLD_NOW) }) | ||
else { return } | ||
|
||
guard | ||
let _XCTFailureHandler = dlsym(_XCTest, "_XCTFailureHandler") | ||
.map({ unsafeBitCast($0, to: XCTFailureHandler.self) }) | ||
else { return } | ||
|
||
guard | ||
let _XCTCurrentTestCase = dlsym(_XCTest, "_XCTCurrentTestCase") | ||
.map({ unsafeBitCast($0, to: XCTCurrentTestCase.self) }) | ||
else { return } | ||
|
||
_XCTFailureHandler(_XCTCurrentTestCase(), true, "\(file)", line, message, nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the dark magic that allows us to hook into XCTest dynamically.
@@ -0,0 +1,3 @@ | |||
typealias XCTCurrentTestCase = @convention(c) () -> AnyObject | |||
typealias XCTFailureHandler | |||
= @convention(c) (AnyObject, Bool, UnsafePointer<CChar>, UInt, String, String?) -> Void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved these into their own file since swift-format breaks on them and we still would like TestStore.swift to be formatted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually turns out that swift-format tripped on them only when they were referenced inline (@convention(c) (...) -> ...).self
.
They format fine as type aliases!
extension Reducer { | ||
public func callAsFunction( | ||
_ state: State, | ||
_ action: Action, | ||
_ environment: Environment | ||
) -> (State, Effect<Action, Never>) { | ||
var state = state | ||
let effects = self.callAsFunction(&state, action, environment) | ||
return (state, effects) | ||
} | ||
} | ||
|
||
extension Reducer where Environment == Void { | ||
public func callAsFunction( | ||
_ state: State, | ||
_ action: Action | ||
) -> State { | ||
var state = state | ||
_ = self.callAsFunction(&state, action) | ||
return state | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted these convenience functions...it seems rare to test a reducer by calling it directly so it seems like surface area we can trim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what a journey!
An attempt to fix #70.