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

Mocked tests don’t run under Swift Package Manager #494

Closed
1ec5 opened this issue Nov 10, 2020 · 2 comments · Fixed by #530
Closed

Mocked tests don’t run under Swift Package Manager #494

1ec5 opened this issue Nov 10, 2020 · 2 comments · Fixed by #530
Assignees
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Nov 10, 2020

Swift Package Manager skips over several test suites that account for most of the unit tests in this repository, on all platforms, not just Linux. These tests have all been conditionally uncompiled with !SWIFT_PACKAGE because linksmt/OHHTTPStubs@563f48d doesn’t support Linux or SPM. We’re using this commit off a fork of OHHTTPStubs for AliSoftware/OHHTTPStubs#286, which introduces watchOS support, even though we don’t have a watchOS test target. Meanwhile, OHHTTPStubs v9.x does support both Linux and SPM.

This issue affects only swift test on the command line, not testing within Xcode, so the primary impact is to continuous integration.

mapbox/MapboxStatic.swift#109 shows that would be straightforward to upgrade to OHHTTPStubs v9.x, but that’ll require the fix in swiftlang/swift-package-manager#2817, which is in Xcode 12.2 (which is still a release candidate) or an equivalent Swift 5.3 image for Linux.

Here are the affected test suites:

  • AnnotationTests
  • DirectionsCredentialsTests
  • DirectionsTests
  • Most of MatchTests
  • OfflineDirectionsTests
  • RoutableMatchTest
  • Most of RouteRefreshTests
  • V5Tests
  • VisualInstructionsTests

/cc @mapbox/navigation-ios

@frederoni
Copy link
Contributor

This issue affects only swift test on the command line, not testing within Xcode, so the primary impact is to continuous integration.

A potential workaround for this could be to remove/rename the .xcodeproj before testing.
If xcodebuild doesn't find a workspace or a project, it defaults to Package.swift. I'd argue that it's cleaner and more convenient if you want to test a target OS that differs from the host OS. Instead of passing flags like these to swiftc,

-Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator"

we could:
https://github.com/mapbox/mapbox-events-ios/blob/9cefee052e846179addefeca3646e066b582c240/.circleci/config.yml#L27-L32

mkdir temp && mv MapboxMobileEvents.xcodeproj temp
xcodebuild -scheme MapboxMobileEvents test -destination "platform=iOS Simulator,name=iPhone 11,OS=latest"
mv temp/MapboxMobileEvents.xcodeproj . && rm -rf temp

Long term swift test should ofc run the full test suite on macOS/Linux, but for testing iOS/watchOS/iPadOS, xcodebuild is much more convenient.

@truburt truburt added this to the v2.0.0 milestone Feb 26, 2021
@truburt truburt added the Core label Mar 2, 2021
@truburt truburt modified the milestones: v2.0.0, v2.0.0 (GA) Mar 5, 2021
@1ec5 1ec5 modified the milestones: v2.0.0 (GA), v2.0.0 (RC) Mar 5, 2021
@azarovalex azarovalex self-assigned this Mar 22, 2021
@azarovalex
Copy link
Contributor

Looks like OHHTTPStubs don't have Linux support, it lacks LinuxMain.swift file, and even if I generate it, OHHTTPStubs imports Foundation and objc/runtime.h internally. In theory, we can use open-sourced Foundation written in Swift on Linux, but we definitely don't have objc runtime there. OHHTTPStubs uses 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 conditional compilation like this:

import OHHTTPStubs
#if SWIFT_PACKAGE
import OHHTTPStubsSwift
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants