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

[Swift 3.0] swift test fails with fatal error: use of unimplemented initializer 'init(invocation:)' #600

Closed
norio-nomura opened this issue Sep 3, 2016 · 10 comments · Fixed by #687

Comments

@norio-nomura
Copy link
Contributor

Using swift-3.0 branch, swift test fails on macOS as following:

$ swift build
Cloning https://github.com/norio-nomura/Nimble
HEAD is now at 8ed5cb9 Merge pull request #6 from ikesyo/swift3-beta-6
Resolved version: 5.0.0-alpha.30p6
Compile Swift Module 'Nimble' (46 sources)
Compile Swift Module 'Quick' (21 sources)
$ swift test
Compile Swift Module 'QuickTests' (20 sources)
Linking ./.build/debug/QuickPackageTests.xctest/Contents/MacOS/QuickPackageTests
Test Suite 'All tests' started at 2016-09-03 11:15:16.837
Test Suite 'QuickPackageTests.xctest' started at 2016-09-03 11:15:16.838
Test Suite 'AfterEachTests' started at 2016-09-03 11:15:16.838
Test Case '-[QuickTests.AfterEachTests testAfterEachIsExecutedInTheCorrectOrder]' started.
/Users/norio/github/Quick/Sources/Quick/QuickSpec.swift: 6: 12: fatal error: use of unimplemented initializer 'init(invocation:)' for class 'Quick.QuickSpec'

Current implementation of Quick needs instance of QuickSpec for enumerating test methods. But It fails to create instance in Swift.
Because:

  • QuickSpec.swift is used instead of QuickSpec.m because building Objective-C is not supported by Swift Package Manager
  • NSInvocation is unimplemented on Swift
  • Swift implicitly generates codes for catching calls of init(invocation:) that uses unimplemented type in Swift
  • The wrapper function is generated if public required override init() is declared in QuickSpec
  • init(invocation:) is called from init() by superclass of XCTestCase

Call stack on fatal error:

$ lldb `xcrun -find xctest` -- .build/debug/QuickPackageTests.xctest
(lldb) target create "/Applications/Xcode-beta.app/Contents/Developer/usr/bin/xctest"
Current executable set to '/Applications/Xcode-beta.app/Contents/Developer/usr/bin/xctest' (x86_64).
(lldb) settings set -- target.run-args  ".build/debug/QuickPackageTests.xctest"
(lldb) process launch
Process 92118 launched: '/Applications/Xcode-beta.app/Contents/Developer/usr/bin/xctest' (x86_64)
Test Suite 'All tests' started at 2016-09-03 12:01:26.126
Test Suite 'QuickPackageTests.xctest' started at 2016-09-03 12:01:26.127
Test Suite 'AfterEachTests' started at 2016-09-03 12:01:26.127
Test Case '-[QuickTests.AfterEachTests testAfterEachIsExecutedInTheCorrectOrder]' started.
/Users/norio/github/swift-dev/SourceKitten/Carthage/Checkouts/Commandant/Carthage/Checkouts/Quick/Sources/Quick/QuickSpec.swift: 6: 12: fatal error: use of unimplemented initializer 'init(invocation:)' for class 'Quick.QuickSpec'
Process 92118 stopped
* thread #1: tid = 0xd1dcf, 0x0000000104996f13 QuickPackageTests`QuickSpec.init(invocation=<unavailable>) -> QuickSpec + 163 at QuickSpec.swift:6, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000104996f13 QuickPackageTests`QuickSpec.init(invocation=<unavailable>) -> QuickSpec + 163 at QuickSpec.swift:6
   3    // NOTE: This file is not intended to be included in the Xcode project or CocoaPods.
   4    //       It is picked up by the Swift Package Manager during its build process.
   5    
-> 6    open class QuickSpec: XCTestCase {
   7        open func spec() {}
   8    
   9    #if os(Linux)
(lldb) bt
* thread #1: tid = 0xd1dcf, 0x0000000104996f13 QuickPackageTests`QuickSpec.init(invocation=<unavailable>) -> QuickSpec + 163 at QuickSpec.swift:6, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x0000000104996f13 QuickPackageTests`QuickSpec.init(invocation=<unavailable>) -> QuickSpec + 163 at QuickSpec.swift:6
    frame #1: 0x0000000104996f8d QuickPackageTests`@objc QuickSpec.init(invocation : NSInvocation?) -> QuickSpec + 45 at QuickSpec.swift:0
    frame #2: 0x00000001049962a1 QuickPackageTests`QuickSpec.init() -> QuickSpec + 49 at QuickSpec.swift:18
    frame #3: 0x000000010491c1cc QuickPackageTests`FunctionalTests_AfterEachSpec.init() -> FunctionalTests_AfterEachSpec + 28 at AfterEachTests.swift:0
    frame #4: 0x000000010491c19c QuickPackageTests`FunctionalTests_AfterEachSpec.__allocating_init() -> FunctionalTests_AfterEachSpec + 44 at AfterEachTests.swift:0
    frame #5: 0x00000001049967b9 QuickPackageTests`static QuickSpec.gatherExamplesIfNeeded(self=QuickTests.FunctionalTests_AfterEachSpec) -> () + 185 at QuickSpec.swift:44
    frame #6: 0x00000001049964e8 QuickPackageTests`static QuickSpec.allTests.getter(self=QuickTests.FunctionalTests_AfterEachSpec) + 424 at QuickSpec.swift:29
    frame #7: 0x0000000104917836 QuickPackageTests`(specClasses=1 value, hadUnexpectedFailure=0x000000010035c3f0, executionCount=0x000000010035c3d0) -> TestRun?).(closure #1) + 230 at SpecRunner.swift:18
    frame #8: 0x0000000104937516 QuickPackageTests`(closure=0x0000000104917af0 QuickPackageTests`partial apply forwarder for QuickTests.(qck_runSpecs (Swift.Array<Quick.QuickSpec.Type>) -> Swift.Optional<QuickTests.TestRun>).(closure #1) at SpecRunner.swift) throws -> ()) -> ()).(closure #2) + 54 at AssertionRecorder.swift:54
    frame #9: 0x000000010498ebb2 QuickPackageTests`ExceptionCapture.tryBlock(unsafeBlock=0x0000000104937590 QuickPackageTests`partial apply forwarder for Nimble.(withAssertionHandler (Nimble.AssertionHandler, closure : () throws -> ()) -> ()).(closure #2) at AssertionRecorder.swift, self=0x0000000100216a80) -> ()) -> () + 50 at ExceptionCapture.swift:24
    frame #10: 0x000000010493726f QuickPackageTests`withAssertionHandler(tempAssertionHandler=0x00000001002845f0, closure=0x0000000104917af0 QuickPackageTests`partial apply forwarder for QuickTests.(qck_runSpecs (Swift.Array<Quick.QuickSpec.Type>) -> Swift.Optional<QuickTests.TestRun>).(closure #1) at SpecRunner.swift) throws -> ()) -> () + 623 at AssertionRecorder.swift:55
    frame #11: 0x0000000104937827 QuickPackageTests`gatherExpectations(silently=true, closure=0x0000000104917af0 QuickPackageTests`partial apply forwarder for QuickTests.(qck_runSpecs (Swift.Array<Quick.QuickSpec.Type>) -> Swift.Optional<QuickTests.TestRun>).(closure #1) at SpecRunner.swift) -> ()) -> [AssertionRecord] + 583 at AssertionRecorder.swift:80
    frame #12: 0x00000001049378f9 QuickPackageTests`gatherFailingExpectations(silently=true, closure=0x0000000104917af0 QuickPackageTests`partial apply forwarder for QuickTests.(qck_runSpecs (Swift.Array<Quick.QuickSpec.Type>) -> Swift.Optional<QuickTests.TestRun>).(closure #1) at SpecRunner.swift) -> ()) -> [AssertionRecord] + 73 at AssertionRecorder.swift:96
    frame #13: 0x000000010491760b QuickPackageTests`qck_runSpecs(specClasses=1 value) -> TestRun? + 283 at SpecRunner.swift:27
    frame #14: 0x00000001049174e3 QuickPackageTests`qck_runSpec(specClass=QuickTests.FunctionalTests_AfterEachSpec) -> TestRun? + 67 at SpecRunner.swift:6
    frame #15: 0x000000010491c4a5 QuickPackageTests`AfterEachTests.testAfterEachIsExecutedInTheCorrectOrder(self=0x0000000100280720) -> () + 117 at AfterEachTests.swift:78
    frame #16: 0x000000010491c8c2 QuickPackageTests`@objc AfterEachTests.testAfterEachIsExecutedInTheCorrectOrder() -> () + 34 at AfterEachTests.swift:0
    frame #17: 0x00007fff8d5c3a6c CoreFoundation`__invoking___ + 140
    frame #18: 0x00007fff8d5c38fe CoreFoundation`-[NSInvocation invoke] + 286
    frame #19: 0x0000000100021ac1 XCTest`__24-[XCTestCase invokeTest]_block_invoke_2 + 481
    frame #20: 0x000000010005aafb XCTest`-[XCTestContext performInScope:] + 190
    frame #21: 0x00000001000218cd XCTest`-[XCTestCase invokeTest] + 255
    frame #22: 0x00000001000220e6 XCTest`-[XCTestCase performTest:] + 457
    frame #23: 0x000000010001f1ef XCTest`-[XCTestSuite performTest:] + 491
    frame #24: 0x000000010001f1ef XCTest`-[XCTestSuite performTest:] + 491
    frame #25: 0x000000010001f1ef XCTest`-[XCTestSuite performTest:] + 491
    frame #26: 0x0000000100032dfc XCTest`-[XCTestObservationCenter _observeTestExecutionForBlock:] + 602
    frame #27: 0x000000010005c112 XCTest`_XCTestMain + 1050
    frame #28: 0x000000010000174f xctest`___lldb_unnamed_symbol3$$xctest + 362
    frame #29: 0x00007fff8bfc65ad libdyld.dylib`start + 1
(lldb) 

This is that I can't resolve on #510 and is part of description written in #510 (comment).

@modocache
Copy link
Member

Thanks for the great write-up! This is a tough issue to solve, I think. Perhaps we can work around it using the SwiftPM macro? I think it was #if __SWIFTPM__ or something...

@karagraysen
Copy link

Any progress on this?

@jeffh
Copy link
Member

jeffh commented Nov 22, 2016

Closing, this was during the work on #510, but was superseded by #601.

@jeffh jeffh closed this as completed Nov 22, 2016
@norio-nomura
Copy link
Contributor Author

Has this problem been solved already?

@ikesyo
Copy link
Member

ikesyo commented Nov 22, 2016

This should not be resolved yet. We can't use Quick with SwiftPM on macOS now.

@ikesyo ikesyo reopened this Nov 22, 2016
@karagraysen
Copy link

That's kind of unrelated to this issue, no? Can we file a new issue with details specific to SPM?

@ikesyo
Copy link
Member

ikesyo commented Nov 22, 2016

I believe this issue is already specific to SwiftPM as @norio-nomura reported originally.

@wongzigii
Copy link
Member

wongzigii commented Nov 22, 2016

I am getting this error after swift test. Is that means Nimble is not imported properly with SPM?

$ swift test
Compile Swift Module `QuickTests` (20 sources)
/Users/Wongzigii/Quick/Tests/QuickTests/QuickAfterSuiteTests/AfterSuiteTests.swift:3:8: error: no such module 'Nimble'
import Nimble
       ^
/Users/Wongzigii/Quick/Tests/QuickTests/QuickAfterSuiteTests/AfterSuiteTests.swift:3:8: error: no such module 'Nimble'
import Nimble
       ^
<unknown>:0: error: build had 1 command failures
error: exit(1): /home/zigii/swift/usr/bin/swift-build-tool -f /home/zigii/Quick/.build/debug.yaml test

Ubuntu 16.04 / Quick 1.0.0 / Swift 3.0.1

@jeffh
Copy link
Member

jeffh commented Nov 29, 2016 via email

@ikesyo
Copy link
Member

ikesyo commented Jan 16, 2017

@jeffh

I'm not sure if users of Quick in Linux has this issue

SwiftPM does not build the test suites of dependencies, so that should not affect Quick users on Linux.

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.

6 participants