-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathErrorProtocol.swift
55 lines (45 loc) · 1.49 KB
/
ErrorProtocol.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: stress_test
// REQUIRES: objc_interop
// UNSUPPORTED: threading_none
import SwiftPrivate
import StdlibUnittest
import Foundation
enum SomeError : Error {
case GoneToFail
}
struct ErrorAsNSErrorRaceTest : RaceTestWithPerTrialData {
class RaceData {
let error: Error
init(error: Error) {
self.error = error
}
}
func makeRaceData() -> RaceData {
return RaceData(error: SomeError.GoneToFail)
}
func makeThreadLocalData() {}
func thread1(_ raceData: RaceData, _: inout Void) -> Observation3Int {
let ns = raceData.error as NSError
// Use valueForKey to bypass bridging, so we can verify that the identity
// of the unbridged NSString object is stable.
let domainInt: Int = unsafeBitCast(ns.value(forKey: "domain").map { $0 as AnyObject },
to: Int.self)
let code: Int = ns.code
let userInfoInt: Int = unsafeBitCast(ns.value(forKey: "userInfo").map { $0 as AnyObject },
to: Int.self)
return Observation3Int(domainInt, code, userInfoInt)
}
func evaluateObservations(
_ observations: [Observation3Int],
_ sink: (RaceTestObservationEvaluation) -> Void
) {
sink(evaluateObservationsAllEqual(observations))
}
}
var ErrorRaceTestSuite = TestSuite("Error races")
ErrorRaceTestSuite.test("NSError bridging") {
runRaceTest(ErrorAsNSErrorRaceTest.self, operations: 1000)
}
runAllTests()