Skip to content

Commit a7daf25

Browse files
committed
Added PlaygroundTransform tests on implicit return.
1 parent e5947e4 commit a7daf25

7 files changed

+154
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
// RUN: %target-build-swift -Xfrontend -pc-macro -Xfrontend -playground -Xfrontend -debugger-support -o %t/main2 %S/Inputs/PlaygroundsRuntime.swift %S/Inputs/SilentPCMacroRuntime.swift %t/main.swift
7+
// RUN: %target-codesign %t/main2
8+
// RUN: %target-run %t/main2 | %FileCheck %s
9+
// REQUIRES: executable_test
10+
func add<I : SignedNumeric>(_ lhs: I, _ rhs: I) -> I {
11+
lhs + rhs
12+
}
13+
add(3, 4)
14+
// CHECK: {{.*}} __builtin_log_scope_entry
15+
// CHECK-NEXT: {{.*}} __builtin_log[='7']
16+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
17+
// CHECK-NEXT: {{.*}} __builtin_log[='7']
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
// RUN: %target-build-swift -Xfrontend -pc-macro -Xfrontend -playground -Xfrontend -debugger-support -o %t/main2 %S/Inputs/PlaygroundsRuntime.swift %S/Inputs/SilentPCMacroRuntime.swift %t/main.swift
7+
// RUN: %target-codesign %t/main2
8+
// RUN: %target-run %t/main2 | %FileCheck %s
9+
// REQUIRES: executable_test
10+
func iss<T>(_ instance: Any, anInstanceOf type: T.Type) -> Bool {
11+
instance is T
12+
}
13+
iss("hello", anInstanceOf: String.self)
14+
iss(57, anInstanceOf: String.self)
15+
// CHECK: {{.*}} __builtin_log_scope_entry
16+
// CHECK-NEXT: {{.*}} __builtin_log[='true']
17+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
18+
// CHECK-NEXT: {{.*}} __builtin_log[='true']
19+
// CHECK: {{.*}} __builtin_log_scope_entry
20+
// CHECK-NEXT: {{.*}} __builtin_log[='false']
21+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
22+
// CHECK-NEXT: {{.*}} __builtin_log[='false']
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
// RUN: %target-build-swift -Xfrontend -pc-macro -Xfrontend -playground -Xfrontend -debugger-support -o %t/main2 %S/Inputs/PlaygroundsRuntime.swift %S/Inputs/SilentPCMacroRuntime.swift %t/main.swift
7+
// RUN: %target-codesign %t/main2
8+
// RUN: %target-run %t/main2 | %FileCheck %s
9+
// REQUIRES: executable_test
10+
func foo() -> String {
11+
"howdy"
12+
}
13+
foo()
14+
// CHECK: {{.*}} __builtin_log_scope_entry
15+
// CHECK-NEXT: {{.*}} __builtin_log[='howdy']
16+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
17+
// CHECK-NEXT: {{.*}} __builtin_log[='howdy']
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
// RUN: %target-build-swift -Xfrontend -pc-macro -Xfrontend -playground -Xfrontend -debugger-support -o %t/main2 %S/Inputs/PlaygroundsRuntime.swift %S/Inputs/SilentPCMacroRuntime.swift %t/main.swift
7+
// RUN: %target-codesign %t/main2
8+
// RUN: %target-run %t/main2 | %FileCheck %s
9+
// REQUIRES: executable_test
10+
struct S {
11+
init?() {
12+
nil
13+
}
14+
}
15+
var s = S()
16+
// CHECK: {{.*}} __builtin_log_scope_entry
17+
// FIXME: It seems like there should be a __builtin_log_scope_exit here but there isn't, whether
18+
// or not the return is explicit.
19+
// CHECK-NEXT: {{.*}} __builtin_log[s='nil']
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -disable-playground-transform -o %t/main %t/main.swift
4+
// RUN: %target-codesign %t/main
5+
// RUN: ! %target-run %t/main --crash 2>&1 | %FileCheck -check-prefix=CRASH-CHECK %s
6+
// REQUIRES: executable_test
7+
8+
// NOTE: "!" is used above instead of "not --crash" because simctl's exit
9+
// status doesn't reflect whether its child process crashed or not. So "not
10+
// --crash %target-run ..." always fails when testing for the iOS Simulator.
11+
// The more precise solution would be to use a version of 'not' cross-compiled
12+
// for the simulator.
13+
14+
func f() -> Int {
15+
fatalError()
16+
}
17+
18+
f()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
// RUN: %target-build-swift -Xfrontend -pc-macro -Xfrontend -playground -Xfrontend -debugger-support -o %t/main2 %S/Inputs/PlaygroundsRuntime.swift %S/Inputs/SilentPCMacroRuntime.swift %t/main.swift
7+
// RUN: %target-codesign %t/main2
8+
// RUN: %target-run %t/main2 | %FileCheck %s
9+
// REQUIRES: executable_test
10+
struct S {
11+
var dict: [Int : Int?]
12+
subscript(_ int: Int) -> Int? {
13+
get {
14+
dict[int, default: Int(String(int))]
15+
}
16+
set {
17+
dict[int] = newValue
18+
}
19+
}
20+
init() {
21+
dict = [:]
22+
}
23+
}
24+
var s = S()
25+
s[13] = 33
26+
s[14]
27+
s[13]
28+
// CHECK: {{.*}} __builtin_log_scope_entry
29+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
30+
31+
// CHECK: {{.*}} __builtin_log_scope_entry
32+
// CHECK-NEXT: {{.*}} __builtin_log[='Optional(Optional(33))']
33+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
34+
35+
// CHECK: {{.*}} __builtin_log_scope_entry
36+
// CHECK-NEXT: {{.*}} __builtin_log[='Optional(14)']
37+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
38+
// CHECK-NEXT: {{.*}} __builtin_log[='Optional(14)']
39+
40+
// CHECK: {{.*}} __builtin_log_scope_entry
41+
// CHECK-NEXT: {{.*}} __builtin_log[='Optional(33)']
42+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
43+
// CHECK-NEXT: {{.*}} __builtin_log[='Optional(33)']
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main | %FileCheck %s
6+
// RUN: %target-build-swift -Xfrontend -pc-macro -Xfrontend -playground -Xfrontend -debugger-support -o %t/main2 %S/Inputs/PlaygroundsRuntime.swift %S/Inputs/SilentPCMacroRuntime.swift %t/main.swift
7+
// RUN: %target-codesign %t/main2
8+
// RUN: %target-run %t/main2 | %FileCheck %s
9+
// REQUIRES: executable_test
10+
var foo: Int {
11+
2019
12+
}
13+
foo
14+
// CHECK: {{.*}} __builtin_log_scope_entry
15+
// CHECK-NEXT: {{.*}} __builtin_log[='2019']
16+
// CHECK-NEXT: {{.*}} __builtin_log_scope_exit
17+
// CHECK-NEXT: {{.*}} __builtin_log[='2019']

0 commit comments

Comments
 (0)