Generated Xcode project is not testable

I'm building a server using SwiftNIO and have separated it into Core and Server modules using SPM. (You can find it here). I'm attempting to add tests and, when using the generated Xcode projects, the main server is not built with testability enabled. Can I get that turned on using the generated Xcode project? From what I can tell it's supposed to be supported.

Additionally, even after changing my code to (temporarily) make things public for testing, building my server executable for testing using Xcode or swift test fails with an Undefined symbols error:

Undefined symbols for architecture x86_64:
  "protocol witness table for DragonflyServer.PacketDecoder : NIO.ByteToMessageDecoder in DragonflyServer", referenced from:
      implicit closure #1 () throws -> () in DragonflyServerTests.DragonflyServerTests.testPacketDecoder() throws -> () in DragonflyServerTests.swift.o
  "DragonflyServer.PacketDecoder.__allocating_init() -> DragonflyServer.PacketDecoder", referenced from:
      closure #1 () -> DragonflyServer.PacketDecoder in implicit closure #1 () throws -> () in DragonflyServerTests.DragonflyServerTests.testPacketDecoder() throws -> () in DragonflyServerTests.swift.o
  "type metadata accessor for DragonflyServer.PacketDecoder", referenced from:
      implicit closure #1 () throws -> () in DragonflyServerTests.DragonflyServerTests.testPacketDecoder() throws -> () in DragonflyServerTests.swift.o
      closure #1 () -> DragonflyServer.PacketDecoder in implicit closure #1 () throws -> () in DragonflyServerTests.DragonflyServerTests.testPacketDecoder() throws -> () in DragonflyServerTests.swift.o
  "type metadata for DragonflyServer.Packet", referenced from:
      DragonflyServerTests.DragonflyServerTests.testPacketDecoder() throws -> () in DragonflyServerTests.swift.o
      type metadata accessor for [DragonflyServer.Packet] in DragonflyServerTests.swift.o
      lazy protocol witness table accessor for type DragonflyServer.Packet and conformance DragonflyServer.Packet : Swift.Equatable in DragonflyServer in DragonflyServerTests.swift.o
  "protocol conformance descriptor for DragonflyServer.Packet : Swift.Equatable in DragonflyServer", referenced from:
      lazy protocol witness table accessor for type DragonflyServer.Packet and conformance DragonflyServer.Packet : Swift.Equatable in DragonflyServer in DragonflyServerTests.swift.o
ld: symbol(s) not found for architecture x86_64

I've tried a variety of combinations of dependencies for my test target and none them let it build. Any ideas?

You can’t link executable targets in unit tests. Instead, move everything except the “main function” in a library target. Example: https://github.com/apple/swift-package-manager/blob/master/Sources/swift-build/main.swift

—> https://bugs.swift.org/browse/SR-9359 and https://bugs.swift.org/browse/SR-1393

Terms of Service

Privacy Policy

Cookie Policy