New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Teach swift package add-target --type test about swift-testing #7481
Conversation
@swift-ci please test |
@swift-ci please test |
@swift-ci please test Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this! I understand your motivation in wanting to use a single option here, however splitting it into two flags is important for a few reasons I listed in comments.
Thanks again!
@@ -60,6 +60,9 @@ extension SwiftPackageCommand { | |||
@Option(help: "The checksum for a remote binary target") | |||
var checksum: String? | |||
|
|||
@Option(help: "The testing library to use when generating test targets, which can be one of 'xctest', 'swift-testing', or 'none'") | |||
var testingLibrary: PackageModelSyntax.AddTarget.TestHarness = .default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please break this up into two flags, --enable/disable-xctest
and --enable/disable-experimental-swift-testing
:
- It would be consistent with the flags we've added to other commands;
- swift-testing is experimental only;
- The default behaviour if neither is specified should be to add support for XCTest only;
- In the future, we can always change the default if needed; and
- It is valid to specify both libraries as dependencies for a test target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you are proposing is a confusing design for functionality that is adding a brand-new test target. Roughly nobody is going to create a new test target that uses both of these testing libraries: they'll pick one and stick with it.
Other commands need to deal with one or both libraries being present, because existing test targets likely use XCTest and will want to pick up Swift Testing. This functionality is not for those use cases.
0ec1f0f
to
05b3ece
Compare
@swift-ci please test |
@swift-ci please test Windows |
) | ||
} | ||
|
||
private static var defaultSwiftTestingVersionForTestTemplate: Version { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not have this at all and solely use config.json, swiftSyntaxVersionForMacroTemplate
should also be removed but we can at least not add another.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this was driven by a failure in Linux CI in prior iterations of this patch, where we were getting a config.json
from an older toolchain. It seemed like a reasonable policy that we would support at least slightly-older toolchains, so the default bridges that gap. If we want to be strict about this, we'll need to track down the configuration that produced this failure.
) | ||
""", | ||
expectedManifest: """ | ||
// swift-tools-version: 5.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does 5.5 actually come from 🤔?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5.5 introduced some tweaks to the package manifest format (e.g., some things moved to labels), such as introducing new package
dependencies and deprecating some old ones. We can either write a bunch of code to deal with all of the differences, or we can limit the functionality to 5.5 or newer. The latter was easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swift-testing is going to need a manifest version of 6.0 or later at some point in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm not sure if that affects its clients—I assume not?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, if we end up changing the manifest format in some way for swift-testing, we'll need make changes here as well. We can enforce a 6.0 manifest or help with updating the manifest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clients of a package are not affected by the package manifest version of the package, other than the fact that all consumers of the client will need new-enough tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sounds good. :)
@Suite | ||
struct \(raw: target.name)Tests { | ||
@Test("\(raw: target.name) tests") | ||
func tests() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylistic suggestion: I recommend naming the func something not prefixed by the word "test", like example()
. The @Test
attribute already marks it as a test so having that prefix can feel redundant. (I realize this was just adapted from the prior XCTest template, of course!)
(If you take this suggestion, I think a unit test below will need to be adjusted)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll drop the test prefix for swift-testing.
Utilities/config.json
Outdated
{"version":1,"swiftSyntaxVersionForMacroTemplate":{"major":600,"minor":0,"patch":0, "prereleaseIdentifier":"latest"}} | ||
{"version":1, | ||
"swiftSyntaxVersionForMacroTemplate":{"major":600,"minor":0,"patch":0, "prereleaseIdentifier":"latest"}, | ||
"swiftTestingVersionForTestTemplate":{"major":0,"minor":7,"patch":0}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We recently released tag 0.8.0 so you can bump this, as well as another place I saw in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll bump in both places, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple comments but this largely looks good to me from the perspective of a swift-testing maintainer! Thank you
Introduce a command-line argument `--testing-library` to the add-target command to specify which test library to generate the test for. This can be 'xctest' (the prior XCTest behavior), 'swift-testing' (to use the new swift-testing library), or 'none' (for no test library at all). For the new swift-testing generation, also add the appropriate package and test target dependency, along with a stub testsuite to start from. Fixes apple#7478
Make the conformance to Codable explicit so we can swap in the default swift-testing package version when it wasn't present in the config file.
05b3ece
to
bcbd9ea
Compare
@swift-ci please test |
@swift-ci please test Windows |
bcbd9ea
to
b08070d
Compare
@swift-ci please test |
@swift-ci please test Windows |
@swift-ci please test Linux |
@swift-ci please test Linux |
…#7481) Introduce a command-line argument `--testing-library` to the add-target command to specify which test library to generate the test for. This can be 'xctest' (the prior XCTest behavior), 'swift-testing' (to use the new swift-testing library), or 'none' (for no test library at all). For the new swift-testing generation, also add the appropriate package and test target dependency, along with a stub testsuite to start from. Fixes apple#7478 (cherry picked from commit a37631a)
…7481) (#7537) **Explanation**: Introduce a command-line argument `--testing-library` to the new add-target command to specify which test library to generate the test for. This can be 'xctest' (the prior XCTest behavior), 'swift-testing' (to use the new swift-testing library), or 'none' (for no test library at all). **Original PR**: #7481 **Risk**: Low. Extends new functionality in a new package command. **Testing**: New tests.
Introduce a command-line argument
--testing-library
to the add-targetcommand to specify which test library to generate the test for. This
can be 'xctest' (the prior XCTest behavior), 'swift-testing' (to use the
new swift-testing library), or 'none' (for no test library at all).
For the new swift-testing generation, also add the appropriate package
and test target dependency, along with a stub testsuite to start from.
Fixes #7478