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

Support tests that use OHHTTPStubs in Swift Package Manager #530

Merged
merged 2 commits into from
Mar 26, 2021

Conversation

azarovalex
Copy link
Contributor

Fixes #494.

Looks like OHHTTPStubs don't have Linux support because OHHTTPStubs uses objc/runtime to swizzle URLSesson methods here.

OHHTTPStubs on macOS through SMP works fine, there is a minor problem with module names – when we import OHHTTPStubs through Carthage, the name of the module is OHHTTPStubs, and when through SMP, the name is OHHTTPStubsSwift. Even though the content of the modules is the same. Currently, I'm solving this issue with a conditional compilation like this:

import OHHTTPStubs
#if SWIFT_PACKAGE
import OHHTTPStubsSwift
#endif

In theory, we can create our own empty package that will use @_exported statements and then include this everywhere, but this API is private.

Also, we need to replace every bundle creating with Bundle.module.
If you have any suggestions on how to run these tests on Linux or how to simplify import statements, feel free to add a comment.

@azarovalex azarovalex requested a review from a team March 25, 2021 11:10
Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

The changes look pretty reasonable to me, including the conditional compilation. The Bundle.module changes are fine because, elsewhere in the test target, we declare that constant conditionally for Carthage. I just have one comment about a more straightforward way to declare the conditional OHHTTPStubs dependency, but it isn’t critical.

@1ec5 1ec5 added the build label Mar 25, 2021
@1ec5 1ec5 added this to the v2.0.0 (RC) milestone Mar 25, 2021
@azarovalex azarovalex merged commit bbe54bc into main Mar 26, 2021
@azarovalex azarovalex deleted the azarovalex/ohhttpstubs-spm-support branch April 16, 2021 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mocked tests don’t run under Swift Package Manager
2 participants