Skip to content

Commit 5ac442f

Browse files
committed
Further streamline TestSwiftPlaygrounds.
1 parent 03c984b commit 5ac442f

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Dylib
2+
f()

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

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def test_no_force_target(self):
8888
@swiftTest
8989
@skipIf(setting=('symbols.use-swift-clangimporter', 'false'))
9090
@skipIf(debug_info=decorators.no_match("dsym"))
91+
@skipIf(macos_version=["<", "12"])
9192
def test_concurrency(self):
9293
"""Test that concurrency is available in playgrounds"""
9394
self.launch(True)
@@ -144,47 +145,56 @@ def launch(self, force_target):
144145
self.options.SetTryAllThreads(True)
145146

146147

147-
def do_basic_test(self, force_target):
148-
contents = ""
149-
150-
with open('Contents.swift', 'r') as contents_file:
148+
def execute_code(self, input_file, expect_error=False):
149+
contents = "syntax error"
150+
with open(input_file, 'r') as contents_file:
151151
contents = contents_file.read()
152-
153-
self.frame().EvaluateExpression(contents, self.options)
152+
res = self.frame().EvaluateExpression(contents, self.options)
154153
ret = self.frame().EvaluateExpression("get_output()")
154+
is_error = res.GetError().Fail() and not (
155+
res.GetError().GetType() == 1 and
156+
res.GetError().GetError() == 0x1001)
155157
playground_output = ret.GetSummary()
158+
with recording(self, self.TraceOn()) as sbuf:
159+
print("playground result: ", file=sbuf)
160+
print(str(res), file=sbuf)
161+
if is_error:
162+
print("error:", file=sbuf)
163+
print(str(res.GetError()), file=sbuf)
164+
else:
165+
print("playground output:", file=sbuf)
166+
print(str(ret), file=sbuf)
167+
168+
if expect_error:
169+
self.assertTrue(is_error)
170+
return playground_output
171+
self.assertFalse(is_error)
172+
self.assertIsNotNone(playground_output)
173+
return playground_output
174+
175+
def do_basic_test(self, force_target):
176+
playground_output = self.execute_code('Contents.swift', not force_target)
156177
if not force_target:
157178
# This is expected to fail because the deployment target
158179
# is less than the availability of the function being
159180
# called.
160181
self.assertEqual(playground_output, '""')
161182
return
162183

163-
self.assertTrue(playground_output is not None)
164-
self.assertTrue("a=\\'3\\'" in playground_output)
165-
self.assertTrue("b=\\'5\\'" in playground_output)
166-
self.assertTrue("=\\'8\\'" in playground_output)
167-
self.assertTrue("=\\'11\\'" in playground_output)
184+
self.assertIn("a=\\'3\\'", playground_output)
185+
self.assertIn("b=\\'5\\'", playground_output)
186+
self.assertIn("=\\'8\\'", playground_output)
187+
self.assertIn("=\\'11\\'", playground_output)
168188

169189
def do_concurrency_test(self):
170-
contents = "error"
171-
with open('Concurrency.swift', 'r') as contents_file:
172-
contents = contents_file.read()
173-
res = self.frame().EvaluateExpression(contents, self.options)
174-
ret = self.frame().EvaluateExpression("get_output()")
175-
playground_output = ret.GetSummary()
176-
self.assertTrue(playground_output is not None)
190+
playground_output = self.execute_code('Concurrency.swift')
177191
self.assertIn("=\\'23\\'", playground_output)
178192

179193
def do_import_test(self):
180194
# Test importing a library that adds new Clang options.
181195
log = self.getBuildArtifact('types.log')
182196
self.expect('log enable lldb types -f ' + log)
183-
contents = "import Dylib\nf()\n"
184-
res = self.frame().EvaluateExpression(contents, self.options)
185-
ret = self.frame().EvaluateExpression("get_output()")
186-
playground_output = ret.GetSummary()
187-
self.assertTrue(playground_output is not None)
197+
playground_output = self.execute_code('Import.swift')
188198
self.assertIn("Hello from the Dylib", playground_output)
189199

190200
# Scan through the types log to make sure the SwiftASTContext was poisoned.

0 commit comments

Comments
 (0)