-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathclass_resilience.swift
76 lines (57 loc) · 2.11 KB
/
class_resilience.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// RUN: %empty-directory(%t)
// RUN: %target-build-swift-dylib(%t/%target-library-name(resilient_class)) -target %target-swift-5.1-abi-triple -enable-library-evolution %S/Inputs/resilient_class.swift -emit-module -emit-module-path %t/resilient_class.swiftmodule -module-name resilient_class
// RUN: %target-codesign %t/%target-library-name(resilient_class)
// RUN: %target-build-swift -parse-as-library -target %target-swift-5.1-abi-triple %s -lresilient_class -I %t -L %t -o %t/main %target-rpath(%t)
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main %t/%target-library-name(resilient_class)
// REQUIRES: executable_test
// REQUIRES: concurrency
// UNSUPPORTED: freestanding
// rdar://76038845
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime
import StdlibUnittest
import resilient_class
class MyDerived : BaseClass<Int> {
override func waitForNothing() async {
await super.waitForNothing()
}
override func wait() async -> Int {
return await super.wait() * 2
}
override func waitForInt() async -> Int {
return await super.waitForInt() * 2
}
override func wait(orThrow: Bool) async throws {
return try await super.wait(orThrow: orThrow)
}
}
func virtualWaitForNothing<T>(_ c: BaseClass<T>) async {
await c.waitForNothing()
}
func virtualWait<T>(_ c: BaseClass<T>) async -> T {
return await c.wait()
}
func virtualWaitForInt<T>(_ c: BaseClass<T>) async -> Int {
return await c.waitForInt()
}
func virtualWait<T>(orThrow: Bool, _ c: BaseClass<T>) async throws {
return try await c.wait(orThrow: orThrow)
}
@main struct Main {
static func main() async {
let task = Task.detached {
var AsyncVTableMethodSuite = TestSuite("ResilientClass")
AsyncVTableMethodSuite.test("AsyncVTableMethod") {
let x = MyDerived(value: 321)
await virtualWaitForNothing(x)
expectEqual(642, await virtualWait(x))
expectEqual(246, await virtualWaitForInt(x))
expectNil(try? await virtualWait(orThrow: true, x))
try! await virtualWait(orThrow: false, x)
}
await runAllTestsAsync()
}
await task.value
}
}