Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Commands/PackageCommands/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Sources/Commands/SwiftBuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
15 changes: 13 additions & 2 deletions Sources/CoreCommands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions Tests/CommandsTests/TestCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down