mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
110 lines
2.0 KiB
Swift
110 lines
2.0 KiB
Swift
// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all -enable-experimental-feature ReferenceBindings)
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: swift_feature_ReferenceBindings
|
|
|
|
import StdlibUnittest
|
|
|
|
defer { runAllTests() }
|
|
|
|
var tests = TestSuite("reference bindings")
|
|
|
|
var global: String = "globalName"
|
|
tests.test("global access") {
|
|
expectEqual(global, "globalName")
|
|
do {
|
|
inout x = global
|
|
expectEqual(x, "globalName")
|
|
}
|
|
expectEqual(global, "globalName")
|
|
}
|
|
|
|
tests.test("multiple global access exclusivity error")
|
|
.crashOutputMatches("Simultaneous accesses to")
|
|
.code {
|
|
expectCrashLater()
|
|
|
|
@inline(never)
|
|
func test(_ x: inout String) {
|
|
inout x = global
|
|
}
|
|
test(&global)
|
|
}
|
|
|
|
tests.test("Class Instance Field Access") {
|
|
class Klass {
|
|
var name: String = "klassName"
|
|
}
|
|
|
|
let k = Klass()
|
|
expectEqual(k.name, "klassName")
|
|
do {
|
|
inout x = k.name
|
|
expectEqual(x, "klassName")
|
|
}
|
|
expectEqual(k.name, "klassName")
|
|
}
|
|
|
|
tests.test("Var Access") {
|
|
var varName = "varName"
|
|
do {
|
|
inout x = varName
|
|
expectEqual(x, "varName")
|
|
}
|
|
expectEqual(varName, "varName")
|
|
|
|
struct S {
|
|
var s1 = "field1"
|
|
var s2 = "field2"
|
|
}
|
|
|
|
var s = S()
|
|
expectEqual(s.s1, "field1")
|
|
expectEqual(s.s2, "field2")
|
|
do {
|
|
inout x = s.s1
|
|
expectEqual(x, "field1")
|
|
}
|
|
expectEqual(s.s1, "field1")
|
|
expectEqual(s.s2, "field2")
|
|
do {
|
|
inout x2 = s.s2
|
|
expectEqual(x2, "field2")
|
|
}
|
|
expectEqual(s.s1, "field1")
|
|
expectEqual(s.s2, "field2")
|
|
}
|
|
|
|
|
|
tests.test("InOut Access") {
|
|
var varName = "varName"
|
|
func inoutTest(_ inputX: inout String) {
|
|
expectEqual(inputX, "varName")
|
|
inout x = inputX
|
|
expectEqual(x, "varName")
|
|
}
|
|
inoutTest(&varName)
|
|
expectEqual(varName, "varName")
|
|
}
|
|
|
|
// We use to hit a verifier error here.
|
|
tests.test("Class Use") {
|
|
class Klass {
|
|
var value: String = "varName"
|
|
}
|
|
|
|
struct S {
|
|
var k = Klass()
|
|
var i = 5
|
|
mutating func x() {
|
|
print("\(i)")
|
|
}
|
|
}
|
|
|
|
var s = S()
|
|
do {
|
|
inout x = s.k
|
|
expectEqual(x.value, "varName")
|
|
}
|
|
}
|