Skip to content

Commit 286be23

Browse files
committed
Evolution: Add backward deployment tests
1 parent ac32948 commit 286be23

10 files changed

+512
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
9+
public struct ResilientStruct {
10+
public init() {}
11+
}
12+
13+
#if AFTER
14+
@_weakLinked public class ResilientClass {
15+
public init() {}
16+
17+
public func fn(_ x: Int) {}
18+
19+
public var storedProp: Int = 0
20+
21+
public var computedProp: Int {
22+
get { return 0 }
23+
set { }
24+
}
25+
26+
public subscript(idx: Int) -> Int {
27+
get { return 0 }
28+
set { }
29+
}
30+
}
31+
32+
@_weakLinked @_fixed_layout public class FixedLayoutClass {
33+
public init() {}
34+
35+
public func fn(_ x: Int) {}
36+
37+
// Make the first field resilient so that the second one has to be accessed
38+
// with a field offset global
39+
private var resilientField = ResilientStruct()
40+
41+
public var storedProp: Int = 0
42+
43+
public var computedProp: Int {
44+
get { return 0 }
45+
set { }
46+
}
47+
48+
public subscript(idx: Int) -> Int {
49+
get { return 0 }
50+
set { }
51+
}
52+
}
53+
#endif
54+
55+
// Overriding a weak-linked method
56+
open class OpenClass {
57+
public init() {}
58+
59+
open func oldMethod() {}
60+
61+
#if AFTER
62+
@_weakLinked open func newMethod() {}
63+
#endif
64+
}
65+
66+
// Inserting a superclass
67+
open class Bottom {
68+
public init() {}
69+
70+
open func bottomMethod() {}
71+
}
72+
73+
#if BEFORE
74+
75+
open class Top : Bottom {}
76+
77+
#else
78+
79+
@_weakLinked open class Middle : Bottom {
80+
open func middleMethod() {}
81+
}
82+
83+
open class Top : Middle {}
84+
85+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
9+
public enum ResilientEnum {
10+
case first
11+
case second
12+
13+
#if AFTER
14+
@_weakLinked case third
15+
#endif
16+
17+
case fourth
18+
case fifth
19+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
9+
public protocol OtherProtocol {
10+
init()
11+
}
12+
public struct OtherConcrete : OtherProtocol {
13+
public init() {}
14+
}
15+
16+
public protocol OldProtocol {
17+
#if AFTER
18+
@_weakLinked associatedtype NewType: OtherProtocol = OtherConcrete
19+
@_weakLinked func newMethod() -> NewType
20+
#endif
21+
}
22+
23+
#if AFTER
24+
extension OldProtocol {
25+
@_weakLinked public func newMethod() -> NewType {
26+
return NewType()
27+
}
28+
}
29+
#endif
30+
31+
#if AFTER
32+
@_weakLinked public protocol NewProtocol {
33+
func newMethod()
34+
}
35+
#endif
36+
37+
public struct NewConforms {
38+
public init() {}
39+
}
40+
41+
#if AFTER
42+
@_weakLinked extension NewConforms : NewProtocol {
43+
public func newMethod() {}
44+
}
45+
#endif
46+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
9+
#if AFTER
10+
@_weakLinked public struct ResilientStruct {
11+
public init() {}
12+
13+
public func fn(_ x: Int) {}
14+
15+
public var storedProp: Int = 0
16+
17+
public var computedProp: Int {
18+
get { return 0 }
19+
set { }
20+
}
21+
22+
public subscript(idx: Int) -> Int {
23+
get { return 0 }
24+
set { }
25+
}
26+
}
27+
28+
@_weakLinked @_fixed_layout public struct FixedLayoutStruct {
29+
public init() {}
30+
31+
public func fn(_ x: Int) {}
32+
33+
public var storedProp: Int = 0
34+
35+
public var computedProp: Int {
36+
get { return 0 }
37+
set { }
38+
}
39+
40+
public subscript(idx: Int) -> Int {
41+
get { return 0 }
42+
set { }
43+
}
44+
}
45+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
9+
#if AFTER
10+
@_weakLinked public func topLevelFunction(_ x: Int) {}
11+
12+
@_weakLinked public var storedGlobal: Int = 0
13+
14+
@_weakLinked public var computedGlobal: Int {
15+
get {
16+
return 0
17+
}
18+
set {}
19+
}
20+
#endif
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// RUN: %target-resilience-test --backward-deployment
2+
// REQUIRES: executable_test
3+
4+
import StdlibUnittest
5+
import backward_deploy_class
6+
7+
8+
var BackwardDeployClassTest = TestSuite("BackwardDeployClass")
9+
10+
BackwardDeployClassTest.test("ResilientClass") {
11+
if getVersion() == 1 {
12+
let s = ResilientClass()
13+
14+
s.fn(s.storedProp)
15+
s.storedProp = 1
16+
s.storedProp += 1
17+
18+
s.fn(s.computedProp)
19+
s.computedProp = 1
20+
s.computedProp += 1
21+
22+
s.fn(s[0])
23+
s[0] = 1
24+
s[0] += 1
25+
}
26+
}
27+
28+
BackwardDeployClassTest.test("FixedLayoutClass") {
29+
if getVersion() == 1 {
30+
let s = FixedLayoutClass()
31+
32+
s.fn(s.storedProp)
33+
s.storedProp = 1
34+
s.storedProp += 1
35+
36+
s.fn(s.computedProp)
37+
s.computedProp = 1
38+
s.computedProp += 1
39+
40+
s.fn(s[0])
41+
s[0] = 1
42+
s[0] += 1
43+
}
44+
}
45+
46+
BackwardDeployClassTest.test("OpenClass") {
47+
class DerivedClass : OpenClass {
48+
var count: Int = 0
49+
50+
override func oldMethod() {
51+
count += 1
52+
super.oldMethod()
53+
}
54+
55+
override func newMethod() {
56+
count += 10
57+
super.newMethod()
58+
}
59+
}
60+
61+
let d = DerivedClass()
62+
63+
d.oldMethod()
64+
if getVersion() == 1 {
65+
d.newMethod()
66+
expectEqual(d.count, 11)
67+
} else {
68+
expectEqual(d.count, 1)
69+
}
70+
}
71+
72+
BackwardDeployClassTest.test("InsertSuperclass") {
73+
class DerivedClass : Top {
74+
var count: Int = 0
75+
76+
override func bottomMethod() {
77+
count += 1
78+
super.bottomMethod()
79+
}
80+
81+
override func middleMethod() {
82+
count += 10
83+
super.middleMethod()
84+
}
85+
}
86+
87+
let d = DerivedClass()
88+
89+
d.bottomMethod()
90+
if getVersion() == 1 {
91+
d.middleMethod()
92+
expectEqual(d.count, 11)
93+
} else {
94+
expectEqual(d.count, 1)
95+
}
96+
}
97+
98+
runAllTests()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %target-resilience-test --backward-deployment
2+
// REQUIRES: executable_test
3+
4+
import StdlibUnittest
5+
import backward_deploy_enum
6+
7+
// <rdar://problem/46438568>
8+
// XFAIL: *
9+
10+
var BackwardDeployEnumTest = TestSuite("BackwardDeployEnum")
11+
12+
func checkIt(_ e: ResilientEnum) -> Int {
13+
switch e {
14+
case .first:
15+
return 1
16+
case .second:
17+
return 2
18+
case .third:
19+
return 3
20+
case .fourth:
21+
return 4
22+
default:
23+
return 5
24+
}
25+
}
26+
27+
BackwardDeployEnumTest.test("ResilientEnum") {
28+
29+
expectEqual(1, checkIt(.first))
30+
expectEqual(2, checkIt(.second))
31+
expectEqual(4, checkIt(.fourth))
32+
expectEqual(5, checkIt(.fifth))
33+
34+
if getVersion() == 1 {
35+
expectEqual(3, checkIt(.third))
36+
}
37+
}
38+
39+
runAllTests()

0 commit comments

Comments
 (0)