Skip to content

Remove Snapshot types from non-Darwin builds. #540

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

Merged
merged 1 commit into from
Jul 16, 2024
Merged
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
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])),
]
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Testing/ABI/EntryPoints/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,3 +108,4 @@ func eventHandlerForStreamingEventSnapshots(
}
}
#endif
#endif
2 changes: 2 additions & 0 deletions Sources/Testing/Events/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ extension Event {
}
}

#if !SWT_NO_SNAPSHOT_TYPES
// MARK: - Snapshotting

extension Event {
Expand Down Expand Up @@ -509,3 +510,4 @@ extension Event.Context {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/Testing/Expectations/Expectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public struct ExpectationFailedError: Error {
public var expectation: Expectation
}

#if !SWT_NO_SNAPSHOT_TYPES
// MARK: - Snapshotting

extension Expectation {
Expand Down Expand Up @@ -100,3 +101,4 @@ extension Expectation {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/Testing/Issues/ErrorSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,3 +41,4 @@ extension ErrorSnapshot: CustomStringConvertible {}
// MARK: - Codable

extension ErrorSnapshot: Codable {}
#endif
2 changes: 2 additions & 0 deletions Sources/Testing/Issues/Issue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ extension Issue.Kind: CustomStringConvertible {
}
}

#if !SWT_NO_SNAPSHOT_TYPES
// MARK: - Snapshotting

extension Issue {
Expand Down Expand Up @@ -476,3 +477,4 @@ extension Issue.Kind.Snapshot: CustomStringConvertible {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/Testing/Parameterization/Test.Case.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -215,3 +216,4 @@ extension Test.Case.Argument {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/Testing/Running/Runner.Plan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ extension Runner.Plan {
}
}

#if !SWT_NO_SNAPSHOT_TYPES
// MARK: - Snapshotting

extension Runner.Plan {
Expand Down Expand Up @@ -430,3 +431,4 @@ extension Runner.Plan.Action {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/Testing/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ extension Test: Equatable, Hashable {
}
}

#if !SWT_NO_SNAPSHOT_TYPES
// MARK: - Snapshotting

extension Test {
Expand Down Expand Up @@ -388,3 +389,4 @@ extension Test {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Tests/TestingTests/EventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,3 +81,4 @@ struct EventTests {
}
#endif
}
#endif
2 changes: 2 additions & 0 deletions Tests/TestingTests/IssueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ final class IssueTests: XCTestCase {
}
#endif

#if !SWT_NO_SNAPSHOT_TYPES
@Suite("Issue Codable Conformance Tests")
struct IssueCodingTests {

Expand Down Expand Up @@ -1531,6 +1532,7 @@ struct IssueCodingTests {
#expect(String(reflecting: issueSnapshot) == String(reflecting: issue))
}
}
#endif

// MARK: - Fixtures

Expand Down
4 changes: 3 additions & 1 deletion Tests/TestingTests/PlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,21 @@ 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()
configuration.setEventHandler { event, context in
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
Expand Down
2 changes: 2 additions & 0 deletions Tests/TestingTests/Runner.Plan.SnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -66,3 +67,4 @@ private struct Runner_Plan_SnapshotFixtures {
@Test(.hidden, .enabled(if: try _erroneousCondition(), "To demonstrate recordIssue action"))
func erroneousTest() {}
}
#endif
2 changes: 1 addition & 1 deletion Tests/TestingTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions Tests/TestingTests/Test.SnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -129,3 +130,4 @@ struct Test_SnapshotTests {
extension Tag {
@Tag fileprivate static var testTag: Self
}
#endif
3 changes: 3 additions & 0 deletions cmake/modules/shared/CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()