diff --git a/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift b/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift index b4e26d7c5291..5cb6a168c3eb 100644 --- a/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift +++ b/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift @@ -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" debugEnvironment.printer( """ \(prefix.isEmpty ? "" : "\(prefix): ")received action: diff --git a/Sources/ComposableArchitecture/Internal/Diff.swift b/Sources/ComposableArchitecture/Internal/Diff.swift index 222efdc450e4..a3e47b3de736 100644 --- a/Sources/ComposableArchitecture/Internal/Diff.swift +++ b/Sources/ComposableArchitecture/Internal/Diff.swift @@ -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 } var string = differences.reduce(into: "") { string, diff in diff.elements.forEach { line in string += "\(diff.which.prefix) \(line)\n" diff --git a/Tests/ComposableArchitectureTests/ReducerTests.swift b/Tests/ComposableArchitectureTests/ReducerTests.swift index 445e7660db69..66090fa12a6a 100644 --- a/Tests/ComposableArchitectureTests/ReducerTests.swift +++ b/Tests/ComposableArchitectureTests/ReducerTests.swift @@ -96,22 +96,24 @@ final class ReducerTests: XCTestCase { } func testPrint() { - struct Unit: Equatable {} + enum Action: Equatable { case incr, noop } struct State: Equatable { var count = 0 } var logs: [String] = [] - let expectation = self.expectation(description: "printed") - - let reducer = Reducer { state, _, _ in - state.count += 1 - return .none + let reducer = Reducer { 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() } ) } @@ -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) + """# ] )