Skip to content

Commit 8227501

Browse files
committed
[lldb] Add tests for more Swift types displayed in C++
rdar://100284870
1 parent 7dae980 commit 8227501

File tree

3 files changed

+140
-17
lines changed

3 files changed

+140
-17
lines changed

lldb/test/API/lang/swift/cxx_interop/backward/test-format-swift-types-in-cxx/TestSwiftFormatSwiftTypesInCxx.py

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,91 @@
88

99
class TestSwiftFormatSwiftTypesInCxx(TestBase):
1010

11-
@swiftTest
12-
def test_class(self):
11+
def setup(self, bkpt_str):
1312
self.build()
1413
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
1514
_, _, _, _= lldbutil.run_to_source_breakpoint(
16-
self, 'Set breakpoint here', lldb.SBFileSpec('main.cpp'))
15+
self, bkpt_str, lldb.SBFileSpec('main.cpp'))
16+
17+
@swiftTest
18+
def test_class(self):
19+
self.setup('Break here for class')
1720

1821
self.expect('v swiftClass', substrs=['SwiftClass', 'field = 42',
1922
'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
2023
'[3] = "strings"'])
21-
self.expect('p swiftClass', substrs=['SwiftClass', 'field = 42',
24+
self.expect('expr swiftClass', substrs=['SwiftClass', 'field = 42',
2225
'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
2326
'[3] = "strings"'])
2427

28+
@swiftTest
29+
def test_subclass(self):
30+
self.setup('Break here for subclass')
31+
2532
self.expect('v swiftSublass', substrs=['SwiftSubclass', 'field = 42',
2633
'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
2734
'[3] = "strings"', 'extraField = "this is an extra subclass field"'])
28-
self.expect('p swiftSublass', substrs=['SwiftSubclass', 'field = 42',
35+
self.expect('expr swiftSublass', substrs=['SwiftSubclass', 'field = 42',
2936
'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
3037
'[3] = "strings"', 'extraField = "this is an extra subclass field"'])
3138

39+
@swiftTest
40+
def test_struct(self):
41+
self.setup('Break here for struct')
42+
3243
self.expect('v swiftStruct', substrs=['SwiftStruct', 'str = "Hello this is a big string"',
3344
'boolean = true'])
34-
self.expect('p swiftStruct', substrs=['SwiftStruct', 'str = "Hello this is a big string"',
45+
self.expect('expr swiftStruct', substrs=['SwiftStruct', 'str = "Hello this is a big string"',
3546
'boolean = true'])
3647

37-
self.expect('v wrapper', substrs=['a.GenericPair<a.SwiftClass, a.SwiftStruct>',
48+
@swiftTest
49+
def test_generic_struct(self):
50+
self.setup('Break here for generic struct')
51+
52+
self.expect('v wrapper', substrs=['a.GenericStructPair<a.SwiftClass, a.SwiftStruct>',
3853
'field = 42', 'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
3954
'[3] = "strings"', 'str = "Hello this is a big string"', 'boolean = true'])
40-
self.expect('p wrapper', substrs=['a.GenericPair<a.SwiftClass, a.SwiftStruct>',
55+
self.expect('expr wrapper', substrs=['a.GenericStructPair<a.SwiftClass, a.SwiftStruct>',
4156
'field = 42', 'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
4257
'[3] = "strings"', 'str = "Hello this is a big string"', 'boolean = true'])
58+
59+
60+
@swiftTest
61+
def test_generic_enum(self):
62+
self.setup('Break here for generic enum')
63+
64+
self.expect('v swiftEnum', substrs=['a.GenericEnum<a.SwiftClass>', 'some',
65+
'field = 42', 'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
66+
'[3] = "strings"'])
67+
self.expect('expr swiftEnum', substrs=['a.GenericEnum<a.SwiftClass>', 'some',
68+
'field = 42', 'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
69+
'[3] = "strings"'])
70+
71+
72+
@swiftTest
73+
def test_swift_ivars(self):
74+
self.setup('Break here for swift ivars')
75+
76+
self.expect('v type_with_ivars', substrs=['TypeWithSwiftIvars', 'swiftClass',
77+
'field = 42', 'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
78+
'[3] = "strings"', 'swiftSubclass', 'field = 42', 'arr = 4 values',
79+
'[0] = "An"', '[1] = "array"', '[2] = "of"', '[3] = "strings"',
80+
'extraField = "this is an extra subclass field"',
81+
'str = "Hello this is a big string"', 'boolean = true'])
82+
self.expect('expr type_with_ivars', substrs=['TypeWithSwiftIvars', 'swiftClass',
83+
'field = 42', 'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
84+
'[3] = "strings"', 'swiftSubclass', 'field = 42', 'arr = 4 values',
85+
'[0] = "An"', '[1] = "array"', '[2] = "of"', '[3] = "strings"',
86+
'extraField = "this is an extra subclass field"',
87+
'str = "Hello this is a big string"', 'boolean = true'])
88+
89+
@swiftTest
90+
def test_typealias(self):
91+
self.setup('Break here for swift alias')
92+
93+
self.expect('v aliased', substrs=['SwiftClass', 'field = 42',
94+
'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
95+
'[3] = "strings"'])
96+
self.expect('expr aliased', substrs=['SwiftClass', 'field = 42',
97+
'arr = 4 values', '[0] = "An"', '[1] = "array"', '[2] = "of"',
98+
'[3] = "strings"'])
Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,62 @@
11
#include "swift-types.h"
22

3-
int main() {
4-
using namespace a;
3+
using namespace a;
4+
5+
int testSwiftClass() {
56
auto swiftClass = returnSwiftClass();
6-
auto swiftSublass = returnSwiftSubclassAsClass();
7+
return 0; // Break here for class
8+
}
9+
10+
int testSwiftSubclass() {
11+
auto swiftSublass = returnSwiftSubclass();
12+
return 0; // Break here for subclass
13+
}
14+
15+
int testSwiftStruct() {
716
auto swiftStruct = returnSwiftStruct();
8-
auto wrapper = returnPair(swiftClass, swiftStruct);
9-
return 0; // Set breakpoint here.
17+
return 0; // Break here for struct
18+
}
19+
20+
int testSwiftGenericStruct() {
21+
auto swiftClass = returnSwiftClass();
22+
auto swiftStruct = returnSwiftStruct();
23+
auto wrapper = returnStructPair(swiftClass, swiftStruct);
24+
return 0; // Break here for generic struct
25+
}
26+
27+
int testSwiftGenericEnum() {
28+
auto swiftClass = returnSwiftClass();
29+
auto swiftEnum = returnGenericEnum(swiftClass);
30+
return 0; // Break here for generic enum
31+
}
32+
33+
struct TypeWithSwiftIvars {
34+
SwiftClass swiftClass;
35+
SwiftSubclass swiftSubclass;
36+
SwiftStruct swiftStruct;
37+
38+
TypeWithSwiftIvars()
39+
: swiftClass(returnSwiftClass()), swiftSubclass(returnSwiftSubclass()),
40+
swiftStruct(returnSwiftStruct()) {}
41+
};
42+
43+
int testSwiftIvars() {
44+
TypeWithSwiftIvars type_with_ivars;
45+
return 0; // Break here for swift ivars
46+
}
47+
48+
int testSwiftAlias() {
49+
auto aliased = returnAliasedClass();
50+
return 0; // Break here for swift alias
51+
}
52+
53+
int main() {
54+
testSwiftClass();
55+
testSwiftSubclass();
56+
testSwiftStruct();
57+
testSwiftGenericStruct();
58+
testSwiftGenericEnum();
59+
testSwiftIvars();
60+
testSwiftAlias();
61+
return 0;
1062
}

lldb/test/API/lang/swift/cxx_interop/backward/test-format-swift-types-in-cxx/swift-types.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public struct SwiftStruct {
1414
}
1515

1616
@frozen
17-
public struct GenericPair<T, T2> {
17+
public struct GenericStructPair<T, T2> {
1818
var x: T
1919
var y: T2
2020

@@ -24,18 +24,33 @@ public struct GenericPair<T, T2> {
2424
}
2525
}
2626

27+
@frozen public enum GenericEnum<T> {
28+
case none
29+
case some(T)
30+
}
31+
2732
public func returnSwiftClass() -> SwiftClass {
2833
return SwiftClass()
2934
}
3035

31-
public func returnSwiftSubclassAsClass() -> SwiftClass {
36+
public func returnSwiftSubclass() -> SwiftSubclass {
3237
return SwiftSubclass()
3338
}
3439

3540
public func returnSwiftStruct() -> SwiftStruct {
3641
return SwiftStruct()
3742
}
3843

39-
public func returnPair<T, U>(t: T, u: U) -> GenericPair<T, U> {
40-
return GenericPair<T, U>(x: t, y: u)
44+
public func returnStructPair<T, U>(t: T, u: U) -> GenericStructPair<T, U> {
45+
return GenericStructPair<T, U>(x: t, y: u)
46+
}
47+
48+
public func returnGenericEnum<T>(t: T) -> GenericEnum<T> {
49+
return .some(t)
50+
}
51+
52+
public typealias MyAliasedClass = SwiftClass;
53+
54+
public func returnAliasedClass() -> MyAliasedClass {
55+
return SwiftClass()
4156
}

0 commit comments

Comments
 (0)