JohnSundell / SwiftPlate

Easily generate cross platform Swift framework projects from the command line
MIT License
1.77k stars 88 forks source link

Linux support missing from cross-platform? #17

Closed idcrook closed 7 years ago

idcrook commented 7 years ago

Noticed that Swift libraries that are to be run on Linux have one slight variation in the testing that is missing from SwiftPlate.

Swift Package Manager (swift package init --type library) does additionally the following:

In Tests/{PROJECT}Tests/{PROJECT}Tests.swift it adds:

    func testExample() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        XCTAssertEqual({PROJECT}().text, "Hello, World!")
    }
    static var allTests : [(String, ({PROJECT}Tests) -> () throws -> Void)] {
        return [
            ("testExample", testExample),
        ]
    }

the example assert is related to boilerplate code in the Sources/ implementation, but the allTests is more interesting, as that is the convention for the slightly different testing flow for Swift encountered under Linux.

For Linux it adds another, related file Tests/LinuxMain.swift. Its contents:

import XCTest
@testable import {PROJECT}Tests

XCTMain([
     testCase({PROJECT}Tests.allTests),
])

Could the "cross-platformness" of SwiftPlate be updated to include libraries on Linux?

JohnSundell commented 7 years ago

@idcrook Thanks for the very detailed issue! Super awesome πŸš€ I'd love for SwiftPlate to support Linux as well! πŸ‘

One thing is that not all libraries can support Linux (for example, if you're building a framework that depends on UIKit or some other Apple platforms-only API). So we should probably ask if the user wants to support Linux when running SwiftPlate - and if so perform the changes you listed above to the project. What do you think?

idcrook commented 7 years ago

I think that makes a lot of sense. πŸ‘ I hadn't tried all the SwiftPM init types (current 3.0.1 bundled swift package has (type: empty|library|executable|system-module)), but it already has a command line switch/option to guard it. I think being prompted about it makes sense. πŸŽ‰

JohnSundell commented 7 years ago

Alright, so let's go with that! πŸ‘ Let me know if you want to do the implementation as well πŸ˜‰

idcrook commented 7 years ago

I'll look into it in a day or two if I can.

JohnSundell commented 7 years ago

@idcrook Awesome, no preasure - just post here if you start working on it - otherwise I (or someone else) might pick it up - would be a great feature to have πŸ˜„

idcrook commented 7 years ago

I created PR #20 that add the Linux library testing support. However, there a a few caveats outlined in the PR.

JohnSundell commented 7 years ago

@idcrook Can we close this now that #20 has been merged? πŸ™‚

idcrook commented 7 years ago

Closing, with PR #20