Skip to content

Commit

Permalink
Make the test_observer compatible with Swift 6 language mode.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 664764173
  • Loading branch information
allevato authored and swiple-rules-gardener committed Aug 19, 2024
1 parent 6d6727a commit 84c67e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion tools/test_observer/Locked.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public struct Locked<Value>: Sendable where Value: Sendable {
}
}

private nonisolated(unsafe) var _storage: ManagedBuffer<Value, pthread_mutex_t>
// Swift 6 requires this to be declared as `nonisolated(unsafe)`, but older compilers emit a
// warning claiming (incorrectly) that it's redundant.
#if compiler(>=6)
private nonisolated(unsafe) var _storage: ManagedBuffer<Value, pthread_mutex_t>
#else
private var _storage: ManagedBuffer<Value, pthread_mutex_t>
#endif

/// The value behind the lock.
public var value: Value {
Expand Down
8 changes: 4 additions & 4 deletions tools/test_observer/XUnitTestRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public struct RecordedIssue: Sendable {
/// nested suites).
///
/// In an async-first world, it would make sense to make this an actor instead of using manual
/// locking. However, since both the XCTest and swift-testing frameworks deliver their events in
/// synchronous contexts, it's easier to do things the old-fashioned way.
public final class XUnitTestRecorder {
/// locking. However, since XCTest delivers its events in a synchronous context, it's easier to use
/// old-fashioned locking.
public final class XUnitTestRecorder: Sendable {
/// Context that is mutated by the test reader, protected by a lock.
private struct Context: Sendable {
/// The total number of tests that have run.
Expand All @@ -64,7 +64,7 @@ public final class XUnitTestRecorder {
public static let shared = XUnitTestRecorder()

/// The context that is mutated by the test reader, protected by a lock.
private var context: Locked<Context> = Locked(.init())
private let context: Locked<Context> = Locked(.init())

/// Indicates whether any failures have been recorded.
public var hasFailure: Bool {
Expand Down

1 comment on commit 84c67e5

@brentleyjones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.