forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
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
classMyDerived:BaseClass<Int>{
overridefunc waitForNothing()async{
await super.waitForNothing()
}
overridefunc wait()async->Int{
returnawait super.wait()*2
}
overridefunc waitForInt()async->Int{
returnawait super.waitForInt()*2
}
overridefunc wait(orThrow:Bool)asyncthrows{
returntryawait super.wait(orThrow: orThrow)
}
}
func virtualWaitForNothing<T>(_ c:BaseClass<T>)async{
await c.waitForNothing()
}
func virtualWait<T>(_ c:BaseClass<T>)async->T{
returnawait c.wait()
}
func virtualWaitForInt<T>(_ c:BaseClass<T>)async->Int{
returnawait c.waitForInt()
}
func virtualWait<T>(orThrow:Bool, _ c:BaseClass<T>)asyncthrows{
returntryawait c.wait(orThrow: orThrow)
}
@mainstructMain{
staticfunc main()async{
lettask=Task.detached{
varAsyncVTableMethodSuite=TestSuite("ResilientClass")
AsyncVTableMethodSuite.test("AsyncVTableMethod"){
letx=MyDerived(value:321)
awaitvirtualWaitForNothing(x)
expectEqual(642,awaitvirtualWait(x))
expectEqual(246,awaitvirtualWaitForInt(x))
expectNil(try?awaitvirtualWait(orThrow:true, x))
try!awaitvirtualWait(orThrow:false, x)
}
awaitrunAllTestsAsync()
}
await task.value
}
}