Skip to content

Commit

Permalink
Use swift-custom-dump for all comparisons in RenderTesterResult
Browse files Browse the repository at this point in the history
This expands the usage of swift-custom-dump to improve test failure readability
  • Loading branch information
gilgtm committed Dec 10, 2024
1 parent c9b5a6f commit 9b7f71c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 9 deletions.
28 changes: 23 additions & 5 deletions WorkflowTesting/Sources/RenderTesterResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public struct RenderTesterResult<WorkflowType: Workflow> {
line: UInt = #line
) -> RenderTesterResult<WorkflowType> where ActionType.WorkflowType == WorkflowType, ActionType: Equatable {
verifyAction(file: file, line: line) { appliedAction in
XCTAssertEqual(appliedAction, action, file: file, line: line)
XCTAssertNoDifference(

Check warning on line 83 in WorkflowTesting/Sources/RenderTesterResult.swift

View workflow job for this annotation

GitHub Actions / tutorial

'XCTAssertNoDifference(_:_:_:file:line:)' is deprecated: renamed to 'expectNoDifference'
appliedAction,
action,
"Action (First) does not match the expected action (Second)",
file: file,
line: line
)
}
}

Expand Down Expand Up @@ -120,7 +126,13 @@ extension RenderTesterResult where WorkflowType.State: Equatable {
file: StaticString = #file,
line: UInt = #line
) -> RenderTesterResult<WorkflowType> {
XCTAssertEqual(state, expectedState, file: file, line: line)
XCTAssertNoDifference(

Check warning on line 129 in WorkflowTesting/Sources/RenderTesterResult.swift

View workflow job for this annotation

GitHub Actions / development-tests (UnitTests)

'XCTAssertNoDifference(_:_:_:file:line:)' is deprecated: renamed to 'expectNoDifference'

Check warning on line 129 in WorkflowTesting/Sources/RenderTesterResult.swift

View workflow job for this annotation

GitHub Actions / tutorial

'XCTAssertNoDifference(_:_:_:file:line:)' is deprecated: renamed to 'expectNoDifference'
state,
expectedState,
"State (First) does not match the expected state (Second)",
file: file,
line: line
)
return self
}

Expand All @@ -137,9 +149,9 @@ extension RenderTesterResult where WorkflowType.State: Equatable {
var initialState = initialState
try modifications(&initialState)
XCTAssertNoDifference(

Check warning on line 151 in WorkflowTesting/Sources/RenderTesterResult.swift

View workflow job for this annotation

GitHub Actions / development-tests (UnitTests)

'XCTAssertNoDifference(_:_:_:file:line:)' is deprecated: renamed to 'expectNoDifference'

Check warning on line 151 in WorkflowTesting/Sources/RenderTesterResult.swift

View workflow job for this annotation

GitHub Actions / tutorial

'XCTAssertNoDifference(_:_:_:file:line:)' is deprecated: renamed to 'expectNoDifference'
initialState,
state,
"Expected state does not match",
initialState,
"State (First) does not match the expected state (Second)",
file: file,
line: line
)
Expand All @@ -156,7 +168,13 @@ extension RenderTesterResult where WorkflowType.Output: Equatable {
line: UInt = #line
) -> RenderTesterResult<WorkflowType> {
verifyOutput(file: file, line: line) { output in
XCTAssertEqual(output, expectedOutput, file: file, line: line)
XCTAssertNoDifference(

Check warning on line 171 in WorkflowTesting/Sources/RenderTesterResult.swift

View workflow job for this annotation

GitHub Actions / development-tests (UnitTests)

'XCTAssertNoDifference(_:_:_:file:line:)' is deprecated: renamed to 'expectNoDifference'

Check warning on line 171 in WorkflowTesting/Sources/RenderTesterResult.swift

View workflow job for this annotation

GitHub Actions / tutorial

'XCTAssertNoDifference(_:_:_:file:line:)' is deprecated: renamed to 'expectNoDifference'
output,
expectedOutput,
"Output (First) does not match the expected output (Second)",
file: file,
line: line
)
}
}
}
53 changes: 49 additions & 4 deletions WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
rendering.doNoopAction(10)
}

expectingFailure(#"("noop(10)") is not equal to ("noop(70)")"#) {
expectingFailure("""
failed - XCTAssertNoDifference failed: …
− TestAction.noop(10)
+ TestAction.noop(70)
(First: −, Second: +) - Action (First) does not match the expected action (Second)
""") {
result.assert(action: TestAction.noop(70))
}

Expand Down Expand Up @@ -272,7 +279,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
}
}

expectingFailure(#"("sendOutput("second")") is not equal to ("noop(0)")"#) {
expectingFailure("""
failed - XCTAssertNoDifference failed: …
− TestAction.sendOutput("second")
+ TestAction.noop(0)
(First: −, Second: +) - Action (First) does not match the expected action (Second)
""") {
result.assert(action: TestAction.noop(0))
}

Expand All @@ -296,7 +310,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
rendering.doOutput("hello")
}

expectingFailure(#"("string("hello")") is not equal to ("string("nope")")"#) {
expectingFailure("""
failed - XCTAssertNoDifference failed: …
− TestWorkflow.Output.string("hello")
+ TestWorkflow.Output.string("nope")
(First: −, Second: +) - Output (First) does not match the expected output (Second)
""") {
result.assert(output: .string("nope"))
}

Expand Down Expand Up @@ -341,12 +362,36 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
}
}

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

expectingFailure("""
failed - XCTAssertNoDifference failed: …
− TestWorkflow.State.idle
+ TestWorkflow.State.sideEffect(key: "nah")
(First: −, Second: +) - State (First) does not match the expected state (Second)
""") {
result.assert(state: TestWorkflow.State.sideEffect(key: "nah"))
}
}

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

expectingFailure("Expected state does not match") {
expectingFailure("""
XCTAssertNoDifference failed: …
− TestWorkflow.State.idle
+ TestWorkflow.State.sideEffect(key: "nah")
(First: −, Second: +) - State (First) does not match the expected state (Second)
""") {
result.assertStateModifications { state in
state = .sideEffect(key: "nah")
}
Expand Down

0 comments on commit 9b7f71c

Please sign in to comment.