pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.72k stars 565 forks source link

Inline snapshot testing output fails when URL request body expected contains carriage returns #771

Closed lukeredpath closed 11 months ago

lukeredpath commented 11 months ago

Describe the bug I'm converting our assertion helper that tests our API client routes generate the correct URL requests over to the new inline snapshot tool. It works well except for one test that uses my swift-url-routing-multipart extension to create a multipart request body. This intentionally contains \r\n line breaks, but these get converted to \n when written into the source file using the .raw strategy, causing the test to fail when re-run.

func testCarriageReturnInlineSnapshot() {
    let string = "This is a line\r\nAnd this is a line\r\n"
    var request = URLRequest(url: URL(string: "https://www.example.com")!)
    request.httpMethod = "POST"
    request.httpBody = string.data(using: .utf8)!
    assertInlineSnapshot(of: request, as: .raw) {
        """
        POST https://www.example.com

        This is a line
        And this is a line

        """
    }
}

Expected behavior I'd expect the original line breaks to be preserved.

Environment

stephencelis commented 11 months ago

Strange! The \r is definitely preserved in the syntax we're writing, so this is probably an issue of Xcode's line ending settings. Either way carriage returns are probably an important thing to verify, so I've opened #772 to address.

lukeredpath commented 11 months ago

I've tested out the above fix and it has resolved my issue.