Skip to content

Commit a6d8425

Browse files
committed
[Test] Re-write the test for SR-13495 to use StblibUnitTest
1 parent 1f42677 commit a6d8425

File tree

2 files changed

+40
-49
lines changed

2 files changed

+40
-49
lines changed

test/SILOptimizer/di_property_wrappers.swift

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -535,54 +535,6 @@ func testSR_12341() {
535535
_ = SR_12341(condition: true)
536536
}
537537

538-
class TestLeak: CustomStringConvertible {
539-
let val: Int
540-
init(val: Int) { self.val = val }
541-
deinit { print(" .. \(self).deinit") }
542-
var description: String { "TestLeak(\(val))" }
543-
}
544-
545-
struct SR_13495 {
546-
@Wrapper var wrapped: TestLeak
547-
var str: String
548-
549-
init() {
550-
wrapped = TestLeak(val: 42)
551-
str = ""
552-
wrapped = TestLeak(val: 27)
553-
}
554-
555-
init(conditionalInit: Bool) {
556-
if (conditionalInit) {
557-
wrapped = TestLeak(val: 42)
558-
}
559-
str = ""
560-
wrapped = TestLeak(val: 27)
561-
}
562-
}
563-
564-
func testSR_13495() {
565-
// CHECK: ## SR_13495
566-
print("\n## SR_13495")
567-
568-
// CHECK-NEXT: .. init TestLeak(42)
569-
// CHECK-NEXT: .. TestLeak(42).deinit
570-
// CHECK-NEXT: .. set TestLeak(27)
571-
// CHECK-NEXT: .. TestLeak(27).deinit
572-
_ = SR_13495()
573-
574-
// CHECK-NEXT: .. init TestLeak(42)
575-
// CHECK-NEXT: .. TestLeak(42).deinit
576-
// CHECK-NEXT: .. init TestLeak(27)
577-
// CHECK-NEXT: .. TestLeak(27).deinit
578-
_ = SR_13495(conditionalInit: true)
579-
580-
// CHECK-NEXT: .. init TestLeak(27)
581-
// CHECK-NEXT: .. TestLeak(27).deinit
582-
_ = SR_13495(conditionalInit: false)
583-
}
584-
585-
586538
@propertyWrapper
587539
struct NonMutatingSetterWrapper<Value> {
588540
var value: Value
@@ -621,5 +573,4 @@ testDefaultNilOptIntStruct()
621573
testComposed()
622574
testWrapperInitWithDefaultArg()
623575
testSR_12341()
624-
testSR_13495()
625576
testNonMutatingSetterStruct()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -o %t/a.out
3+
// RUN: %target-codesign %t/a.out
4+
// RUN: %target-run %t/a.out
5+
6+
// REQUIRES: executable_test
7+
8+
import StdlibUnittest
9+
10+
@propertyWrapper
11+
struct Wrapper<T> {
12+
var wrappedValue: T
13+
}
14+
15+
struct TestWrappedValueLeak {
16+
@Wrapper var wrapped: LifetimeTracked = LifetimeTracked(0)
17+
var str: String
18+
19+
init() {
20+
wrapped = LifetimeTracked(42)
21+
str = ""
22+
wrapped = LifetimeTracked(27)
23+
}
24+
25+
init(conditionalInit: Bool) {
26+
if (conditionalInit) {
27+
wrapped = LifetimeTracked(42)
28+
}
29+
str = ""
30+
wrapped = LifetimeTracked(27)
31+
}
32+
}
33+
34+
TestSuite("Property Wrapper DI").test("test wrapped value leak") {
35+
_ = TestWrappedValueLeak()
36+
_ = TestWrappedValueLeak(conditionalInit: true)
37+
_ = TestWrappedValueLeak(conditionalInit: false)
38+
}
39+
40+
runAllTests()

0 commit comments

Comments
 (0)