Problem
All MistDemoTests files use @testable import MistDemo, but MistDemo is declared as an .executableTarget in Examples/MistDemo/Package.swift. Executable targets do not produce importable modules, so the test suite fails to compile with:
Unable to resolve module dependency: 'MistDemo'
@testable import MistDemo
^
This has been broken since the tests were introduced in alpha.4 but was only surfaced when actually running swift test in the MistDemo example.
Root Cause
In Examples/MistDemo/Package.swift, MistDemo is declared as:
.executableTarget(
name: "MistDemo",
...
)
Swift Package Manager does not expose executable targets as importable modules, so test targets cannot @testable import them.
Fix
Split MistDemo into:
MistDemo library target — all current source files in Sources/MistDemo/ except the @main entry point
- A thin executable target (e.g.
MistDemoEntry) — contains only MistDemo.swift (the @main struct), depends on the MistDemo library, and is wired to the mistdemo product
Then MistDemoTests can @testable import MistDemo from the library without any changes to the test files.
Affected Files
Examples/MistDemo/Package.swift — target restructuring
Examples/MistDemo/Sources/MistDemo/MistDemo.swift — move to new entry-point target directory
Problem
All
MistDemoTestsfiles use@testable import MistDemo, butMistDemois declared as an.executableTargetinExamples/MistDemo/Package.swift. Executable targets do not produce importable modules, so the test suite fails to compile with:This has been broken since the tests were introduced in alpha.4 but was only surfaced when actually running
swift testin the MistDemo example.Root Cause
In
Examples/MistDemo/Package.swift,MistDemois declared as:Swift Package Manager does not expose executable targets as importable modules, so test targets cannot
@testable importthem.Fix
Split
MistDemointo:MistDemolibrary target — all current source files inSources/MistDemo/except the@mainentry pointMistDemoEntry) — contains onlyMistDemo.swift(the@mainstruct), depends on theMistDemolibrary, and is wired to themistdemoproductThen
MistDemoTestscan@testable import MistDemofrom the library without any changes to the test files.Affected Files
Examples/MistDemo/Package.swift— target restructuringExamples/MistDemo/Sources/MistDemo/MistDemo.swift— move to new entry-point target directory