diff --git a/Package.swift b/Package.swift index 5c22be5c2..78d364d5c 100644 --- a/Package.swift +++ b/Package.swift @@ -132,6 +132,7 @@ extension Array where Element == PackageDescription.SwiftSetting { .define("SWT_NO_FILE_IO", .when(platforms: [.wasi])), .define("SWT_NO_EXIT_TESTS", .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi])), + .define("SWT_NO_SNAPSHOT_TYPES", .when(platforms: [.linux, .windows, .wasi])), ] } diff --git a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift index 6ed1bbe87..d9ed894ff 100644 --- a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift +++ b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift @@ -512,10 +512,12 @@ public func configurationForEntryPoint(from args: __CommandLineArguments_v0) thr /// - Throws: If `version` is not a supported ABI version. func eventHandlerForStreamingEvents(version: Int?, forwardingTo eventHandler: @escaping @Sendable (UnsafeRawBufferPointer) -> Void) throws -> Event.Handler { switch version { +#if !SWT_NO_SNAPSHOT_TYPES case -1: // Legacy support for Xcode 16 betas. Support for this undocumented version // will be removed in a future update. Do not use it. eventHandlerForStreamingEventSnapshots(to: eventHandler) +#endif case nil, 0: ABIv0.Record.eventHandler(forwardingTo: eventHandler) case let .some(unsupportedVersion): @@ -547,7 +549,7 @@ private func _writeJSONLine(_ json: UnsafeRawBufferPointer, to file: borrowing F if _slowPath(json.contains(where: isASCIINewline)) { #if DEBUG let message = Event.ConsoleOutputRecorder.warning( - "JSON encoder produced one or more newline characters while encoding an event snapshot. Please file a bug report at https://github.com/apple/swift-testing/issues/new", + "JSON encoder produced one or more newline characters while encoding an event to JSON. Please file a bug report at https://github.com/apple/swift-testing/issues/new", options: .for(.stderr) ) #if SWT_TARGET_OS_APPLE diff --git a/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift b/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift index 5b0266604..41922e801 100644 --- a/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift +++ b/Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift @@ -45,6 +45,7 @@ extension ABIv0.Record { } } +#if !SWT_NO_SNAPSHOT_TYPES // MARK: - Experimental event streaming /// A type containing an event snapshot and snapshots of the contents of an @@ -107,3 +108,4 @@ func eventHandlerForStreamingEventSnapshots( } } #endif +#endif diff --git a/Sources/Testing/Events/Event.swift b/Sources/Testing/Events/Event.swift index ac0c49a49..e58083bcd 100644 --- a/Sources/Testing/Events/Event.swift +++ b/Sources/Testing/Events/Event.swift @@ -287,6 +287,7 @@ extension Event { } } +#if !SWT_NO_SNAPSHOT_TYPES // MARK: - Snapshotting extension Event { @@ -509,3 +510,4 @@ extension Event.Context { } } } +#endif diff --git a/Sources/Testing/Expectations/Expectation.swift b/Sources/Testing/Expectations/Expectation.swift index 5f7aab856..a5733b038 100644 --- a/Sources/Testing/Expectations/Expectation.swift +++ b/Sources/Testing/Expectations/Expectation.swift @@ -53,6 +53,7 @@ public struct ExpectationFailedError: Error { public var expectation: Expectation } +#if !SWT_NO_SNAPSHOT_TYPES // MARK: - Snapshotting extension Expectation { @@ -100,3 +101,4 @@ extension Expectation { } } } +#endif diff --git a/Sources/Testing/Issues/ErrorSnapshot.swift b/Sources/Testing/Issues/ErrorSnapshot.swift index 364845f9b..04f7bdb85 100644 --- a/Sources/Testing/Issues/ErrorSnapshot.swift +++ b/Sources/Testing/Issues/ErrorSnapshot.swift @@ -8,6 +8,7 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // +#if !SWT_NO_SNAPSHOT_TYPES /// A serializable snapshot of an `Error` value. /// /// This type conforms to `Error` as well, meaning it can be thrown and treated @@ -40,3 +41,4 @@ extension ErrorSnapshot: CustomStringConvertible {} // MARK: - Codable extension ErrorSnapshot: Codable {} +#endif diff --git a/Sources/Testing/Issues/Issue.swift b/Sources/Testing/Issues/Issue.swift index 01562a641..5baa93513 100644 --- a/Sources/Testing/Issues/Issue.swift +++ b/Sources/Testing/Issues/Issue.swift @@ -194,6 +194,7 @@ extension Issue.Kind: CustomStringConvertible { } } +#if !SWT_NO_SNAPSHOT_TYPES // MARK: - Snapshotting extension Issue { @@ -476,3 +477,4 @@ extension Issue.Kind.Snapshot: CustomStringConvertible { } } } +#endif diff --git a/Sources/Testing/Parameterization/Test.Case.swift b/Sources/Testing/Parameterization/Test.Case.swift index 48ab741a7..275cad0a1 100644 --- a/Sources/Testing/Parameterization/Test.Case.swift +++ b/Sources/Testing/Parameterization/Test.Case.swift @@ -160,6 +160,7 @@ extension Test.Case.Argument.ID: Codable {} extension Test.Parameter: Hashable {} extension Test.Case.Argument.ID: Hashable {} +#if !SWT_NO_SNAPSHOT_TYPES // MARK: - Snapshotting extension Test.Case { @@ -215,3 +216,4 @@ extension Test.Case.Argument { } } } +#endif diff --git a/Sources/Testing/Running/Runner.Plan.swift b/Sources/Testing/Running/Runner.Plan.swift index d91a29b4c..7954ecd24 100644 --- a/Sources/Testing/Running/Runner.Plan.swift +++ b/Sources/Testing/Running/Runner.Plan.swift @@ -303,6 +303,7 @@ extension Runner.Plan { } } +#if !SWT_NO_SNAPSHOT_TYPES // MARK: - Snapshotting extension Runner.Plan { @@ -430,3 +431,4 @@ extension Runner.Plan.Action { } } } +#endif diff --git a/Sources/Testing/Test.swift b/Sources/Testing/Test.swift index d077d7f2c..db442f4b2 100644 --- a/Sources/Testing/Test.swift +++ b/Sources/Testing/Test.swift @@ -271,6 +271,7 @@ extension Test: Equatable, Hashable { } } +#if !SWT_NO_SNAPSHOT_TYPES // MARK: - Snapshotting extension Test { @@ -388,3 +389,4 @@ extension Test { } } } +#endif diff --git a/Tests/TestingTests/EventTests.swift b/Tests/TestingTests/EventTests.swift index 4e77046fd..ffd148c52 100644 --- a/Tests/TestingTests/EventTests.swift +++ b/Tests/TestingTests/EventTests.swift @@ -8,6 +8,7 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // +#if !SWT_NO_SNAPSHOT_TYPES @testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing #if SWT_BUILDING_WITH_CMAKE @_implementationOnly import _TestingInternals @@ -80,3 +81,4 @@ struct EventTests { } #endif } +#endif diff --git a/Tests/TestingTests/IssueTests.swift b/Tests/TestingTests/IssueTests.swift index ce2022d52..01a6d2779 100644 --- a/Tests/TestingTests/IssueTests.swift +++ b/Tests/TestingTests/IssueTests.swift @@ -1419,6 +1419,7 @@ final class IssueTests: XCTestCase { } #endif +#if !SWT_NO_SNAPSHOT_TYPES @Suite("Issue Codable Conformance Tests") struct IssueCodingTests { @@ -1531,6 +1532,7 @@ struct IssueCodingTests { #expect(String(reflecting: issueSnapshot) == String(reflecting: issue)) } } +#endif // MARK: - Fixtures diff --git a/Tests/TestingTests/PlanTests.swift b/Tests/TestingTests/PlanTests.swift index 0ecf8db0d..52f3081b0 100644 --- a/Tests/TestingTests/PlanTests.swift +++ b/Tests/TestingTests/PlanTests.swift @@ -421,6 +421,7 @@ struct PlanTests { #expect(plan.stepGraph.subgraph(at: typeInfo.fullyQualifiedNameComponents + CollectionOfOne("reserved1(reserved2:)")) != nil) } +#if !SWT_NO_SNAPSHOT_TYPES @Test("Test cases of a disabled test are not evaluated") func disabledTestCases() async throws { var configuration = Configuration() @@ -428,12 +429,13 @@ struct PlanTests { guard case .testSkipped = event.kind else { return } - let testSnapshot = try #require(context.test.map({ Test.Snapshot(snapshotting: $0 )})) + let testSnapshot = try #require(context.test.map { Test.Snapshot(snapshotting: $0) }) #expect(testSnapshot.testCases?.isEmpty ?? false) } await runTestFunction(named: "disabled(x:)", in: ParameterizedTests.self, configuration: configuration) } +#endif } // MARK: - Fixtures diff --git a/Tests/TestingTests/Runner.Plan.SnapshotTests.swift b/Tests/TestingTests/Runner.Plan.SnapshotTests.swift index 34e83e786..e193de219 100644 --- a/Tests/TestingTests/Runner.Plan.SnapshotTests.swift +++ b/Tests/TestingTests/Runner.Plan.SnapshotTests.swift @@ -8,6 +8,7 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // +#if !SWT_NO_SNAPSHOT_TYPES @testable @_spi(ForToolsIntegrationOnly) import Testing @Suite("Runner.Plan.Snapshot tests") @@ -66,3 +67,4 @@ private struct Runner_Plan_SnapshotFixtures { @Test(.hidden, .enabled(if: try _erroneousCondition(), "To demonstrate recordIssue action")) func erroneousTest() {} } +#endif diff --git a/Tests/TestingTests/SwiftPMTests.swift b/Tests/TestingTests/SwiftPMTests.swift index 2f944adc0..23c1307eb 100644 --- a/Tests/TestingTests/SwiftPMTests.swift +++ b/Tests/TestingTests/SwiftPMTests.swift @@ -229,7 +229,7 @@ struct SwiftPMTests { ]) func eventStreamOutput(outputArgumentName: String, versionArgumentName: String, version: String) async throws { // Test that JSON records are successfully streamed to a file and can be - // read back as snapshots. + // read back into memory and decoded. let tempDirPath = try temporaryDirectory() let temporaryFilePath = appendPathComponent("\(UInt64.random(in: 0 ..< .max))", to: tempDirPath) defer { diff --git a/Tests/TestingTests/Test.SnapshotTests.swift b/Tests/TestingTests/Test.SnapshotTests.swift index f28a1e95a..12a3f2467 100644 --- a/Tests/TestingTests/Test.SnapshotTests.swift +++ b/Tests/TestingTests/Test.SnapshotTests.swift @@ -8,6 +8,7 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // +#if !SWT_NO_SNAPSHOT_TYPES @_spi(Experimental) @_spi(ForToolsIntegrationOnly) @testable import Testing @Suite("Test.Snapshot tests") @@ -129,3 +130,4 @@ struct Test_SnapshotTests { extension Tag { @Tag fileprivate static var testTag: Self } +#endif diff --git a/cmake/modules/shared/CompilerSettings.cmake b/cmake/modules/shared/CompilerSettings.cmake index bcbf5cf74..c354a5bd7 100644 --- a/cmake/modules/shared/CompilerSettings.cmake +++ b/cmake/modules/shared/CompilerSettings.cmake @@ -29,3 +29,6 @@ endif() if(CMAKE_SYSTEM_NAME IN_LIST "iOS;watchOS;tvOS;visionOS;WASI") add_compile_definitions("SWT_NO_EXIT_TESTS") endif() +if(NOT APPLE) + add_compile_definitions("SWT_NO_SNAPSHOT_TYPES") +endif()