-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
public struct InstalledSwiftPMConfiguration: Codable { | ||
public struct InstalledSwiftPMConfiguration { | ||
public struct Version: Codable, CustomStringConvertible { | ||
let major: Int | ||
let minor: Int | ||
|
@@ -31,6 +31,7 @@ public struct InstalledSwiftPMConfiguration: Codable { | |
|
||
let version: Int | ||
public let swiftSyntaxVersionForMacroTemplate: Version | ||
public let swiftTestingVersionForTestTemplate: Version | ||
|
||
public static var `default`: InstalledSwiftPMConfiguration { | ||
return .init( | ||
|
@@ -40,7 +41,56 @@ public struct InstalledSwiftPMConfiguration: Codable { | |
minor: 0, | ||
patch: 0, | ||
prereleaseIdentifier: "latest" | ||
) | ||
), | ||
swiftTestingVersionForTestTemplate: defaultSwiftTestingVersionForTestTemplate | ||
) | ||
} | ||
|
||
private static var defaultSwiftTestingVersionForTestTemplate: Version { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
.init( | ||
major: 0, | ||
minor: 8, | ||
patch: 0, | ||
prereleaseIdentifier: nil | ||
) | ||
} | ||
} | ||
|
||
extension InstalledSwiftPMConfiguration: Codable { | ||
enum CodingKeys: CodingKey { | ||
case version | ||
case swiftSyntaxVersionForMacroTemplate | ||
case swiftTestingVersionForTestTemplate | ||
} | ||
|
||
public init(from decoder: any Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.version = try container.decode( | ||
Int.self, | ||
forKey: CodingKeys.version | ||
) | ||
self.swiftSyntaxVersionForMacroTemplate = try container.decode( | ||
Version.self, | ||
forKey: CodingKeys.swiftSyntaxVersionForMacroTemplate | ||
) | ||
self.swiftTestingVersionForTestTemplate = try container.decodeIfPresent( | ||
Version.self, | ||
forKey: CodingKeys.swiftTestingVersionForTestTemplate | ||
) ?? InstalledSwiftPMConfiguration.defaultSwiftTestingVersionForTestTemplate | ||
} | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
try container.encode(self.version, forKey: CodingKeys.version) | ||
try container.encode( | ||
self.swiftSyntaxVersionForMacroTemplate, | ||
forKey: CodingKeys.swiftSyntaxVersionForMacroTemplate | ||
) | ||
try container.encode( | ||
self.swiftTestingVersionForTestTemplate, | ||
forKey: CodingKeys.swiftTestingVersionForTestTemplate | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,6 +564,53 @@ class ManifestEditTests: XCTestCase { | |
} | ||
} | ||
|
||
func testAddSwiftTestingTestTarget() throws { | ||
try assertManifestRefactor(""" | ||
// swift-tools-version: 5.5 | ||
let package = Package( | ||
name: "packages" | ||
) | ||
""", | ||
expectedManifest: """ | ||
// swift-tools-version: 5.5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Okay, sounds good. :) |
||
let package = Package( | ||
name: "packages", | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-testing.git", from: "0.8.0"), | ||
], | ||
targets: [ | ||
.testTarget( | ||
name: "MyTest", | ||
dependencies: [ .product(name: "Testing", package: "swift-testing") ] | ||
), | ||
] | ||
) | ||
""", | ||
expectedAuxiliarySources: [ | ||
RelativePath("Tests/MyTest/MyTest.swift") : """ | ||
import Testing | ||
|
||
@Suite | ||
struct MyTestTests { | ||
@Test("MyTest tests") | ||
func example() { | ||
#expect(42 == 17 + 25) | ||
} | ||
} | ||
""" | ||
]) { manifest in | ||
try AddTarget.addTarget( | ||
TargetDescription( | ||
name: "MyTest", | ||
type: .test | ||
), | ||
to: manifest, | ||
configuration: .init( | ||
testHarness: .swiftTesting | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{"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":8,"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.
Please break this up into two flags,
--enable/disable-xctest
and--enable/disable-experimental-swift-testing
: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.