Skip to content

Commit 6028912

Browse files
committed
Evolution: Test that adding or removing weak/unowned is a resilient change
1 parent 890bf2e commit 6028912

4 files changed

+98
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public var count = 0
2+
3+
public func getVersion() -> Int {
4+
#if BEFORE
5+
return 0
6+
#else
7+
return 1
8+
#endif
9+
}
10+
11+
public class MathClass {
12+
public init() {}
13+
}
14+
15+
public class Attributed {
16+
public init(x: MathClass, y: MathClass) {
17+
self.x = x
18+
self.y = y
19+
}
20+
21+
#if BEFORE
22+
public var x: MathClass?
23+
public var y: MathClass
24+
#else
25+
public weak var x: MathClass?
26+
public unowned var y: MathClass
27+
#endif
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public var count = 0
2+
3+
public func getVersion() -> Int {
4+
#if BEFORE
5+
return 0
6+
#else
7+
return 1
8+
#endif
9+
}
10+
11+
public class MathClass {
12+
public init() {}
13+
}
14+
15+
public struct Attributed {
16+
public init(x: MathClass, y: MathClass) {
17+
self.x = x
18+
self.y = y
19+
}
20+
21+
#if BEFORE
22+
public var x: MathClass?
23+
public var y: MathClass
24+
#else
25+
public weak var x: MathClass?
26+
public unowned var y: MathClass
27+
#endif
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-resilience-test
2+
// REQUIRES: executable_test
3+
4+
import StdlibUnittest
5+
import class_add_property_attribute
6+
7+
8+
var AddPropertyAttribute = TestSuite("AddPropertyAttribute")
9+
10+
AddPropertyAttribute.test("AddPropertyAttribute") {
11+
do {
12+
let x = MathClass()
13+
let y = MathClass()
14+
15+
let a = Attributed(x: x, y: y)
16+
expectTrue(x === a.x)
17+
expectTrue(y === a.y)
18+
}
19+
}
20+
21+
runAllTests()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-resilience-test
2+
// REQUIRES: executable_test
3+
4+
import StdlibUnittest
5+
import struct_add_property_attribute
6+
7+
8+
var AddPropertyAttribute = TestSuite("AddPropertyAttribute")
9+
10+
AddPropertyAttribute.test("AddPropertyAttribute") {
11+
do {
12+
let x = MathClass()
13+
let y = MathClass()
14+
15+
let a = Attributed(x: x, y: y)
16+
expectTrue(x === a.x)
17+
expectTrue(y === a.y)
18+
}
19+
}
20+
21+
runAllTests()

0 commit comments

Comments
 (0)