Skip to content

Commit d454328

Browse files
authored
Remove Snapshot types from non-Darwin builds. (#540)
Now that we've landed and tagged #479 in 0.11.0, we no longer need to keep building the snapshot types for non-Darwin platforms because we have a stable, permanent replacement for them. We need to keep them around on Darwin to support Xcode 16 betas. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 4c368b3 commit d454328

File tree

17 files changed

+35
-3
lines changed

17 files changed

+35
-3
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ extension Array where Element == PackageDescription.SwiftSetting {
132132

133133
.define("SWT_NO_FILE_IO", .when(platforms: [.wasi])),
134134
.define("SWT_NO_EXIT_TESTS", .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi])),
135+
.define("SWT_NO_SNAPSHOT_TYPES", .when(platforms: [.linux, .windows, .wasi])),
135136
]
136137
}
137138

Sources/Testing/ABI/EntryPoints/EntryPoint.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,12 @@ public func configurationForEntryPoint(from args: __CommandLineArguments_v0) thr
512512
/// - Throws: If `version` is not a supported ABI version.
513513
func eventHandlerForStreamingEvents(version: Int?, forwardingTo eventHandler: @escaping @Sendable (UnsafeRawBufferPointer) -> Void) throws -> Event.Handler {
514514
switch version {
515+
#if !SWT_NO_SNAPSHOT_TYPES
515516
case -1:
516517
// Legacy support for Xcode 16 betas. Support for this undocumented version
517518
// will be removed in a future update. Do not use it.
518519
eventHandlerForStreamingEventSnapshots(to: eventHandler)
520+
#endif
519521
case nil, 0:
520522
ABIv0.Record.eventHandler(forwardingTo: eventHandler)
521523
case let .some(unsupportedVersion):
@@ -547,7 +549,7 @@ private func _writeJSONLine(_ json: UnsafeRawBufferPointer, to file: borrowing F
547549
if _slowPath(json.contains(where: isASCIINewline)) {
548550
#if DEBUG
549551
let message = Event.ConsoleOutputRecorder.warning(
550-
"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",
552+
"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",
551553
options: .for(.stderr)
552554
)
553555
#if SWT_TARGET_OS_APPLE

Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extension ABIv0.Record {
4545
}
4646
}
4747

48+
#if !SWT_NO_SNAPSHOT_TYPES
4849
// MARK: - Experimental event streaming
4950

5051
/// A type containing an event snapshot and snapshots of the contents of an
@@ -107,3 +108,4 @@ func eventHandlerForStreamingEventSnapshots(
107108
}
108109
}
109110
#endif
111+
#endif

Sources/Testing/Events/Event.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ extension Event {
287287
}
288288
}
289289

290+
#if !SWT_NO_SNAPSHOT_TYPES
290291
// MARK: - Snapshotting
291292

292293
extension Event {
@@ -509,3 +510,4 @@ extension Event.Context {
509510
}
510511
}
511512
}
513+
#endif

Sources/Testing/Expectations/Expectation.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public struct ExpectationFailedError: Error {
5353
public var expectation: Expectation
5454
}
5555

56+
#if !SWT_NO_SNAPSHOT_TYPES
5657
// MARK: - Snapshotting
5758

5859
extension Expectation {
@@ -100,3 +101,4 @@ extension Expectation {
100101
}
101102
}
102103
}
104+
#endif

Sources/Testing/Issues/ErrorSnapshot.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11+
#if !SWT_NO_SNAPSHOT_TYPES
1112
/// A serializable snapshot of an `Error` value.
1213
///
1314
/// This type conforms to `Error` as well, meaning it can be thrown and treated
@@ -40,3 +41,4 @@ extension ErrorSnapshot: CustomStringConvertible {}
4041
// MARK: - Codable
4142

4243
extension ErrorSnapshot: Codable {}
44+
#endif

Sources/Testing/Issues/Issue.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ extension Issue.Kind: CustomStringConvertible {
194194
}
195195
}
196196

197+
#if !SWT_NO_SNAPSHOT_TYPES
197198
// MARK: - Snapshotting
198199

199200
extension Issue {
@@ -476,3 +477,4 @@ extension Issue.Kind.Snapshot: CustomStringConvertible {
476477
}
477478
}
478479
}
480+
#endif

Sources/Testing/Parameterization/Test.Case.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ extension Test.Case.Argument.ID: Codable {}
160160
extension Test.Parameter: Hashable {}
161161
extension Test.Case.Argument.ID: Hashable {}
162162

163+
#if !SWT_NO_SNAPSHOT_TYPES
163164
// MARK: - Snapshotting
164165

165166
extension Test.Case {
@@ -215,3 +216,4 @@ extension Test.Case.Argument {
215216
}
216217
}
217218
}
219+
#endif

Sources/Testing/Running/Runner.Plan.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ extension Runner.Plan {
303303
}
304304
}
305305

306+
#if !SWT_NO_SNAPSHOT_TYPES
306307
// MARK: - Snapshotting
307308

308309
extension Runner.Plan {
@@ -430,3 +431,4 @@ extension Runner.Plan.Action {
430431
}
431432
}
432433
}
434+
#endif

Sources/Testing/Test.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ extension Test: Equatable, Hashable {
271271
}
272272
}
273273

274+
#if !SWT_NO_SNAPSHOT_TYPES
274275
// MARK: - Snapshotting
275276

276277
extension Test {
@@ -388,3 +389,4 @@ extension Test {
388389
}
389390
}
390391
}
392+
#endif

Tests/TestingTests/EventTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11+
#if !SWT_NO_SNAPSHOT_TYPES
1112
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1213
#if SWT_BUILDING_WITH_CMAKE
1314
@_implementationOnly import _TestingInternals
@@ -80,3 +81,4 @@ struct EventTests {
8081
}
8182
#endif
8283
}
84+
#endif

Tests/TestingTests/IssueTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ final class IssueTests: XCTestCase {
14191419
}
14201420
#endif
14211421

1422+
#if !SWT_NO_SNAPSHOT_TYPES
14221423
@Suite("Issue Codable Conformance Tests")
14231424
struct IssueCodingTests {
14241425

@@ -1531,6 +1532,7 @@ struct IssueCodingTests {
15311532
#expect(String(reflecting: issueSnapshot) == String(reflecting: issue))
15321533
}
15331534
}
1535+
#endif
15341536

15351537
// MARK: - Fixtures
15361538

Tests/TestingTests/PlanTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,19 +421,21 @@ struct PlanTests {
421421
#expect(plan.stepGraph.subgraph(at: typeInfo.fullyQualifiedNameComponents + CollectionOfOne("reserved1(reserved2:)")) != nil)
422422
}
423423

424+
#if !SWT_NO_SNAPSHOT_TYPES
424425
@Test("Test cases of a disabled test are not evaluated")
425426
func disabledTestCases() async throws {
426427
var configuration = Configuration()
427428
configuration.setEventHandler { event, context in
428429
guard case .testSkipped = event.kind else {
429430
return
430431
}
431-
let testSnapshot = try #require(context.test.map({ Test.Snapshot(snapshotting: $0 )}))
432+
let testSnapshot = try #require(context.test.map { Test.Snapshot(snapshotting: $0) })
432433
#expect(testSnapshot.testCases?.isEmpty ?? false)
433434
}
434435

435436
await runTestFunction(named: "disabled(x:)", in: ParameterizedTests.self, configuration: configuration)
436437
}
438+
#endif
437439
}
438440

439441
// MARK: - Fixtures

Tests/TestingTests/Runner.Plan.SnapshotTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11+
#if !SWT_NO_SNAPSHOT_TYPES
1112
@testable @_spi(ForToolsIntegrationOnly) import Testing
1213

1314
@Suite("Runner.Plan.Snapshot tests")
@@ -66,3 +67,4 @@ private struct Runner_Plan_SnapshotFixtures {
6667
@Test(.hidden, .enabled(if: try _erroneousCondition(), "To demonstrate recordIssue action"))
6768
func erroneousTest() {}
6869
}
70+
#endif

Tests/TestingTests/SwiftPMTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct SwiftPMTests {
229229
])
230230
func eventStreamOutput(outputArgumentName: String, versionArgumentName: String, version: String) async throws {
231231
// Test that JSON records are successfully streamed to a file and can be
232-
// read back as snapshots.
232+
// read back into memory and decoded.
233233
let tempDirPath = try temporaryDirectory()
234234
let temporaryFilePath = appendPathComponent("\(UInt64.random(in: 0 ..< .max))", to: tempDirPath)
235235
defer {

Tests/TestingTests/Test.SnapshotTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11+
#if !SWT_NO_SNAPSHOT_TYPES
1112
@_spi(Experimental) @_spi(ForToolsIntegrationOnly) @testable import Testing
1213

1314
@Suite("Test.Snapshot tests")
@@ -129,3 +130,4 @@ struct Test_SnapshotTests {
129130
extension Tag {
130131
@Tag fileprivate static var testTag: Self
131132
}
133+
#endif

cmake/modules/shared/CompilerSettings.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ endif()
2929
if(CMAKE_SYSTEM_NAME IN_LIST "iOS;watchOS;tvOS;visionOS;WASI")
3030
add_compile_definitions("SWT_NO_EXIT_TESTS")
3131
endif()
32+
if(NOT APPLE)
33+
add_compile_definitions("SWT_NO_SNAPSHOT_TYPES")
34+
endif()

0 commit comments

Comments
 (0)