diff --git a/R/expect-constant.R b/R/expect-constant.R index b4b0917d4..2640f2c88 100644 --- a/R/expect-constant.R +++ b/R/expect-constant.R @@ -86,7 +86,7 @@ expect_waldo_constant_ <- function( msg <- c( sprintf("Expected %s to be %s.", act$lab, exp$lab), "Differences:", - paste0(comp, collpase = "\n") + paste0(comp, "\n") ) fail(msg, info = info, trace_env = trace_env) } else { diff --git a/R/expect-equality.R b/R/expect-equality.R index 4dfe43e0c..9c4e715cd 100644 --- a/R/expect-equality.R +++ b/R/expect-equality.R @@ -151,7 +151,7 @@ expect_waldo_equal_ <- function( msg <- c( sprintf(msg, act$lab, exp$lab), "Differences:", - paste0(comp, collpase = "\n") + paste0(comp, "\n") ) fail(msg, info = info, trace_env = trace_env) } diff --git a/tests/testthat/_snaps/expect-equality.md b/tests/testthat/_snaps/expect-equality.md index 39c919cf7..576136339 100644 --- a/tests/testthat/_snaps/expect-equality.md +++ b/tests/testthat/_snaps/expect-equality.md @@ -40,6 +40,26 @@ Differences: Types not compatible: double is not character +# correctly spaces lines + + Code + expect_equal(list(a = 1), list(a = "b", b = 10)) + Condition + Error: + ! Expected `list(a = 1)` to equal `list(a = "b", b = 10)`. + Differences: + `actual` is length 1 + `expected` is length 2 + + `names(actual)`: "a" + `names(expected)`: "a" "b" + + `actual$a` is a double vector (1) + `expected$a` is a character vector ('b') + + `actual$b` is absent + `expected$b` is a double vector (10) + # provide useful feedback on failure (2e) Code diff --git a/tests/testthat/test-expect-equality.R b/tests/testthat/test-expect-equality.R index 5924870d2..73fb883fb 100644 --- a/tests/testthat/test-expect-equality.R +++ b/tests/testthat/test-expect-equality.R @@ -72,6 +72,10 @@ test_that("provide useful feedback on failure (3e)", { expect_snapshot_failure(expect_equal(x, "a")) }) +test_that("correctly spaces lines", { + expect_snapshot_failure(expect_equal(list(a = 1), list(a = "b", b = 10))) +}) + test_that("provide useful feedback on failure (2e)", { local_edition(2) withr::local_options(testthat.edition_ignore = TRUE)