Skip to content

Commit

Permalink
[WorkflowTesting] Use CustomDump to better visualize failure messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DJBen committed May 17, 2023
1 parent 1f86835 commit 202355f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ let package = Package(
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift.git", from: "7.1.1"),
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.2.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.44.14"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "0.6.1"),
],
targets: [
// MARK: Workflow
Expand All @@ -103,7 +104,10 @@ let package = Package(
),
.target(
name: "WorkflowTesting",
dependencies: ["Workflow"],
dependencies: [
.product(name: "CustomDump", package: "swift-custom-dump"),
"Workflow",
],
path: "WorkflowTesting/Sources"
),
.testTarget(
Expand Down
1 change: 1 addition & 0 deletions WorkflowTesting.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Pod::Spec.new do |s|
s.source_files = 'WorkflowTesting/Sources/**/*.swift'

s.dependency 'Workflow', "#{s.version}"
s.dependency 'CustomDump', '~> 0.6.1'
s.framework = 'XCTest'

s.pod_target_xcconfig = {
Expand Down
7 changes: 4 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 @@ -77,7 +78,7 @@ public struct RenderTesterResult<WorkflowType: Workflow> {
line: UInt = #line
) -> RenderTesterResult<WorkflowType> where ActionType.WorkflowType == WorkflowType, ActionType: Equatable {
return verifyAction(file: file, line: line) { appliedAction in
XCTAssertEqual(appliedAction, action, file: file, line: line)
XCTAssertNoDifference(appliedAction, action, file: file, line: line)
}
}

Expand Down Expand Up @@ -117,7 +118,7 @@ extension RenderTesterResult where WorkflowType.State: Equatable {
file: StaticString = #file,
line: UInt = #line
) -> RenderTesterResult<WorkflowType> {
XCTAssertEqual(state, expectedState, file: file, line: line)
XCTAssertNoDifference(state, expectedState, file: file, line: line)
return self
}
}
Expand All @@ -131,7 +132,7 @@ extension RenderTesterResult where WorkflowType.Output: Equatable {
line: UInt = #line
) -> RenderTesterResult<WorkflowType> {
return verifyOutput(file: file, line: line) { output in
XCTAssertEqual(output, expectedOutput, file: file, line: line)
XCTAssertNoDifference(output, expectedOutput, file: file, line: line)
}
}
}
11 changes: 6 additions & 5 deletions WorkflowTesting/Sources/WorkflowActionTester.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 All @@ -32,10 +33,10 @@ extension WorkflowAction {
/// .tester(withState: .firstState)
/// .send(action: .exampleAction)
/// .verifyOutput { output in
/// XCTAssertEqual(.finished, output)
/// XCTAssertNoDifference(.finished, output)
/// }
/// .verifyState { state in
/// XCTAssertEqual(.differentState, state)
/// XCTAssertNoDifference(.differentState, state)
/// }
/// ```
///
Expand All @@ -47,7 +48,7 @@ extension WorkflowAction {
/// .send(action: .actionProducingNoOutput)
/// .assertNoOutput()
/// .verifyState { state in
/// XCTAssertEqual(.differentState, state)
/// XCTAssertNoDifference(.differentState, state)
/// }
/// ```
///
Expand Down Expand Up @@ -143,7 +144,7 @@ extension WorkflowActionTester where WorkflowType.State: Equatable {
@discardableResult
public func assert(state expectedState: WorkflowType.State, file: StaticString = #file, line: UInt = #line) -> WorkflowActionTester<WorkflowType, Action> {
return verifyState { actualState in
XCTAssertEqual(actualState, expectedState, file: file, line: line)
XCTAssertNoDifference(actualState, expectedState, file: file, line: line)
}
}
}
Expand All @@ -157,7 +158,7 @@ extension WorkflowActionTester where WorkflowType.Output: Equatable {
@discardableResult
public func assert(output expectedOutput: WorkflowType.Output, file: StaticString = #file, line: UInt = #line) -> WorkflowActionTester<WorkflowType, Action> {
return verifyOutput { actualOutput in
XCTAssertEqual(actualOutput, expectedOutput, file: file, line: line)
XCTAssertNoDifference(actualOutput, expectedOutput, file: file, line: line)
}
}
}
7 changes: 4 additions & 3 deletions WorkflowTesting/Sources/WorkflowRenderTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// `@testable import Workflow` will fail compilation in Release mode.
#if DEBUG

import CustomDump
import XCTest
@testable import Workflow

Expand Down Expand Up @@ -60,7 +61,7 @@ extension Workflow {
/// producingOutput: nil
/// )
/// .render { rendering in
/// XCTAssertEqual("expected text on rendering", rendering.text)
/// XCTAssertNoDifference("expected text on rendering", rendering.text)
/// }
/// .assert(state: TestWorkflow.State())
/// .assert(output: TestWorkflow.Output.finished)
Expand All @@ -71,7 +72,7 @@ extension Workflow {
/// workflow
/// .renderTester()
/// .render { rendering in
/// XCTAssertEqual("expected text on rendering", rendering.text)
/// XCTAssertNoDifference("expected text on rendering", rendering.text)
/// }
/// ```
///
Expand All @@ -80,7 +81,7 @@ extension Workflow {
/// workflow
/// .renderTester()
/// .render { rendering in
/// XCTAssertEqual("expected text on rendering", rendering.text)
/// XCTAssertNoDifference("expected text on rendering", rendering.text)
/// rendering.updateText("updated")
/// }
/// .assert(
Expand Down
33 changes: 30 additions & 3 deletions WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,16 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
rendering.doNoopAction(10)
}

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

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

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

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

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

Expand Down

0 comments on commit 202355f

Please sign in to comment.