Hi everyone,
I am having difficulties with an executable Swit package I am working on.
The package worked fine, until I changed the executable product's name from the package's name "MyExecutablePackage"
to "my-executable-package"
. I did this, so it can be called like $ ./color-definition-parser
from the command line (which is more in line with what you would expect a command line tool to be named).
However, since I have done so, in my test files on the line where I import the package with @testable import MyExecutablePackage
, I get the error No such module 'MyExecutablePackage'
. So it seems my test target no longer sees the main module. (Changing it to @testable import my-executable-package
does not help.)
The weird thing is, I can build and run the package from the command line:
$ swift build
Building for debugging...
[4/4] Linking my-executable-package
Build complete! (6.01s)
And the tests run and on the command line:
$ swift test
Building for debugging...
[4/4] Linking MyExecutablePackageTests
Build complete! (1.94s)
Test Suite 'All tests' started at 2023-10-18 20:17:00.525
...
Test Suite 'All tests' passed at 2023-10-18 20:17:00.614.
Executed 56 tests, with 0 failures (0 unexpected) in 0.085 (0.089) seconds
My Pacakge.swift file looks like this at the moment:
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyExecutablePackage",
platforms: [ .macOS(.v13), .iOS(.v14) ],
products: [
.executable(
name: "my-executable-package", // Everything worked fine until this was changed from "MyExecutablePackage"
targets: ["MyExecutablePackage"]
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.3")
],
targets: [
.executableTarget(
name: "MyExecutablePackage",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Sources"
),
.testTarget(
name: "MyExecutablePackageTests",
dependencies: [ "MyExecutablePackage" ],
path: "Tests"
)
]
)
Any ideas what's going on and how to fix it?