I've run into a bit of a quandary, about why this fails to work, and I need to ask to find out if there is a reason for what I'm seeing. I can reproduce 100% of the time.
What I am trying to do:
2. Add a New File to CommandLineApp, let's call it Foo.swift:
Build, and everything works!
3. Add a new UnitTest swift class FooTests.swift:
Build Error:
Questions:
Thank you for any help with this.
What I am trying to do:
Use Swift Package Manager to generate a command line application target.
Add a Swift class/struct/function to the project
Add a UnitTest for validation
Use SPM to create a new command line project:
Code Block mkdir CommandLineTool cd CommandLineTool swift package init --type executable
2. Add a New File to CommandLineApp, let's call it Foo.swift:
Code Block import Foundation public struct Foo { public func message() -> String { return "Hello, World" } }
Build, and everything works!
3. Add a new UnitTest swift class FooTests.swift:
Code Block import XCTest @testable import CommandLineTool final class FooTests: XCTestCase { func testFooMessage() { let message = Foo().message() XCTAssertTrue(message == "Hello, world!") } }
Build Error:
Code Block Undefined symbol: CommandLineTool.Foo.message() -> Swift.String Undefined symbol: CommandLineTool.Foo.init() -> CommandLineTool.Foo
Questions:
Why does this fail?
Why can I not add a UnitTest for items added to a command line SPM project?
The same process also fails, if I use Xcode 12.4 to generate a Command Line Tool project for macOS.
Doing the exact same process is successful if I use one of the following:
Use SPM to generate a library, and I add a new Unit Test.
Use Xcode 12.4 to generate a macOS UI based App or iOS app project, then add in a UnitTest for a new swift file I add to the main application.
Thank you for any help with this.