Skip to content

Commit

Permalink
assertStateModifications: swift-custom-dump
Browse files Browse the repository at this point in the history
- Before: assertStateModifications was difficult to use because the diffs for failed assertions were difficult to read
- After: Incorporate CustomDump into assertStateModifications to make the assertions easy to read
  • Loading branch information
gilgtm committed Dec 2, 2024
1 parent 2ce9f82 commit cf28ea2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
"version" : "1.1.4"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1",
"version" : "1.3.3"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
Expand Down
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ let package = Package(
.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.1.4"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"),
],
targets: [
// MARK: Workflow
Expand All @@ -80,7 +81,10 @@ let package = Package(
),
.target(
name: "WorkflowTesting",
dependencies: ["Workflow"],
dependencies: [
"Workflow",
.product(name: "CustomDump", package: "swift-custom-dump"),
],
path: "WorkflowTesting/Sources",
linkerSettings: [.linkedFramework("XCTest")]
),
Expand Down
17 changes: 14 additions & 3 deletions WorkflowTesting/Sources/RenderTesterResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import CustomDump
import Workflow
import XCTest

Expand Down Expand Up @@ -129,13 +130,23 @@ extension RenderTesterResult where WorkflowType.State: Equatable {
/// and is expected to mutate it to match the new state.
@discardableResult
public func assertStateModifications(
file: StaticString = #file,
_ modifications: (inout WorkflowType.State) throws -> Void,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
_ modifications: (inout WorkflowType.State) throws -> Void
column: UInt = #column
) rethrows -> RenderTesterResult<WorkflowType> {
var initialState = initialState
try modifications(&initialState)
XCTAssertEqual(state, initialState, "Expected state does not match", file: file, line: line)
expectNoDifference(
initialState,
state,
"Expected state does not match",
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
return self
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
}
}

func test_assertState() {
func test_assertStateModifications() {
let result = TestWorkflow()
.renderTester(initialState: .idle)
.render { _ in }
Expand Down

0 comments on commit cf28ea2

Please sign in to comment.