You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Generate tests for executable/tool with --enable-swift-testing (#9032)
Updated `InitPackage` to handle `.executable` and `.tool` types when
generating test files with SwiftTesting. Added corresponding tests to
verify correct test file content for these package types.
### Motivation:
The `swift package init` command did not generate a `Tests` directory
for executable or tool packages when the `--enable-swift-testing` flag
was used. This was caused by logic in
`Sources/Workspace/InitPackage.swift` that incorrectly skipped test
generation for these package types. This change fixes that behavior,
ensuring that tests are created as expected.
### Modifications:
- In `Sources/Workspace/InitPackage.swift`, the `writeTests()` function
was modified to proceed with test generation for `.executable` and
`.tool` package types.
- In the same file, the `writeTestFileStubs()` function was updated to
include `.executable` and `.tool` types, allowing the creation of
standard library-style test files for them.
### Result:
After this change, running `swift package init --type executable
--enable-swift-testing` or `swift package init --type tool
--enable-swift-testing` correctly generates a `Tests` directory with
sample test files, aligning the tool's behavior with its intended
functionality.
### Reproduction and Verification:
#### Reproducing the Issue (on `main` branch):
1. Create a temporary directory: `mkdir -p /tmp/test-repro && cd
/tmp/test-repro`
2. Run `swift package init --type executable --enable-swift-testing`.
3. Verify that no `Tests` directory is created by running `ls -F`.
#### Verifying the Fix (on this branch):
1. Build the package manager: `swift build`
2. Find the built executable: `find .build -name swift-package`
3. Create a temporary directory: `mkdir -p /tmp/test-fix && cd
/tmp/test-fix`
4. Run the newly built package manager to init a project:
`../.build/arm64-apple-macosx/debug/swift-package init --type executable
--enable-swift-testing` (adjust path as needed).
5. Verify that a `Tests` directory is now created by running `ls -F`.
0 commit comments