@@ -3,7 +3,7 @@ import XCTest
33
44/// Default handler for Nimble. This assertion handler passes failures along to
55/// XCTest.
6- public class NimbleXCTestHandler : AssertionHandler {
6+ public final class NimbleXCTestHandler : AssertionHandler {
77 public func assert( _ assertion: Bool , message: FailureMessage , location: SourceLocation ) {
88 if !assertion {
99 recordFailure ( " \( message. stringValue) \n " , location: location)
@@ -13,7 +13,7 @@ public class NimbleXCTestHandler: AssertionHandler {
1313
1414/// Alternative handler for Nimble. This assertion handler passes failures along
1515/// to XCTest by attempting to reduce the failure message size.
16- public class NimbleShortXCTestHandler : AssertionHandler {
16+ public final class NimbleShortXCTestHandler : AssertionHandler {
1717 public func assert( _ assertion: Bool , message: FailureMessage , location: SourceLocation ) {
1818 if !assertion {
1919 let msg : String
@@ -29,32 +29,45 @@ public class NimbleShortXCTestHandler: AssertionHandler {
2929
3030/// Fallback handler in case XCTest is unavailable. This assertion handler will abort
3131/// the program if it is invoked.
32- class NimbleXCTestUnavailableHandler : AssertionHandler {
32+ final class NimbleXCTestUnavailableHandler : AssertionHandler {
3333 func assert( _ assertion: Bool , message: FailureMessage , location: SourceLocation ) {
3434 fatalError ( " XCTest is not available and no custom assertion handler was configured. Aborting. " )
3535 }
3636}
3737
3838#if canImport(Darwin)
3939/// Helper class providing access to the currently executing XCTestCase instance, if any
40- @objc final public class CurrentTestCaseTracker : NSObject , XCTestObservation {
40+ @objc final public class CurrentTestCaseTracker : NSObject , XCTestObservation , @ unchecked Sendable {
4141 @objc public static let sharedInstance = CurrentTestCaseTracker ( )
4242
43- private( set) var currentTestCase : XCTestCase ?
43+ private let lock = NSRecursiveLock ( )
44+
45+ private var _currentTestCase : XCTestCase ?
46+ var currentTestCase : XCTestCase ? {
47+ lock. lock ( )
48+ defer { lock. unlock ( ) }
49+ return _currentTestCase
50+ }
4451
4552 private var stashed_swift_reportFatalErrorsToDebugger : Bool = false
4653
4754 @objc public func testCaseWillStart( _ testCase: XCTestCase ) {
55+ lock. lock ( )
56+ defer { lock. unlock ( ) }
57+
4858 #if (os(macOS) || os(iOS) || os(visionOS)) && !SWIFT_PACKAGE
4959 stashed_swift_reportFatalErrorsToDebugger = _swift_reportFatalErrorsToDebugger
5060 _swift_reportFatalErrorsToDebugger = false
5161 #endif
5262
53- currentTestCase = testCase
63+ _currentTestCase = testCase
5464 }
5565
5666 @objc public func testCaseDidFinish( _ testCase: XCTestCase ) {
57- currentTestCase = nil
67+ lock. lock ( )
68+ defer { lock. unlock ( ) }
69+
70+ _currentTestCase = nil
5871
5972 #if (os(macOS) || os(iOS) || os(visionOS)) && !SWIFT_PACKAGE
6073 _swift_reportFatalErrorsToDebugger = stashed_swift_reportFatalErrorsToDebugger
0 commit comments