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

Newlines in the extended failure message are unconditionally stripped #959

Closed
1 task done
agurtovoy opened this issue Jan 23, 2022 · 1 comment · Fixed by #1001
Closed
1 task done

Newlines in the extended failure message are unconditionally stripped #959

agurtovoy opened this issue Jan 23, 2022 · 1 comment · Fixed by #1001
Labels
Milestone

Comments

@agurtovoy
Copy link

  • I have read CONTRIBUTING and have done my best to follow them.

What did you do?

First of all, thanks for the awesome library!

We have written a custom Nimble <-> swift-snapshot-testing integration that essentially looks like this:

public func matchSnapshot<T, Format>(named name: String? = nil, as format: Snapshotting<T, Format>,
                                     file: StaticString = #file, line: UInt = #line) -> Predicate<T> {
    return Predicate { (actualExpression: Expression<T>) throws -> PredicateResult in
        let msg = ExpectationMessage.expectedTo(name != nil ? "match snapshot '\(name!)'" : "match snapshot")
        if let actualValue = try actualExpression.evaluate() {
            if let failure = verifySnapshot(matching: actualValue, as: format, named: name,
                                           file: file, testName: QuickSpec.current.shortName, line: line) {
                return PredicateResult(
                    status: .fail,
                    message: msg.appended(details: failure) 
                    //                    ^^^^^^^^^^^^^^^^^
                    //                    expected appended `details` to preserve newlines
                )
            }
                
            return PredicateResult(status: .matches, message: msg)
        } else {
            return PredicateResult(
                status: .fail,
                message: msg.appendedBeNilHint()
            )
        }
    }
}

When not nil, failure is a multi-line string diff between the actual value and the snapshot.

What did you expect to happen?

We expected that Nimble would preserve the newlines in the extended failure message.

What actually happened instead?

Instead, newlines in the extended failure message appear to be unconditionally stripped, which renders the snapshot diffs unusable:

value += "\n\(stripNewlines(extendedMessage))"

This also seems to violate the documented intent of appended(details: String):

For a more comprehensive message that spans multiple lines, use appended(details: String) instead

Environment

List the software versions you're using:

  • Quick: 4.0.0
  • Nimble: 9.1.0
  • Xcode Version: 13.2 (13C90)
  • Swift Version: Xcode Default

Please also mention which package manager you used and its version. Delete the
other package managers in this list:

  • Swift Package Manager: 5.5.0
@younata younata added this to the v11.0.0 milestone Apr 19, 2022
@younata
Copy link
Member

younata commented Apr 19, 2022

Going to prioritize this for v11 (assuming this is something we can actually fix and not, like, an Xcode/xctest limitation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants