mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Testcase for the playground transform.
This is the first testcase and includes the test harness which will work for other testcases as well. Also includes a fix to make sure that we only instrument once per main source file, and not once per parse as we were doing before. Swift SVN r20456
This commit is contained in:
@@ -412,16 +412,15 @@ void CompilerInstance::performSema() {
|
||||
parseIntoSourceFile(MainFile, MainFile.getBufferID().getValue(), &Done,
|
||||
TheSILModule ? &SILContext : nullptr,
|
||||
&PersistentState, DelayedCB.get());
|
||||
if (PrimaryBufferID == NO_SUCH_BUFFER ||
|
||||
MainBufferID == PrimaryBufferID) {
|
||||
if (PrimaryBufferID == NO_SUCH_BUFFER || MainBufferID == PrimaryBufferID)
|
||||
performTypeChecking(MainFile, PersistentState.getTopLevelContext(),
|
||||
CurTUElem);
|
||||
if (Invocation.getFrontendOptions().Playground)
|
||||
performPlaygroundTransform(MainFile);
|
||||
}
|
||||
CurTUElem = MainFile.Decls.size();
|
||||
} while (!Done);
|
||||
|
||||
|
||||
if (Invocation.getFrontendOptions().Playground &&
|
||||
(PrimaryBufferID == NO_SUCH_BUFFER || MainBufferID == PrimaryBufferID))
|
||||
performPlaygroundTransform(MainFile);
|
||||
}
|
||||
|
||||
// Type-check each top-level input besides the main source file.
|
||||
|
||||
42
test/PlaygroundTransform/Inputs/PlaygroundsRuntime.swift
Normal file
42
test/PlaygroundTransform/Inputs/PlaygroundsRuntime.swift
Normal file
@@ -0,0 +1,42 @@
|
||||
class LogRecord {
|
||||
let text : String
|
||||
init(api : String, object : Any, name : String) {
|
||||
var object_description : String = ""
|
||||
print(object, &object_description)
|
||||
text = api + "[" + name + "='" + object_description + "']"
|
||||
}
|
||||
init(api : String, object: Any) {
|
||||
var object_description : String = ""
|
||||
print(object, &object_description)
|
||||
text = api + "['" + object_description + "']"
|
||||
}
|
||||
init(api: String) {
|
||||
text = api
|
||||
}
|
||||
}
|
||||
|
||||
func $builtin_log<T>(object : T, name : String) -> AnyObject? {
|
||||
return LogRecord(api:"$builtin_log", object:object, name:name)
|
||||
}
|
||||
|
||||
func $builtin_log_scope_entry() -> AnyObject? {
|
||||
return LogRecord(api:"$builtin_log_scope_entry")
|
||||
}
|
||||
|
||||
func $builtin_log_scope_exit() -> AnyObject? {
|
||||
return LogRecord(api:"$builtin_log_scope_exit")
|
||||
}
|
||||
|
||||
func $builtin_print<T>(object: T) -> AnyObject? {
|
||||
return LogRecord(api:"$builtin_print", object:object)
|
||||
}
|
||||
|
||||
func $builtin_println<T>(object: T) -> AnyObject? {
|
||||
return LogRecord(api:"$builtin_println", object:object)
|
||||
}
|
||||
|
||||
func $builtin_send_data(object:AnyObject?, sl: Int, el: Int, sc: Int, ec: Int) {
|
||||
let loc : String = "[" + String(sl) + ":" + String(sc)
|
||||
+ "-" + String(el) + ":" + String(ec) + "]"
|
||||
println(loc + " " + (object as LogRecord).text)
|
||||
}
|
||||
18
test/PlaygroundTransform/declarations.swift
Normal file
18
test/PlaygroundTransform/declarations.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
// RUN: rm -rf %t
|
||||
// RUN: mkdir %t
|
||||
// RUN: cp %s %t/main.swift
|
||||
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
|
||||
// RUN: %target-run %t/main | FileCheck %s
|
||||
var a = 2
|
||||
var b = 3
|
||||
a + b
|
||||
// CHECK: [{{.*}}] $builtin_log_scope_entry
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log[a='2']
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log_scope_exit
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log_scope_entry
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log[b='3']
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log_scope_exit
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log_scope_entry
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log[='5']
|
||||
// CHECK-NEXT: [{{.*}}] $builtin_log_scope_exit
|
||||
|
||||
Reference in New Issue
Block a user