Skip to content

Commit 7229ce2

Browse files
committed
Convert resilient superclass dispatch tests to StdlibUnittest
Also run the full product of before/after combinations.
1 parent eecf025 commit 7229ce2

File tree

4 files changed

+185
-112
lines changed

4 files changed

+185
-112
lines changed

validation-test/Evolution/Inputs/superclass_methods.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
19
public class Base {
210
public init() {}
311
public func method() -> String {

validation-test/Evolution/Inputs/superclass_properties.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
19
public class Base {
210
public init() {}
311
public var property: String {
Lines changed: 85 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,108 @@
11
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
// RUN: %target-build-swift -emit-module -emit-library -module-name superclass_methods -emit-module-path %t/superclass_methods.swiftmodule -Xfrontend -enable-resilience -D BEFORE %S/Inputs/superclass_methods.swift -o %t/before/superclass_methods.o
3-
// RUN: %target-build-swift -c %s -I %t -Xfrontend -enable-resilience -o %t/main.o
4-
// RUN: %target-build-swift %t/before/superclass_methods.o %t/main.o -o %t/before/main
5-
// RUN: %t/before/main | FileCheck --check-prefix=BEFORE %s
6-
// RUN: %target-build-swift -emit-module -emit-library -module-name superclass_methods -emit-module-path %t/superclass_methods.swiftmodule -Xfrontend -enable-resilience -D AFTER %S/Inputs/superclass_methods.swift -o %t/after/superclass_methods.o
7-
// RUN: %target-build-swift %t/after/superclass_methods.o %t/main.o -o %t/after/main -v
8-
// RUN: %t/after/main | FileCheck --check-prefix=AFTER %s
92

3+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/superclass_methods.swift -o %t/before/superclass_methods.o
4+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/superclass_methods.swift -o %t/before/superclass_methods.o
5+
6+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/superclass_methods.swift -o %t/after/superclass_methods.o
7+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/superclass_methods.swift -o %t/after/superclass_methods.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/superclass_methods.o %t/before/main.o -o %t/before_before
13+
// RUN: %target-build-swift %t/before/superclass_methods.o %t/after/main.o -o %t/before_after
14+
// RUN: %target-build-swift %t/after/superclass_methods.o %t/before/main.o -o %t/after_before
15+
// RUN: %target-build-swift %t/after/superclass_methods.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
1023
import superclass_methods
1124

12-
do {
13-
class Leaf : AddInterposingMethod {
14-
override func method() -> String {
15-
return super.method()
25+
var SuperclassMethodsTest = TestSuite("SuperclassMethods")
26+
27+
SuperclassMethodsTest.test("AddInterposingMethod") {
28+
do {
29+
class Leaf : AddInterposingMethod {
30+
override func method() -> String {
31+
return super.method()
32+
}
33+
override class func classMethod() -> String {
34+
return super.classMethod()
35+
}
1636
}
17-
override class func classMethod() -> String {
18-
return super.classMethod()
37+
if getVersion() == 0 {
38+
expectEqual(Leaf().method(), "Base.method()")
39+
expectEqual(Leaf.classMethod(), "Base.classMethod()")
40+
} else {
41+
expectEqual(Leaf().method(), "AddInterposingMethod.method()")
42+
expectEqual(Leaf.classMethod(), "AddInterposingMethod.classMethod()")
1943
}
2044
}
21-
let leaf = Leaf()
22-
print(leaf.method())
23-
print(Leaf.classMethod())
24-
// BEFORE: Base.method()
25-
// BEFORE: Base.classMethod()
26-
// AFTER: AddInterposingMethod.method()
27-
// AFTER: AddInterposingMethod.classMethod()
2845
}
2946

30-
do {
31-
class Leaf : RemoveInterposingMethod {
32-
override func method() -> String {
33-
return super.method()
47+
SuperclassMethodsTest.test("RemoveInterposingMethod") {
48+
do {
49+
class Leaf : RemoveInterposingMethod {
50+
override func method() -> String {
51+
return super.method()
52+
}
53+
override class func classMethod() -> String {
54+
return super.classMethod()
55+
}
3456
}
35-
override class func classMethod() -> String {
36-
return super.classMethod()
57+
if getVersion() == 0 {
58+
expectEqual(Leaf().method(), "RemoveInterposingMethod.method()")
59+
expectEqual(Leaf.classMethod(), "RemoveInterposingMethod.classMethod()")
60+
} else {
61+
expectEqual(Leaf().method(), "Base.method()")
62+
expectEqual(Leaf.classMethod(), "Base.classMethod()")
3763
}
3864
}
39-
print(Leaf().method())
40-
print(Leaf.classMethod())
41-
// BEFORE: RemoveInterposingMethod.method()
42-
// BEFORE: RemoveInterposingMethod.classMethod()
43-
// AFTER: Base.method()
44-
// AFTER: Base.classMethod()
4565
}
4666

47-
do {
48-
class Leaf : InsertSuperclass {
49-
override func method() -> String {
50-
return super.method()
67+
SuperclassMethodsTest.test("InsertSuperclass") {
68+
do {
69+
class Leaf : InsertSuperclass {
70+
override func method() -> String {
71+
return super.method()
72+
}
73+
override class func classMethod() -> String {
74+
return super.classMethod()
75+
}
5176
}
52-
override class func classMethod() -> String {
53-
return super.classMethod()
77+
if getVersion() == 0 {
78+
expectEqual(Leaf().method(), "Base.method()")
79+
expectEqual(Leaf.classMethod(), "Base.classMethod()")
80+
} else {
81+
expectEqual(Leaf().method(), "InBetween.method()")
82+
expectEqual(Leaf.classMethod(), "InBetween.classMethod()")
5483
}
5584
}
56-
print(Leaf().method())
57-
print(Leaf.classMethod())
58-
// BEFORE: Base.method()
59-
// BEFORE: Base.classMethod()
60-
// AFTER: InBetween.method()
61-
// AFTER: InBetween.classMethod()
6285
}
6386

64-
do {
65-
class Leaf : ChangeRoot {
66-
override func method() -> String {
67-
return super.method()
87+
SuperclassMethodsTest.test("ChangeRoot") {
88+
do {
89+
class Leaf : ChangeRoot {
90+
override func method() -> String {
91+
return super.method()
92+
}
93+
override class func classMethod() -> String {
94+
return super.classMethod()
95+
}
6896
}
69-
override class func classMethod() -> String {
70-
return super.classMethod()
97+
if getVersion() == 0 {
98+
expectEqual(Leaf().method(), "Base.method()")
99+
expectEqual(Leaf.classMethod(), "Base.classMethod()")
100+
} else {
101+
expectEqual(Leaf().method(), "OtherBase.method()")
102+
expectEqual(Leaf.classMethod(), "OtherBase.classMethod()")
71103
}
72104
}
73-
print(Leaf().method())
74-
print(Leaf.classMethod())
75-
// BEFORE: Base.method()
76-
// BEFORE: Base.classMethod()
77-
// AFTER: OtherBase.method()
78-
// AFTER: OtherBase.classMethod()
79105
}
106+
107+
runAllTests()
108+
Lines changed: 84 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,107 @@
11
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
// RUN: %target-build-swift -emit-module -emit-library -module-name superclass_properties -emit-module-path %t/superclass_properties.swiftmodule -Xfrontend -enable-resilience -D BEFORE %S/Inputs/superclass_properties.swift -o %t/before/superclass_properties.o
3-
// RUN: %target-build-swift -c %s -I %t -Xfrontend -enable-resilience -o %t/main.o
4-
// RUN: %target-build-swift %t/before/superclass_properties.o %t/main.o -o %t/before/main
5-
// RUN: %t/before/main | FileCheck --check-prefix=BEFORE %s
6-
// RUN: %target-build-swift -emit-module -emit-library -module-name superclass_properties -emit-module-path %t/superclass_properties.swiftmodule -Xfrontend -enable-resilience -D AFTER %S/Inputs/superclass_properties.swift -o %t/after/superclass_properties.o
7-
// RUN: %target-build-swift %t/after/superclass_properties.o %t/main.o -o %t/after/main -v
8-
// RUN: %t/after/main | FileCheck --check-prefix=AFTER %s
92

3+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/superclass_properties.swift -o %t/before/superclass_properties.o
4+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/superclass_properties.swift -o %t/before/superclass_properties.o
5+
6+
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/superclass_properties.swift -o %t/after/superclass_properties.o
7+
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/superclass_properties.swift -o %t/after/superclass_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/superclass_properties.o %t/before/main.o -o %t/before_before
13+
// RUN: %target-build-swift %t/before/superclass_properties.o %t/after/main.o -o %t/before_after
14+
// RUN: %target-build-swift %t/after/superclass_properties.o %t/before/main.o -o %t/after_before
15+
// RUN: %target-build-swift %t/after/superclass_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
1023
import superclass_properties
1124

12-
do {
13-
class Leaf : AddInterposingProperty {
14-
override var property: String {
15-
return super.property
25+
var SuperclassPropertiesTest = TestSuite("SuperclassProperties")
26+
27+
SuperclassPropertiesTest.test("AddInterposingProperty") {
28+
do {
29+
class Leaf : AddInterposingProperty {
30+
override var property: String {
31+
return super.property
32+
}
33+
override class var classProperty: String {
34+
return super.classProperty
35+
}
1636
}
17-
override class var classProperty: String {
18-
return super.classProperty
37+
if getVersion() == 0 {
38+
expectEqual(Leaf().property, "Base.property")
39+
expectEqual(Leaf.classProperty, "Base.classProperty")
40+
} else {
41+
expectEqual(Leaf().property, "AddInterposingProperty.property")
42+
expectEqual(Leaf.classProperty, "AddInterposingProperty.classProperty")
1943
}
2044
}
21-
let leaf = Leaf()
22-
print(leaf.property)
23-
print(Leaf.classProperty)
24-
// BEFORE: Base.property
25-
// BEFORE: Base.classProperty
26-
// AFTER: AddInterposingProperty.property
27-
// AFTER: AddInterposingProperty.classProperty
2845
}
2946

30-
do {
31-
class Leaf : RemoveInterposingProperty {
32-
override var property: String {
33-
return super.property
47+
SuperclassPropertiesTest.test("RemoveInterposingProperty") {
48+
do {
49+
class Leaf : RemoveInterposingProperty {
50+
override var property: String {
51+
return super.property
52+
}
53+
override class var classProperty: String {
54+
return super.classProperty
55+
}
3456
}
35-
override class var classProperty: String {
36-
return super.classProperty
57+
if getVersion() == 0 {
58+
expectEqual(Leaf().property, "RemoveInterposingProperty.property")
59+
expectEqual(Leaf.classProperty, "RemoveInterposingProperty.classProperty")
60+
} else {
61+
expectEqual(Leaf().property, "Base.property")
62+
expectEqual(Leaf.classProperty, "Base.classProperty")
3763
}
3864
}
39-
print(Leaf().property)
40-
print(Leaf.classProperty)
41-
// BEFORE: RemoveInterposingProperty.property
42-
// BEFORE: RemoveInterposingProperty.classProperty
43-
// AFTER: Base.property
44-
// AFTER: Base.classProperty
4565
}
4666

47-
do {
48-
class Leaf : InsertSuperclass {
49-
override var property: String {
50-
return super.property
67+
SuperclassPropertiesTest.test("InsertSuperclass") {
68+
do {
69+
class Leaf : InsertSuperclass {
70+
override var property: String {
71+
return super.property
72+
}
73+
override class var classProperty: String {
74+
return super.classProperty
75+
}
5176
}
52-
override class var classProperty: String {
53-
return super.classProperty
77+
if getVersion() == 0 {
78+
expectEqual(Leaf().property, "Base.property")
79+
expectEqual(Leaf.classProperty, "Base.classProperty")
80+
} else {
81+
expectEqual(Leaf().property, "InBetween.property")
82+
expectEqual(Leaf.classProperty, "InBetween.classProperty")
5483
}
5584
}
56-
print(Leaf().property)
57-
print(Leaf.classProperty)
58-
// BEFORE: Base.property
59-
// BEFORE: Base.classProperty
60-
// AFTER: InBetween.property
61-
// AFTER: InBetween.classProperty
6285
}
6386

64-
do {
65-
class Leaf : ChangeRoot {
66-
override var property: String {
67-
return super.property
87+
SuperclassPropertiesTest.test("ChangeRoot") {
88+
do {
89+
class Leaf : ChangeRoot {
90+
override var property: String {
91+
return super.property
92+
}
93+
override class var classProperty: String {
94+
return super.classProperty
95+
}
6896
}
69-
override class var classProperty: String {
70-
return super.classProperty
97+
if getVersion() == 0 {
98+
expectEqual(Leaf().property, "Base.property")
99+
expectEqual(Leaf.classProperty, "Base.classProperty")
100+
} else {
101+
expectEqual(Leaf().property, "OtherBase.property")
102+
expectEqual(Leaf.classProperty, "OtherBase.classProperty")
71103
}
72104
}
73-
print(Leaf().property)
74-
print(Leaf.classProperty)
75-
// BEFORE: Base.property
76-
// BEFORE: Base.classProperty
77-
// AFTER: OtherBase.property
78-
// AFTER: OtherBase.classProperty
79105
}
106+
107+
runAllTests()

0 commit comments

Comments
 (0)