My Swift macOS project is using the Swift-Collections package via the Swift Package Manager (Xcode 13.1, Swift-Collections 1.0.2).
When the Host Application for my unit-test target is set to None, test builds fail with several Undefined symbol
errors of the form:
Undefined symbol: OrderedCollections.OrderedSet.append(A) -> (inserted: Swift.Bool, index: Swift.Int)
Seems the swift-collections package files aren't added to the test target when there's no host application, and I can't see any way to add them. If anyone can tell me if this can be solved via edits to the Package.swift
file or similar that would be great.
Incidentally, the motivation for running unit tests without a host application was the fact that code executed when launching the app is being counted in the code-coverage report, which is significantly skewing coverage to the upside. If there's a way I haven't noticed to prevent this or filter it (without source-code changes), that would also solve my issue.
Edit: This also occurs in a new test project: create new macOS project; add Swift-Collections' OrderedCollections package via File -> Add Package; add simple struct importing and using OrderedCollections, eg:
import Foundation
import OrderedCollections
struct Wut {
static func thing() {
let whatever = OrderedSet<Int>()
}
}
Set the Host application to None in the unit-test target's 'General' tab, hit cmd-U and the build fails:
Undefined symbol: OrderedCollections.OrderedSet.init() -> OrderedCollections.OrderedSet<A>
The error is telling you that Linker can't resolve the symbols for the OrderedCollections
package. When it is running the test bundle injected into the host app it can look in the host app for these symbols. When it is running without a host app you have to point the linker to the library containing the symbols.
To fix:
The plus icon below both lists is how you add the library. Here: