Skip to content

Commit a90ad0e

Browse files
committed
[lldb] Add Swift/C++ backward interop expression evaluation tests
rdar://100284870
1 parent b88dc63 commit a90ad0e

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SWIFT_CXX_HEADER := swift-types.h
2+
SWIFT_SOURCES := swift-types.swift
3+
CXX_SOURCES := main.cpp
4+
SWIFT_CXX_INTEROP := 1
5+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR) -parse-as-library
6+
CFLAGS = -I. -g
7+
include Makefile.rules
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
"""
3+
Test that evaluating expressions works on backward interop mode.
4+
"""
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test.decorators import *
7+
8+
9+
class TestSwiftBackwardInteropExpressions(TestBase):
10+
11+
@swiftTest
12+
def test_func_step_in(self):
13+
self.build()
14+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
15+
_, _, _, _ = lldbutil.run_to_source_breakpoint(
16+
self, 'Break here', lldb.SBFileSpec('main.cpp'))
17+
self.expect('expr swiftFunc()', substrs=["Inside a Swift function"])
18+
self.expect('expr swiftClass.swiftMethod()', substrs=["Inside a Swift method"])
19+
self.expect('expr a::SwiftClass::swiftStaticMethod()', substrs=["In a Swift static method"])
20+
self.expect('expr swiftClass.getSwiftProperty()', substrs=["This is a class with properties"])
21+
self.expect('expr swiftSubclassAsClass.overrideableMethod()', substrs=["In subclass"])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "swift-types.h"
2+
3+
using namespace a;
4+
5+
int main() {
6+
swiftFunc();
7+
auto swiftClass = SwiftClass::init();
8+
swiftClass.swiftMethod();
9+
SwiftClass::swiftStaticMethod();
10+
swiftClass.getSwiftProperty();
11+
auto swiftSubclass = SwiftSubclass::init();
12+
SwiftClass swiftSubclassAsClass = swiftSubclass;
13+
swiftSubclassAsClass.overrideableMethod();
14+
return 0; // Break here
15+
}
16+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
public func swiftFunc() -> String{
3+
return "Inside a Swift function!"
4+
}
5+
6+
public class SwiftClass {
7+
var field: Int
8+
var arr: [String]
9+
public init() {
10+
field = 42
11+
arr = ["An", "array", "of", "strings"]
12+
}
13+
14+
public func swiftMethod() -> String {
15+
return "Inside a Swift method!"
16+
}
17+
18+
private var _desc = "This is a class with properties!"
19+
public var swiftProperty: String {
20+
get {
21+
return _desc
22+
}
23+
}
24+
25+
public static func swiftStaticMethod() -> String {
26+
return "In a Swift static method!"
27+
}
28+
29+
public func overrideableMethod() -> String {
30+
return "In the base class!"
31+
}
32+
}
33+
34+
public class SwiftSubclass: SwiftClass {
35+
public override func overrideableMethod() -> String {
36+
return "In subclass!"
37+
}
38+
}
39+

0 commit comments

Comments
 (0)