Skip to content
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

Merged
merged 10 commits into from May 11, 2020
Merged

Merge Test Support Module #71

merged 10 commits into from May 11, 2020

Conversation

stephencelis
Copy link
Member

An attempt to fix #70.

An attempt to fix #70.
@@ -1,16 +0,0 @@
{
Copy link
Member Author

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 */; };
Copy link
Member Author

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 .
Copy link
Member Author

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).

Comment on lines 416 to 435
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)
}
Copy link
Member Author

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
Copy link
Member Author

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.

Copy link
Member Author

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!

Comment on lines -3 to -24
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
}
}
Copy link
Member Author

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.

Copy link
Member

@mbrandonw mbrandonw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a journey!

@stephencelis stephencelis merged commit a429d9d into master May 11, 2020
@stephencelis stephencelis deleted the merge-test-support branch May 11, 2020 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge the core library with the test support library
2 participants