Skip to content

Commit e711d5e

Browse files
committed
Preliminary evolution tests
Checking these in to get some discussion over FileCheck style and test file structure going before I write too many more tests.
1 parent 199468f commit e711d5e

6 files changed

+424
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
public func getVersion() -> Int {
3+
#if BEFORE
4+
return 0
5+
#else
6+
return 1
7+
#endif
8+
}
9+
10+
@_fixed_layout public struct AddRemoveConformance {
11+
public init() {
12+
x = 0
13+
y = 0
14+
}
15+
16+
public var x: Int
17+
public var y: Int
18+
19+
public var z: Int {
20+
get { return x + y }
21+
set {
22+
x = newValue / 2
23+
y = newValue - x
24+
}
25+
}
26+
}
27+
28+
public protocol PointLike {
29+
var x: Int { get set }
30+
var y: Int { get set }
31+
}
32+
33+
public protocol Point3DLike {
34+
var z: Int { get set }
35+
}
36+
37+
#if AFTER
38+
extension AddRemoveConformance : PointLike {}
39+
extension AddRemoveConformance : Point3DLike {}
40+
#endif
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
#if BEFORE
3+
4+
public struct ChangeStoredToComputed {
5+
public init() {
6+
celcius = 0
7+
}
8+
9+
public var celcius: Int
10+
11+
public var fahrenheit: Int {
12+
get {
13+
return (celcius * 9) / 5 + 32
14+
}
15+
set {
16+
celcius = ((newValue - 32) * 5) / 9
17+
}
18+
}
19+
}
20+
21+
#else
22+
23+
public struct ChangeStoredToComputed {
24+
public init() {
25+
fahrenheit = 32
26+
}
27+
28+
public var celcius: Int {
29+
get {
30+
return ((fahrenheit - 32) * 5) / 9
31+
}
32+
set {
33+
fahrenheit = (newValue * 9) / 5 + 32
34+
}
35+
}
36+
37+
public var fahrenheit: Int = 32
38+
}
39+
40+
#endif
41+
42+
43+
#if BEFORE
44+
45+
var global: Int = 0
46+
47+
public struct ChangeEmptyToNonEmpty {
48+
public init() {}
49+
50+
public var property: Int {
51+
get { return global }
52+
set { global = newValue }
53+
}
54+
}
55+
56+
#else
57+
58+
public struct ChangeEmptyToNonEmpty {
59+
public init() {
60+
property = 0
61+
}
62+
63+
public var property: Int
64+
}
65+
66+
#endif
67+
68+
public func getProperty(c: ChangeEmptyToNonEmpty) -> Int {
69+
return c.property
70+
}
71+
72+
73+
#if BEFORE
74+
75+
public struct AddStoredProperty {
76+
public init() {
77+
count = 0
78+
}
79+
80+
public var count: Int
81+
}
82+
83+
#else
84+
85+
public struct AddStoredProperty {
86+
public init() {
87+
_count = 0
88+
_sign = 0
89+
}
90+
91+
public var count: Int {
92+
get { return _count * _sign }
93+
set {
94+
if newValue < 0 {
95+
_count = -newValue
96+
_sign = -1
97+
} else {
98+
_count = newValue
99+
_sign = 1
100+
}
101+
}
102+
}
103+
104+
private var _count: Int
105+
private var _sign: Int
106+
}
107+
108+
#endif
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
public struct ChangeSize {
3+
public init() {
4+
_value = 0
5+
}
6+
7+
public var value: Int32 {
8+
get { return Int32(_value) }
9+
set { _value = T(newValue) }
10+
}
11+
12+
#if BEFORE
13+
typealias T = Int32
14+
#else
15+
typealias T = Int64
16+
#endif
17+
18+
private var _value: T
19+
}
20+
21+
@_fixed_layout public struct ChangeFieldOffsetsOfFixedLayout {
22+
public init() {
23+
v1 = ChangeSize()
24+
v2 = ChangeSize()
25+
}
26+
27+
public var v1: ChangeSize
28+
public var v2: ChangeSize
29+
30+
public func getTotal() -> Int32 {
31+
return v1.value + v2.value
32+
}
33+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2+
3+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_add_remove_conformances.swift -o %t/before/struct_add_remove_conformances.o
4+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_add_remove_conformances.swift -o %t/before/struct_add_remove_conformances.o
5+
6+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_add_remove_conformances.swift -o %t/after/struct_add_remove_conformances.o
7+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_add_remove_conformances.swift -o %t/after/struct_add_remove_conformances.o
8+
9+
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10+
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11+
12+
// RUN: %target-build-swift %t/before/struct_add_remove_conformances.o %t/before/main.o -o %t/before_before
13+
// RUN: %target-build-swift %t/before/struct_add_remove_conformances.o %t/after/main.o -o %t/before_after
14+
// RUN: %target-build-swift %t/after/struct_add_remove_conformances.o %t/before/main.o -o %t/after_before
15+
// RUN: %target-build-swift %t/after/struct_add_remove_conformances.o %t/after/main.o -o %t/after_after
16+
17+
// RUN: %target-run %t/before_before
18+
// RUN: %target-run %t/before_after
19+
// RUN: %target-run %t/after_before
20+
// RUN: %target-run %t/after_after
21+
22+
// Requires fixes to @_transparent attribute
23+
// XFAIL: *
24+
25+
import StdlibUnittest
26+
import struct_add_remove_conformances
27+
28+
var StructAddRemoveConformancesTest = TestSuite("StructAddRemoveConformances")
29+
30+
StructAddRemoveConformancesTest.test("AddRemoveConformance") {
31+
var t = AddRemoveConformance()
32+
33+
do {
34+
t.x = 10
35+
t.y = 20
36+
expectEqual(t.x, 10)
37+
expectEqual(t.y, 20)
38+
}
39+
40+
if getVersion() > 0 {
41+
var p = t as! PointLike
42+
p.x = 30
43+
p.y = 40
44+
expectEqual(p.x, 30)
45+
expectEqual(p.y, 40)
46+
} else {
47+
expectEqual(t is PointLike, false)
48+
}
49+
}
50+
51+
#if AFTER
52+
protocol MyPointLike {
53+
var x: Int { get set }
54+
var y: Int { get set }
55+
}
56+
57+
protocol MyPoint3DLike {
58+
var z: Int { get set }
59+
}
60+
61+
extension AddRemoveConformance : MyPointLike {}
62+
extension AddRemoveConformance : MyPoint3DLike {}
63+
64+
StructAddRemoveConformancesTest.test("MyPointLike") {
65+
var p: MyPointLike = AddRemoveConformance()
66+
67+
p.x = 50
68+
p.y = 60
69+
expectEqual(p.x, 50)
70+
expectEqual(p.y, 60)
71+
}
72+
#endif
73+
74+
runAllTests()
75+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2+
3+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_add_remove_properties.swift -o %t/before/struct_add_remove_properties.o
4+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/struct_add_remove_properties.swift -o %t/before/struct_add_remove_properties.o
5+
6+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_add_remove_properties.swift -o %t/after/struct_add_remove_properties.o
7+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/struct_add_remove_properties.swift -o %t/after/struct_add_remove_properties.o
8+
9+
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10+
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11+
12+
// RUN: %target-build-swift %t/before/struct_add_remove_properties.o %t/before/main.o -o %t/before_before
13+
// RUN: %target-build-swift %t/before/struct_add_remove_properties.o %t/after/main.o -o %t/before_after
14+
// RUN: %target-build-swift %t/after/struct_add_remove_properties.o %t/before/main.o -o %t/after_before
15+
// RUN: %target-build-swift %t/after/struct_add_remove_properties.o %t/after/main.o -o %t/after_after
16+
17+
// RUN: %target-run %t/before_before
18+
// RUN: %target-run %t/before_after
19+
// RUN: %target-run %t/after_before
20+
// RUN: %target-run %t/after_after
21+
22+
import StdlibUnittest
23+
import struct_add_remove_properties
24+
25+
var StructAddRemovePropertiesTest = TestSuite("StructAddRemoveProperties")
26+
27+
StructAddRemovePropertiesTest.test("ChangeStoredToComputed") {
28+
var t = ChangeStoredToComputed()
29+
30+
do {
31+
expectEqual(t.celcius, 0)
32+
expectEqual(t.fahrenheit, 32)
33+
}
34+
35+
do {
36+
t.celcius = 10
37+
expectEqual(t.celcius, 10)
38+
expectEqual(t.fahrenheit, 50)
39+
}
40+
41+
do {
42+
func increaseTemperature(inout t: Int) {
43+
t += 10
44+
}
45+
46+
increaseTemperature(&t.celcius)
47+
48+
expectEqual(t.celcius, 20)
49+
expectEqual(t.fahrenheit, 68)
50+
}
51+
}
52+
53+
StructAddRemovePropertiesTest.test("ChangeEmptyToNonEmpty") {
54+
var t = ChangeEmptyToNonEmpty()
55+
56+
do {
57+
expectEqual(t.property, 0)
58+
t.property += 1
59+
expectEqual(t.property, 1)
60+
}
61+
62+
do {
63+
func increment(inout t: Int) {
64+
t += 1
65+
}
66+
67+
increment(&t.property)
68+
expectEqual(t.property, 2)
69+
}
70+
71+
do {
72+
expectEqual(getProperty(t), 2)
73+
}
74+
}
75+
76+
StructAddRemovePropertiesTest.test("AddStoredProperty") {
77+
var t = AddStoredProperty()
78+
79+
do {
80+
expectEqual(t.count, 0)
81+
t.count = 100
82+
expectEqual(t.count, 100)
83+
}
84+
85+
do {
86+
t.count = -1000
87+
expectEqual(t.count, -1000)
88+
}
89+
}
90+
91+
runAllTests()

0 commit comments

Comments
 (0)