-
Notifications
You must be signed in to change notification settings - Fork 64
Description
I was just setting up tests in a new project using testthat 3e and found that comparing a string made using glue doesn't match an equivalent character string.
The change in testthat to using waldo::compare means that the compare.glue method isn't called.
Here's a reprex demonstrating the difference between testthat 2e and 3e:
library(glue)
library(testthat)
a <- glue("this is a test string")
b <- "this is a test string"
test_that("glue and character strings match - testthat 2e", {
local_edition(2)
expect_equal(a, b)
})
#> Test passed 🎊
test_that("glue and character strings match - testthat 3e", {
local_edition(3)
expect_equal(a, b)
})
#> ── Failure (<text>:14:3): glue and character strings match - testthat 3e ───────
#> `a` (`actual`) not equal to `b` (`expected`).
#>
#> `actual` is an S3 object of class <glue/character>, a character vector
#> `expected` is a character vector ('this is a test string')
testthat::compare(a, b)
#> Equal
waldo::compare(a, b)
#> `old` is an S3 object of class <glue/character>, a character vector
#> `new` is a character vector ('this is a test string')Created on 2021-02-24 by the reprex package (v1.0.0)
Workarounds for now would be to use testthat 2e (remove/omit the Config/testthat/edition: 3 line from DESCRIPTION in projects using testthat >= 3.0.0), or wrap the expected values in tests where glue creates the actual string(s) with as_glue().
But it looks like compare_proxy provides a way to override the default comparison behaviour in waldo. I'd be happy to put together a pull request if it's wanted. Thanks.