Files
swift-mirror/test/stmt/then_stmt_exec.swift
Daniel Rodríguez Troitiño ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00

77 lines
1.5 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swiftc_driver -Xfrontend -enable-experimental-feature -Xfrontend ThenStatements -o %t/a.out %s
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: swift_feature_ThenStatements
func testDeferIf(_ x: Bool) -> Int {
defer {
print("defer testDeferIf")
}
let x = if x {
defer {
print("defer if")
}
print("enter if")
then 0
} else {
1
}
print("after if")
return x
}
_ = testDeferIf(true)
// CHECK: enter if
// CHECK-NEXT: defer if
// CHECK-NEXT: after if
// CHECK-NEXT: defer testDeferIf
func testDeferSwitch(_ x: Bool) -> Int {
defer {
print("defer testDeferSwitch")
}
let x = switch x {
case true:
defer {
print("defer case true")
}
print("enter case true")
fallthrough
case false:
defer {
print("defer case false")
}
print("enter case false")
then 1
}
print("after switch")
return x
}
_ = testDeferSwitch(true)
// CHECK: enter case true
// CHECK-NEXT: defer case true
// CHECK-NEXT: enter case false
// CHECK-NEXT: defer case false
// CHECK-NEXT: after switch
// CHECK-NEXT: defer testDeferSwitch
func testFallthrough(_ x: Bool) -> Int {
var z = 0
let y: Int
let x = switch x {
case true:
z = 1
fallthrough
case false:
y = 2
then 3
}
return x + y + z
}
print("fallthrough: \(testFallthrough(true))")
// CHECK: fallthrough: 6