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

Enable swift PM tests on Linux and macOS #118

Merged
merged 2 commits into from
May 25, 2022
Merged

Enable swift PM tests on Linux and macOS #118

merged 2 commits into from
May 25, 2022

Conversation

vox-humana
Copy link
Contributor

Follow up from #116

  • Removed UIKit.UIImage dependency from tests.
  • Added a simple GitHub action that runs swift test on Linux and macOS. Not sure whether it should be integrated in https://github.com/WeTransfer/WeTransfer-iOS-CI.
  • Changed the order of build steps in test target as Xcode build was failing with:

error: Cycle inside Mocker; building could produce unreliable results. This usually can be resolved by moving the target's Headers build phase before Compile Sources.

  • Had to change integration of resource files in the test target as copying them on Linux cases this crash.
  • Two tests (testMockCachePolicy and testRedirectResponse) were disabled on Linux as seems that swift-corelibs-foundation doesn't support these features.

Copy link
Contributor

@BasThomas BasThomas left a comment

Choose a reason for hiding this comment

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

This looks great! Got a few questions. Thanks for taking the time to look into this! ❤️


extension Bundle {
#if !SWIFT_PACKAGE
static let module = Bundle(for: MockedData.self)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, how does this work for the constants above if we're SWIFT_PACKAGE is YES? From what I can tell, it shouldn't compile? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SPM generates this special Bundle.module accessor (https://developer.apple.com/documentation/swift_packages/bundling_resources_with_a_swift_package) Unfortunately, it doesn't exist in non-SPM targets, so here I was trying to keep both Xcode iOS tests and SPM tests working with resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this makes sense to me! 🙂

func testRedirectResponse() {
func testRedirectResponse() throws {
#if os(Linux)
throw XCTSkip("The URLSession swift-corelibs-foundation implementation doesn't currently handle redirects directly")
Copy link
Contributor

Choose a reason for hiding this comment

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

👌. Perhaps we can even leave a reference to the issue that tracks this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the code that throws this error https://github.com/apple/swift-corelibs-foundation/blob/main/Sources/FoundationNetworking/URLSession/URLSessionTask.swift#L1037 I haven't found any open issue, seems like URLSession hasn't been fully implemented on Linux, also, not sure what's their plans in swift-corelibs-foundation

@@ -173,13 +154,13 @@ final class MockerTests: XCTestCase {
/// It should return the additional headers.
func testAdditionalHeaders() {
let expectation = self.expectation(description: "Data request should succeed")
let headers = ["testkey": "testvalue"]
let headers = ["Testkey": "testvalue"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added capitalisation to HTTP headers because Foundation on Linux does this 🤷

Copy link
Contributor

@AvdLee AvdLee left a comment

Choose a reason for hiding this comment

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

This all makes total sense to me! Thanks a lot for taking the effort to add this. No need to add the GitHub action to our CI package, it's pretty specific. All good 💪

@AvdLee AvdLee enabled auto-merge (squash) May 25, 2022 12:13
@wetransferplatform
Copy link
Collaborator

Messages
📖

View more details on Bitrise

📖 MockerTests: Executed 25 tests (0 failed, 0 retried, 0 skipped) in 1.704 seconds

SwiftLint found issues

Severity File Reason
Warning MockedData.swift:12 Types used for hosting only static members should be implemented as a caseless enum to avoid instantiation. (convenience_type)
Warning MockerTests.swift:163 Line should be 140 characters or less: currently 151 characters (line_length)
Warning MockerTests.swift:181 Line should be 140 characters or less: currently 149 characters (line_length)
Warning MockerTests.swift:239 Line should be 140 characters or less: currently 154 characters (line_length)
Warning MockerTests.swift:52 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:71 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:94 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:116 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:149 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:165 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:183 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:206 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:259 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:435 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)
Warning MockerTests.swift:469 Chained function calls should be either on the same line, or one per line. (multiline_function_chains)

Code Coverage Report

Name Coverage
Mocker.framework 86.42%

Generated by 🚫 Danger Swift against 5295a25

@AvdLee AvdLee merged commit f887c0e into WeTransfer:master May 25, 2022
@wetransferplatform
Copy link
Collaborator

Congratulations! 🎉 This was released as part of Release 2.6.0 🚀

Generated by GitBuddy

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.

4 participants