-
Notifications
You must be signed in to change notification settings - Fork 47
chore: Bump Perception to 2.0 #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dfab0b6
a954911
1bdb147
19e8b7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// Tracks a completion flag during a test or during a portion of a larger test. | ||
/// | ||
/// This can be useful during tests in which object deinitialization can have side-effects that you may | ||
/// want to filter out when making assertions. | ||
class CompletionTracker { | ||
private(set) var isComplete: Bool = false | ||
|
||
func complete() { | ||
isComplete = true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ final class ObservableStateTests: XCTestCase { | |
} | ||
|
||
func testChildCountMutation() async { | ||
let tracker = CompletionTracker() | ||
var state = ParentState() | ||
let childCountDidChange = expectation(description: "child.count.didChange") | ||
|
||
|
@@ -35,23 +36,29 @@ final class ObservableStateTests: XCTestCase { | |
withPerceptionTracking { | ||
_ = state.child | ||
} onChange: { | ||
XCTFail("state.child should not change.") | ||
if tracker.isComplete == false { | ||
XCTFail("state.child should not change.") | ||
} | ||
Comment on lines
+39
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same kind of approach used in Perception now: https://github.com/pointfreeco/swift-perception/blob/main/Tests/PerceptionTests/PerceptionTrackingTests.swift#L32 The issue is that the registrar deinit pathway will now trigger an onChange which we don't really want to "count" in this context. Related to pointfreeco/swift-perception#153 ![]() |
||
} | ||
|
||
state.child.count += 1 | ||
await fulfillment(of: [childCountDidChange], timeout: 0) | ||
XCTAssertEqual(state.child.count, 1) | ||
tracker.complete() | ||
} | ||
|
||
func testChildReset() async { | ||
let tracker = CompletionTracker() | ||
var state = ParentState() | ||
let childDidChange = expectation(description: "child.didChange") | ||
|
||
let child = state.child | ||
withPerceptionTracking { | ||
_ = child.count | ||
} onChange: { | ||
XCTFail("child.count should not change.") | ||
if tracker.isComplete == false { | ||
XCTFail("child.count should not change.") | ||
} | ||
} | ||
withPerceptionTracking { | ||
_ = state.child | ||
|
@@ -62,6 +69,7 @@ final class ObservableStateTests: XCTestCase { | |
state.child = ChildState(count: 42) | ||
await fulfillment(of: [childDidChange], timeout: 0) | ||
XCTAssertEqual(state.child.count, 42) | ||
tracker.complete() | ||
} | ||
|
||
func testReplaceChild() async { | ||
|
@@ -139,16 +147,20 @@ final class ObservableStateTests: XCTestCase { | |
|
||
// nil -> nil | ||
do { | ||
let tracker = CompletionTracker() | ||
var state = ParentState(optional: nil) | ||
|
||
withPerceptionTracking { | ||
_ = state.optional | ||
} onChange: { | ||
XCTFail("Optional should not change") | ||
if tracker.isComplete == false { | ||
XCTFail("Optional should not change") | ||
} | ||
} | ||
|
||
state.optional = nil | ||
XCTAssertNil(state.optional) | ||
tracker.complete() | ||
} | ||
|
||
// value -> nil | ||
|
@@ -169,13 +181,16 @@ final class ObservableStateTests: XCTestCase { | |
} | ||
|
||
func testMutateOptional() async { | ||
let tracker = CompletionTracker() | ||
var state = ParentState(optional: ChildState()) | ||
let optionalCountDidChange = expectation(description: "optional.count.didChange") | ||
|
||
withPerceptionTracking { | ||
_ = state.optional | ||
} onChange: { | ||
XCTFail("Optional should not change") | ||
if tracker.isComplete == false { | ||
XCTFail("Optional should not change") | ||
} | ||
} | ||
let optional = state.optional | ||
withPerceptionTracking { | ||
|
@@ -187,6 +202,7 @@ final class ObservableStateTests: XCTestCase { | |
state.optional?.count += 1 | ||
await fulfillment(of: [optionalCountDidChange], timeout: 0) | ||
XCTAssertEqual(state.optional?.count, 1) | ||
tracker.complete() | ||
} | ||
|
||
func testReplaceWithCopy() async { | ||
|
@@ -225,6 +241,7 @@ final class ObservableStateTests: XCTestCase { | |
} | ||
|
||
func testIdentifiedArray_MutateElement() { | ||
let tracker = CompletionTracker() | ||
var state = ParentState(rows: [ | ||
ChildState(), | ||
ChildState(), | ||
|
@@ -234,12 +251,16 @@ final class ObservableStateTests: XCTestCase { | |
withPerceptionTracking { | ||
_ = state.rows | ||
} onChange: { | ||
XCTFail("rows should not change") | ||
if tracker.isComplete == false { | ||
XCTFail("rows should not change") | ||
} | ||
} | ||
withPerceptionTracking { | ||
_ = state.rows[0] | ||
} onChange: { | ||
XCTFail("rows[0] should not change") | ||
if tracker.isComplete == false { | ||
XCTFail("rows[0] should not change") | ||
} | ||
} | ||
withPerceptionTracking { | ||
_ = state.rows[0].count | ||
|
@@ -249,12 +270,15 @@ final class ObservableStateTests: XCTestCase { | |
withPerceptionTracking { | ||
_ = state.rows[1].count | ||
} onChange: { | ||
XCTFail("rows[1].count should not change") | ||
if tracker.isComplete == false { | ||
XCTFail("rows[1].count should not change") | ||
} | ||
} | ||
|
||
state.rows[0].count += 1 | ||
XCTAssertEqual(state.rows[0].count, 1) | ||
wait(for: [firstRowCountDidChange], timeout: 0) | ||
tracker.complete() | ||
} | ||
|
||
func testCopy() { | ||
|
@@ -289,15 +313,19 @@ final class ObservableStateTests: XCTestCase { | |
} | ||
|
||
func testArrayMutate() { | ||
let tracker = CompletionTracker() | ||
var state = ParentState(children: [ChildState()]) | ||
|
||
withPerceptionTracking { | ||
_ = state.children | ||
} onChange: { | ||
XCTFail("children should not change") | ||
if tracker.isComplete == false { | ||
XCTFail("children should not change") | ||
} | ||
} | ||
|
||
state.children[0].count += 1 | ||
tracker.complete() | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(commenting here for threading support) – just an FYI, but i believe the 'memory leak fix' was reverted from the 6.2 release branch (see here). idk exactly how that corresponds to what's in any given Xcode beta. sadly no justification was given in any of the PRs so not sure what the underlying motivation was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting. It looks like the pointfree folks haven't removed it from their backport at this point...
Pinged them about it here: pointfreeco/swift-perception#153
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll look into getting those changes into Perception soon. I pinged their PR for more context, so hopefully they can provide some.