Skip to content

Commit 8c3c3fb

Browse files
Merge pull request #6042 from adrian-prantl/playground-split
Split playgrounds test into multiple test functions
2 parents d4a2322 + d79c229 commit 8c3c3fb

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,48 @@ def get_run_triple(self):
7070
@swiftTest
7171
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
7272
@skipIf(debug_info=decorators.no_match("dsym"))
73-
def test_cross_module_extension(self):
73+
def test_force_target(self):
74+
"""Test that playgrounds work"""
75+
self.launch(True)
76+
self.do_basic_test(True)
77+
78+
@skipUnlessDarwin
79+
@swiftTest
80+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
81+
@skipIf(debug_info=decorators.no_match("dsym"))
82+
def test_no_force_target(self):
83+
"""Test that playgrounds work"""
84+
self.launch(False)
85+
self.do_basic_test(False)
86+
87+
@skipUnlessDarwin
88+
@swiftTest
89+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
90+
@skipIf(debug_info=decorators.no_match("dsym"))
91+
def test_concurrency(self):
92+
"""Test that concurrency is available in playgrounds"""
93+
self.launch(True)
94+
self.do_concurrency_test()
95+
96+
@skipUnlessDarwin
97+
@swiftTest
98+
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
99+
@skipIf(debug_info=decorators.no_match("dsym"))
100+
def test_import(self):
101+
"""Test that a dylib can be imported in playgrounds"""
102+
self.launch(True)
103+
self.do_concurrency_test()
104+
105+
106+
def launch(self, force_target):
74107
"""Test that playgrounds work"""
75108
self.build(dictionary={
76109
'TARGET_SWIFTFLAGS':
77110
'-target {}'.format(self.get_build_triple()),
78111
})
79-
self.do_test(True)
80-
self.do_test(False)
81-
82-
def setUp(self):
83-
TestBase.setUp(self)
84-
self.PlaygroundStub_source = "PlaygroundStub.swift"
85-
self.PlaygroundStub_source_spec = lldb.SBFileSpec(
86-
self.PlaygroundStub_source)
87-
88-
def do_test(self, force_target):
89-
"""Test that playgrounds work"""
90-
exe_name = "PlaygroundStub"
91-
exe = self.getBuildArtifact(exe_name)
92112

93113
# Create the target
114+
exe = self.getBuildArtifact("PlaygroundStub")
94115
if force_target:
95116
target = self.dbg.CreateTargetWithFileAndArch(
96117
exe, self.get_run_triple())
@@ -103,7 +124,7 @@ def do_test(self, force_target):
103124

104125
# Set the breakpoints
105126
breakpoint = target.BreakpointCreateBySourceRegex(
106-
'Set breakpoint here', self.PlaygroundStub_source_spec)
127+
'Set breakpoint here', lldb.SBFileSpec("PlaygroundStub.swift"))
107128
self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)
108129

109130
process = target.LaunchSimple(None, None, os.getcwd())
@@ -116,19 +137,21 @@ def do_test(self, force_target):
116137
self.expect('settings set target.swift-framework-search-paths "%s"' %
117138
self.getBuildDir())
118139

140+
self.options = lldb.SBExpressionOptions()
141+
self.options.SetLanguage(lldb.eLanguageTypeSwift)
142+
self.options.SetPlaygroundTransformEnabled()
143+
# The concurrency expressions will spawn multiple threads.
144+
self.options.SetOneThreadTimeoutInMicroSeconds(1)
145+
self.options.SetTryAllThreads(True)
146+
147+
148+
def do_basic_test(self, force_target):
119149
contents = ""
120150

121151
with open('Contents.swift', 'r') as contents_file:
122152
contents = contents_file.read()
123153

124-
options = lldb.SBExpressionOptions()
125-
options.SetLanguage(lldb.eLanguageTypeSwift)
126-
options.SetPlaygroundTransformEnabled()
127-
# The concurrency expressions will spawn multiple threads.
128-
options.SetOneThreadTimeoutInMicroSeconds(1)
129-
options.SetTryAllThreads(True)
130-
131-
self.frame().EvaluateExpression(contents, options)
154+
self.frame().EvaluateExpression(contents, self.options)
132155
ret = self.frame().EvaluateExpression("get_output()")
133156
playground_output = ret.GetSummary()
134157
if not force_target:
@@ -144,21 +167,22 @@ def do_test(self, force_target):
144167
self.assertTrue("=\\'8\\'" in playground_output)
145168
self.assertTrue("=\\'11\\'" in playground_output)
146169

147-
# Test concurrency
170+
def do_concurrency_test(self):
148171
contents = "error"
149172
with open('Concurrency.swift', 'r') as contents_file:
150173
contents = contents_file.read()
151-
res = self.frame().EvaluateExpression(contents, options)
174+
res = self.frame().EvaluateExpression(contents, self.options)
152175
ret = self.frame().EvaluateExpression("get_output()")
153176
playground_output = ret.GetSummary()
154177
self.assertTrue(playground_output is not None)
155178
self.assertIn("=\\'23\\'", playground_output)
156179

180+
def do_import_test(self):
157181
# Test importing a library that adds new Clang options.
158182
log = self.getBuildArtifact('types.log')
159183
self.expect('log enable lldb types -f ' + log)
160184
contents = "import Dylib\nf()\n"
161-
res = self.frame().EvaluateExpression(contents, options)
185+
res = self.frame().EvaluateExpression(contents, self.options)
162186
ret = self.frame().EvaluateExpression("get_output()")
163187
playground_output = ret.GetSummary()
164188
self.assertTrue(playground_output is not None)

0 commit comments

Comments
 (0)