From 5444e1951bf88cc0a91794d15eae1659da07a43d Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 24 May 2024 17:43:15 -0400 Subject: [PATCH] Remove `experimental` from `--enable-[experimental-]swift-testing` This PR removes the word `experimental` from the aforementioned command-line option for `swift package init`, `swift build`, and `swift test`. This change is speculative. --- Sources/Commands/PackageCommands/Init.swift | 3 ++- Sources/Commands/SwiftBuildCommand.swift | 3 ++- Sources/CoreCommands/Options.swift | 15 +++++++++++++-- Tests/CommandsTests/TestCommandTests.swift | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Sources/Commands/PackageCommands/Init.swift b/Sources/Commands/PackageCommands/Init.swift index 05090069eea..18e0bec77de 100644 --- a/Sources/Commands/PackageCommands/Init.swift +++ b/Sources/Commands/PackageCommands/Init.swift @@ -60,7 +60,8 @@ extension SwiftPackageCommand { if testLibraryOptions.enableXCTestSupport { testingLibraries.insert(.xctest) } - if testLibraryOptions.explicitlyEnableSwiftTestingLibrarySupport == true { + if testLibraryOptions.explicitlyEnableSwiftTestingLibrarySupport == true + || testLibraryOptions.explicitlyEnableExperimentalSwiftTestingLibrarySupport == true { testingLibraries.insert(.swiftTesting) } let packageName = self.packageName ?? cwd.basename diff --git a/Sources/Commands/SwiftBuildCommand.swift b/Sources/Commands/SwiftBuildCommand.swift index 0b6567cfed8..c0d4b80cde8 100644 --- a/Sources/Commands/SwiftBuildCommand.swift +++ b/Sources/Commands/SwiftBuildCommand.swift @@ -110,7 +110,8 @@ struct BuildCommandOptions: ParsableArguments { // or disable either testing library. if !buildTests { if testLibraryOptions.explicitlyEnableXCTestSupport != nil - || testLibraryOptions.explicitlyEnableSwiftTestingLibrarySupport != nil { + || testLibraryOptions.explicitlyEnableSwiftTestingLibrarySupport != nil + || testLibraryOptions.explicitlyEnableExperimentalSwiftTestingLibrarySupport != nil { throw StringError("pass --build-tests to build test targets") } } diff --git a/Sources/CoreCommands/Options.swift b/Sources/CoreCommands/Options.swift index f047c177ce1..c98a3f4d300 100644 --- a/Sources/CoreCommands/Options.swift +++ b/Sources/CoreCommands/Options.swift @@ -579,11 +579,17 @@ public struct TestLibraryOptions: ParsableArguments { /// Callers (other than `swift package init`) will generally want to use /// ``enableSwiftTestingLibrarySupport(swiftCommandState:)`` since it will /// take into account whether the package has a dependency on swift-testing. - @Flag(name: .customLong("experimental-swift-testing"), + @Flag(name: .customLong("swift-testing"), inversion: .prefixedEnableDisable, - help: "Enable experimental support for swift-testing") + help: "Enable support for swift-testing") public var explicitlyEnableSwiftTestingLibrarySupport: Bool? + /// Deprecated shadow of ``explicitlyEnableSwiftTestingLibrarySupport``. + @Flag(name: .customLong("experimental-swift-testing"), + inversion: .prefixedEnableDisable, + help: .hidden) + public var explicitlyEnableExperimentalSwiftTestingLibrarySupport: Bool? + /// Whether to enable support for swift-testing. public func enableSwiftTestingLibrarySupport( swiftCommandState: SwiftCommandState @@ -592,6 +598,11 @@ public struct TestLibraryOptions: ParsableArguments { if let callerSuppliedValue = explicitlyEnableSwiftTestingLibrarySupport { return callerSuppliedValue } + + // Temporarily honor the experimental flag too. + if let callerSuppliedValue = explicitlyEnableExperimentalSwiftTestingLibrarySupport { + return callerSuppliedValue + } // If the active package has a dependency on swift-testing, automatically enable support for it so that extra steps are not needed. let workspace = try swiftCommandState.getActiveWorkspace() diff --git a/Tests/CommandsTests/TestCommandTests.swift b/Tests/CommandsTests/TestCommandTests.swift index 22229ba8de7..da3c8ce659e 100644 --- a/Tests/CommandsTests/TestCommandTests.swift +++ b/Tests/CommandsTests/TestCommandTests.swift @@ -286,6 +286,20 @@ final class TestCommandTests: CommandsTestCase { "Skipping \(#function) because swift-testing tests are not explicitly enabled" ) + try fixture(name: "Miscellaneous/TestDiscovery/SwiftTesting") { fixturePath in + do { + let (stdout, _) = try SwiftPM.Test.execute(["--enable-swift-testing", "--disable-xctest"], packagePath: fixturePath) + XCTAssertMatch(stdout, .contains(#"Test "SOME TEST FUNCTION" started"#)) + } + } + } + + func testBasicSwiftTestingIntegration_ExperimentalFlag() throws { + try XCTSkipUnless( + nil != ProcessInfo.processInfo.environment["SWIFT_PM_SWIFT_TESTING_TESTS_ENABLED"], + "Skipping \(#function) because swift-testing tests are not explicitly enabled" + ) + try fixture(name: "Miscellaneous/TestDiscovery/SwiftTesting") { fixturePath in do { let (stdout, _) = try SwiftPM.Test.execute(["--enable-experimental-swift-testing", "--disable-xctest"], packagePath: fixturePath)