Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.5"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.4.0"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.5.0"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "2.0.0"),
Copy link
Contributor

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.

Copy link
Member Author

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

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.

.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
],
Expand Down
32 changes: 16 additions & 16 deletions Samples/Tuist/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions WorkflowSwiftUI/Tests/CompletionTracker.swift
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
}
}
44 changes: 36 additions & 8 deletions WorkflowSwiftUI/Tests/Derived/ObservableStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class ObservableStateTests: XCTestCase {
}

func testChildCountMutation() async {
let tracker = CompletionTracker()
var state = ParentState()
let childCountDidChange = expectation(description: "child.count.didChange")

Expand All @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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

image

}

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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -225,6 +241,7 @@ final class ObservableStateTests: XCTestCase {
}

func testIdentifiedArray_MutateElement() {
let tracker = CompletionTracker()
var state = ParentState(rows: [
ChildState(),
ChildState(),
Expand All @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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()
}
}

Expand Down
6 changes: 5 additions & 1 deletion WorkflowSwiftUI/Tests/NestedStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ final class NestedStoreTests: XCTestCase {

// nil to nil
do {
let tracker = CompletionTracker()
var state = State(optional: nil)
func makeModel() -> StateAccessor<State> {
StateAccessor(state: state) { update in
Expand All @@ -131,11 +132,14 @@ final class NestedStoreTests: XCTestCase {
withPerceptionTracking {
_ = store.scope(keyPath: \.optional)?.name
} onChange: {
XCTFail("optional should not change")
if tracker.isComplete == false {
XCTFail("optional should not change")
}
}

state.optional = nil
setModel(makeModel())
tracker.complete()
}
}

Expand Down
Loading
Loading