Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension Reducer {
debugEnvironment.queue.async {
let actionOutput = debugOutput(localAction).indent(by: 2)
let stateOutput =
debugDiff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)"
debugDiff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)\n"
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 seemed to need a newline, found it while writing a test

debugEnvironment.printer(
"""
\(prefix.isEmpty ? "" : "\(prefix): ")received action:
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComposableArchitecture/Internal/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func diff(_ first: String, _ second: String) -> String? {
first.split(separator: "\n", omittingEmptySubsequences: false)[...],
second.split(separator: "\n", omittingEmptySubsequences: false)[...]
)
guard !differences.isEmpty else { return nil }
if differences.count == 1, case .both = differences[0].which { return nil }
Copy link
Member Author

Choose a reason for hiding this comment

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

correct logic

var string = differences.reduce(into: "") { string, diff in
diff.elements.forEach { line in
string += "\(diff.which.prefix) \(line)\n"
Expand Down
29 changes: 19 additions & 10 deletions Tests/ComposableArchitectureTests/ReducerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,24 @@ final class ReducerTests: XCTestCase {
}

func testPrint() {
struct Unit: Equatable {}
enum Action: Equatable { case incr, noop }
Copy link
Member Author

Choose a reason for hiding this comment

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

updated test for the "(no changes)" behavior

struct State: Equatable { var count = 0 }

var logs: [String] = []

let expectation = self.expectation(description: "printed")

let reducer = Reducer<State, Unit, Void> { state, _, _ in
state.count += 1
return .none
let reducer = Reducer<State, Action, Void> { state, action, _ in
switch action {
case .incr:
state.count += 1
return .none
case .noop:
return .none
}
}
.debug("[prefix]") { _ in
DebugEnvironment(
printer: {
logs.append($0)
expectation.fulfill()
}
)
}
Expand All @@ -122,22 +124,29 @@ final class ReducerTests: XCTestCase {
environment: ()
)
store.assert(
.send(Unit()) { $0.count = 1 }
.send(.incr) { $0.count = 1 },
.send(.noop)
)

self.wait(for: [expectation], timeout: 1)
_ = XCTWaiter.wait(for: [self.expectation(description: "wait")], timeout: 0.1)

XCTAssertEqual(
logs,
[
#"""
[prefix]: received action:
Unit()
Action.incr
  State(
− count: 0
+ count: 1
  )

"""#,
#"""
[prefix]: received action:
Action.noop
(No state changes)

"""#
]
)
Expand Down