diff --git a/DESCRIPTION b/DESCRIPTION index 56e347b..91cd1a1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,3 +38,4 @@ BugReports: https://github.com/tidyverse/glue/issues VignetteBuilder: knitr ByteCompile: true Config/Needs/website: tidyverse/tidytemplate +Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index 59a1140..b0eafe2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # glue (development version) +* `compare_proxy.glue()` method defined so glue objects can be compared to strings in testthat 3e without errors (#212) * Unterminated comments in glue expression now throw an error (#227, @gaborcsardi) * Unterminated quotes in glue expressions now throw an error (#226, @gaborcsardi) * `print.glue()` no longer prints an empty newline for 0 length inputs (#214) diff --git a/R/utils.R b/R/utils.R index c3d4aa5..9f0138c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -82,3 +82,9 @@ compare.glue <- function(x, y, ...) { } NextMethod("compare") } + +## @export +compare_proxy.glue <- function(x, path = "x") { + class(x) <- NULL + NextMethod("compare_proxy") +} diff --git a/R/zzz.R b/R/zzz.R index 75a0159..f92e130 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,6 +1,7 @@ # nocov start .onLoad <- function(...) { register_s3_method("testthat", "compare", "glue") + register_s3_method("waldo", "compare_proxy", "glue") # Register on package load because vctrs depends on glue and will # not be fully loaded when glue is loaded diff --git a/tests/testthat/test-collapse.R b/tests/testthat/test-collapse.R index c839896..4b2e378 100644 --- a/tests/testthat/test-collapse.R +++ b/tests/testthat/test-collapse.R @@ -1,5 +1,3 @@ -context("glue_collapse") - test_that("glue_collapse works like paste(glue_collapse=)", { # Always return 0 length outputs for 0 length inputs. #expect_identical(paste(glue_collapse = "", character(0)), glue_collapse(character(0))) diff --git a/tests/testthat/test-color.R b/tests/testthat/test-color.R index bafcec4..9dbcea6 100644 --- a/tests/testthat/test-color.R +++ b/tests/testthat/test-color.R @@ -1,5 +1,3 @@ -context("color") - skip_if_not_installed("crayon") library(crayon) diff --git a/tests/testthat/test-glue.R b/tests/testthat/test-glue.R index 10bceb5..5435034 100644 --- a/tests/testthat/test-glue.R +++ b/tests/testthat/test-glue.R @@ -1,5 +1,3 @@ -context("glue") - test_that("inputs are concatenated, interpolated variables recycled", { expect_equal(glue("test", "a", "string", "{1:2}"), c("testastring1", "testastring2")) }) @@ -505,7 +503,7 @@ test_that("throws informative error if interpolating a function", { # some crayon functions are OK, make sure this still works if (require("crayon")) { - expect_is(glue("{red}red{reset}"), "glue") + expect_s3_class(glue("{red}red{reset}"), "glue") } }) @@ -531,3 +529,7 @@ test_that("unterminated comment", { test_that("empty glue produces no output", { expect_equal(capture.output(print(glue())), character()) }) + +test_that("glue objects can be compared to regular strings", { + expect_equal(capture.output(print(glue())), character()) +}) diff --git a/tests/testthat/test-quoting.R b/tests/testthat/test-quoting.R index 6b8f14e..01a06f5 100644 --- a/tests/testthat/test-quoting.R +++ b/tests/testthat/test-quoting.R @@ -1,5 +1,3 @@ -context("quoting") - test_that("single_quote works", { expect_identical(single_quote(character()), character()) expect_identical(single_quote(NA), NA_character_) diff --git a/tests/testthat/test-sql.R b/tests/testthat/test-sql.R index 3b4f18b..5a083b2 100644 --- a/tests/testthat/test-sql.R +++ b/tests/testthat/test-sql.R @@ -1,5 +1,3 @@ -context("sql") - skip_if_not_installed("DBI") skip_if_not_installed("RSQLite") diff --git a/tests/testthat/test-trim.R b/tests/testthat/test-trim.R index 73b9d98..00b25ae 100644 --- a/tests/testthat/test-trim.R +++ b/tests/testthat/test-trim.R @@ -1,5 +1,3 @@ -context("trim") - test_that("trim works", { expect_identical("", trim("")) expect_identical(character(), trim(character()))