From ffd92db9bb92c054966bd85b984c6a2251fcd5a0 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 29 Oct 2024 16:08:04 -0500 Subject: [PATCH] Check that snapshots always strip \r Fixes #1958 --- tests/testthat/_snaps/snapshot.md | 8 ++++++++ tests/testthat/test-snapshot.R | 5 +++++ tests/testthat/test-verify-output.R | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/tests/testthat/_snaps/snapshot.md b/tests/testthat/_snaps/snapshot.md index eb044544e..09dc8308f 100644 --- a/tests/testthat/_snaps/snapshot.md +++ b/tests/testthat/_snaps/snapshot.md @@ -44,6 +44,14 @@ Error in `f()`: ! 4 +# line-endings fixed before comparison + + Code + cat(x) + Output + a + b + # multiple outputs of same type are collapsed Code diff --git a/tests/testthat/test-snapshot.R b/tests/testthat/test-snapshot.R index ab35726b4..ff15d1de4 100644 --- a/tests/testthat/test-snapshot.R +++ b/tests/testthat/test-snapshot.R @@ -30,6 +30,11 @@ test_that("empty lines are preserved", { expect_snapshot(f(), error = TRUE) }) +test_that("line-endings fixed before comparison", { + x <- "a\n\rb" + expect_snapshot(cat(x)) +}) + test_that("multiple outputs of same type are collapsed", { expect_snapshot({ x <- 1 diff --git a/tests/testthat/test-verify-output.R b/tests/testthat/test-verify-output.R index e9c5295ca..4a3c5889d 100644 --- a/tests/testthat/test-verify-output.R +++ b/tests/testthat/test-verify-output.R @@ -91,3 +91,9 @@ test_that("verify_exec() doesn't leave tempfiles around", { expect_equal(before, after) }) + +test_that("verify_exec() strips CR", { + act <- verify_exec(quote(cat("\r\n"))) + exp <- verify_exec(quote(cat("\n"))) + expect_equal(act[-1], exp[-1]) +})