Skip to content
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

[WorkflowTesting] Use CustomDump to better visualize failure messages #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
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'
Copy link
Contributor

@jamieQ jamieQ May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my guess is this is not going to work as a change to the public repo because this has been hosted internally as a pod, but AFAIK does not exist in the public CocoaPods spec repo

Copy link

@dnkoutso dnkoutso May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. Podspecs may not specify "repos" on where the pod comes from and if the podspec is published into the cocoapods trunk (read its open source like Workflow is) then all of its dependencies must be public too.

Copy link
Contributor

@square-tomb square-tomb May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@DJBen DJBen May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I came across this and it seems public https://github.com/Golface/CocoaPods-Composable-Architecture.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnkoutso what do you recommend the next step to unblock it would be?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DJBen this is a pain...we'd have to ask for someone to publish this in the open source repo or we cannot depend on it. An alternative is to duplicate all of it inside Workflow which is meh. Trying to think of alternatives..........

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I publish it to the trunk, will it solve the issue? Because SQ internally is using a fork, will that cause a version conflict?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do it would solve this issue here I believe yes.

For SQ if it uses an internal fork it would have to ensure the version requirements specified here match and if they do then I think it will take the fork

Copy link
Author

@DJBen DJBen May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to untangle the public dependency and here's what I find:

  • CustomDump depends on XCTestDynamicOverlay, but it needs > 0.4. Unfortunately, an old 0.1.1 is occupied by another person github.com/Arafo ([email protected]).

Is it okay that I alias the pods with PFC (pointfreeco), so they become PFCXCTestDynamicOverlay and PFCCustomDump, and so I can upload our versions to the public trunk?

I anticipate that may cause source file conflict if in our test, we have both files from CustomDump and PFCCustomDump. Another alternative is to cherry-pick and prefix all the files necessary from CustomDump to this repo. I wonder what you all think.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gilgtm I managed to contact Rafa and persuade him to delete the XCTestDynamicOverlay repo so I can push a new version. I managed to push CustomDump 0.11.0 to cocoapods.

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