Skip to content

Refactor --init mode for library package support, Adds test stubs to libs #141

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

Merged
merged 1 commit into from
Mar 8, 2016

Conversation

aciidgh
Copy link
Contributor

@aciidgh aciidgh commented Feb 22, 2016

Adds two modes to --init: --init library and --init exec with executable as default if not specified.

--init exec or --init behaves same as before

--init library mode:

  • Creates this folder structure :
Creating Library package: MyAwesomePackage
Creating Package.swift
Creating Sources/
Creating Sources/MyAwesomePackage.swift
Creating Tests/
Creating Tests/LinuxMain.swift
Creating Tests/MyAwesomePackage/
Creating Tests/MyAwesomePackage/MyAwesomePackage.swift
  • Sources/MyAwesomePackage.swift contains empty struct of the same name :
struct MyAwesomePackage {

}
  • Tests/MyAwesomePackage/MyAwesomePackage.swift :
import XCTest
@testable import MyAwesomePackage

class MyAwesomePackage: XCTestCase {

    func testExample() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
    }

}

#if os(Linux)
extension MyAwesomePackage: XCTestCaseProvider {
    var allTests : [(String, () throws -> Void)] {
        return [
            ("testExample", testExample),
        ]
    }
}
#endif
  • Tests/LinuxMain.swift :
import XCTest
@testable import MyAwesomePackagetest

XCTMain([
    MyAwesomePackage(),
])

Executable currently don't support proper testing so no test stubs are generated for executables :
swift-test works properly on OSX but fails with the below error on Linux for packages containing main.swift, however works correctly for libs :

Compiling Swift Module 'MyAwesomePackagetest' (1 sources)
Linking test-Package.xctest
/home/aciid/temo/MyAwesomePackage/.build/debug/MyAwesomePackage.build/main.swift.o: In function `main':
/home/aciid/temo/MyAwesomePackage/Sources/main.swift:(.text+0x0): multiple definition of `main'
/tmp/LinuxMain-c1efa2.o:/tmp/LinuxMain-c1efa2.o:(.text+0x0): first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): swift-build-tool -f /home/aciid/temo/MyAwesomePackage/.build/debug.yaml test

@mxcl
Copy link
Contributor

mxcl commented Feb 22, 2016

Only libraries are testable at this time, it works on Darwin because we build an xctest bundle, however it would stop working if we built there were two executable modules being compiled into the bundle.

It doesn't work on Linux because we build a main into the test runner.

So at this time, I'm not sure we can merge this unless we change --init to make a library or we ask the user if they want a library or we encourage modular development by creating a library and an executable module.


I considered compiling executable modules in two parts, a module with everything except the main.swift and then the executable product with the main.swift, however this simply won't work if any non-private state exists in main.swift.


Possibly there is a solution if on Linux we compile each module as a dylib, but I'm not 100% sure how this would affect the _main symbols

@aciidgh
Copy link
Contributor Author

aciidgh commented Feb 22, 2016

how about having two modes for --init for library and executable, something like:
--init library and --init exec and defaulting to executable if not specified?

@mxcl
Copy link
Contributor

mxcl commented Feb 22, 2016

Sounds reasonable, would enjoy input from @ddunbar and @mattt.

@aciidgh aciidgh force-pushed the init_pkg_enhancements branch from 90002ed to 9d52df2 Compare February 23, 2016 11:29
@aciidgh aciidgh changed the title Add test stubs for init mode Refactor --init mode for library package support, Adds test stubs to libs Feb 23, 2016
@aciidgh
Copy link
Contributor Author

aciidgh commented Feb 23, 2016

waiting for inputs from @ddunbar and @mattt in the meanwhile @mxcl updated PR and description to add library and exec modes to --init

@aciidgh aciidgh force-pushed the init_pkg_enhancements branch from 5465061 to 7ee8a22 Compare February 26, 2016 18:51
@aciidgh
Copy link
Contributor Author

aciidgh commented Feb 26, 2016

rebased

@aciidgh aciidgh force-pushed the init_pkg_enhancements branch from 7ee8a22 to 943d8cc Compare February 26, 2016 18:54
@mxcl
Copy link
Contributor

mxcl commented Feb 26, 2016

K, looks good. Lets make it executable though since we don’t abbreviate generally here at the Fruit Company.

@aciidgh aciidgh force-pushed the init_pkg_enhancements branch from 943d8cc to 88a39e4 Compare February 27, 2016 00:25
@aciidgh
Copy link
Contributor Author

aciidgh commented Feb 27, 2016

@mxcl done

@mxcl
Copy link
Contributor

mxcl commented Feb 27, 2016

@swift-ci Please test

@aciidgh
Copy link
Contributor Author

aciidgh commented Mar 1, 2016

@mxcl is there any changes required in this PR?

@mxcl
Copy link
Contributor

mxcl commented Mar 8, 2016

We can squash and merge. I'll update the swift-3 branch if needed tomorrow.

@aciidgh aciidgh force-pushed the init_pkg_enhancements branch from 88a39e4 to f10727c Compare March 8, 2016 03:56
@aciidgh
Copy link
Contributor Author

aciidgh commented Mar 8, 2016

Rebased and squashed

@mxcl
Copy link
Contributor

mxcl commented Mar 8, 2016

@swift-ci Please test

mxcl added a commit that referenced this pull request Mar 8, 2016
Refactor --init mode for library package support, Adds test stubs to libs
@mxcl mxcl merged commit f6c8f03 into swiftlang:master Mar 8, 2016
@aciidgh aciidgh deleted the init_pkg_enhancements branch March 8, 2016 23:22
aciidgh pushed a commit to aciidgh/swift-package-manager that referenced this pull request Jan 11, 2019
[BuildSystem] Diagnose duplicate command names.
MaxDesiatov pushed a commit to MaxDesiatov/swift-package-manager that referenced this pull request Jul 6, 2020
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.

2 participants