Unit testing a mixed Swift/Objective-C OS X framework fails when test target contains only ObjC

Originator:armadsen
Number:rdar://23790191 Date Originated:07-Dec-2015 03:09 PM
Status:Resolved Resolved:20-Nov-2016 9:08 AM
Product:Developer Tools Product Version:7.1.1 (7B1005)
Classification:Other Bug Reproducible:Always
 
Summary:
I have an OS X framework which I'm slowly migrating to Swift. As it stands, the framework contains both Objective-C and Swift, which works fine. The framework Xcode project also contains a unit test target, implemented entirely in Objective-C.

When tests are run, the test fails with the following error:

"Test target MixedFrameworkTests encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)".

Console reveals that the error is actually that libSwiftCore.dylib can't be loaded when loading the test bundle.

Adding an (empty) Swift class to the test target convinces Xcode to copy libSwiftCore.dylib, etc. into the test bundle, and the problem goes away.

Steps to Reproduce:
1. Create a new OS X framework project. Select Objective-C for the language, and check the "include unit tests" option.
2. Add a Swift file which defines a public class with public methods to the framework.
3. Import the framework into the test target's test case using @import MyFramework;
4. Add a simple unit test that exercises the framework's API.
5. Run the unit tests.

Expected Results:
The unit test bundle builds successfully and the test succeeds.

Actual Results:
Building the test target succeeds, but running the tests fails with:

Test target MixedFrameworkTests encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)



Version:
Xcode 7.1.1 (7B1005), OS X 10.11.1 (15B42)

Notes:
As mentioned in the summary, this problem can be worked around by adding an (empty) Swift class to the test target. This causes the test target build to include a 'Copy Swift standard libraries' build phase, and the test succeeds.

Two very simple example projects that demonstrate bug are available:

https://www.dropbox.com/s/asz4uh7bh3ozly5/MixedFrameworkBroken.zip?dl=0
https://www.dropbox.com/s/0txyyuyyvieqvap/MixedFrameworkWorks.zip?dl=0

MixedFrameworkBroken.zip is a project with a mixed Objective-C / Swift framework and a pure-Objective-C test target. Running the test fails. MixedFrameworkWorks.zip contains the same project with only one change: the addition of a Swift file (DummySwiftClass.swift) to the test target. This addition causes the tests to succeed.

Comments

Did you have any feedback from Apple on this?

By phillips1988 at March 14, 2016, 11:22 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!