@@ -3,7 +3,7 @@ import XCTest
3
3
4
4
/// Default handler for Nimble. This assertion handler passes failures along to
5
5
/// XCTest.
6
- public class NimbleXCTestHandler : AssertionHandler {
6
+ public final class NimbleXCTestHandler : AssertionHandler {
7
7
public func assert( _ assertion: Bool , message: FailureMessage , location: SourceLocation ) {
8
8
if !assertion {
9
9
recordFailure ( " \( message. stringValue) \n " , location: location)
@@ -13,7 +13,7 @@ public class NimbleXCTestHandler: AssertionHandler {
13
13
14
14
/// Alternative handler for Nimble. This assertion handler passes failures along
15
15
/// to XCTest by attempting to reduce the failure message size.
16
- public class NimbleShortXCTestHandler : AssertionHandler {
16
+ public final class NimbleShortXCTestHandler : AssertionHandler {
17
17
public func assert( _ assertion: Bool , message: FailureMessage , location: SourceLocation ) {
18
18
if !assertion {
19
19
let msg : String
@@ -29,32 +29,45 @@ public class NimbleShortXCTestHandler: AssertionHandler {
29
29
30
30
/// Fallback handler in case XCTest is unavailable. This assertion handler will abort
31
31
/// the program if it is invoked.
32
- class NimbleXCTestUnavailableHandler : AssertionHandler {
32
+ final class NimbleXCTestUnavailableHandler : AssertionHandler {
33
33
func assert( _ assertion: Bool , message: FailureMessage , location: SourceLocation ) {
34
34
fatalError ( " XCTest is not available and no custom assertion handler was configured. Aborting. " )
35
35
}
36
36
}
37
37
38
38
#if canImport(Darwin)
39
39
/// 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 {
41
41
@objc public static let sharedInstance = CurrentTestCaseTracker ( )
42
42
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
+ }
44
51
45
52
private var stashed_swift_reportFatalErrorsToDebugger : Bool = false
46
53
47
54
@objc public func testCaseWillStart( _ testCase: XCTestCase ) {
55
+ lock. lock ( )
56
+ defer { lock. unlock ( ) }
57
+
48
58
#if (os(macOS) || os(iOS) || os(visionOS)) && !SWIFT_PACKAGE
49
59
stashed_swift_reportFatalErrorsToDebugger = _swift_reportFatalErrorsToDebugger
50
60
_swift_reportFatalErrorsToDebugger = false
51
61
#endif
52
62
53
- currentTestCase = testCase
63
+ _currentTestCase = testCase
54
64
}
55
65
56
66
@objc public func testCaseDidFinish( _ testCase: XCTestCase ) {
57
- currentTestCase = nil
67
+ lock. lock ( )
68
+ defer { lock. unlock ( ) }
69
+
70
+ _currentTestCase = nil
58
71
59
72
#if (os(macOS) || os(iOS) || os(visionOS)) && !SWIFT_PACKAGE
60
73
_swift_reportFatalErrorsToDebugger = stashed_swift_reportFatalErrorsToDebugger
0 commit comments