Skip to content

Commit a930f5c

Browse files
committed
Tweak use_catch() messaging
And add a test
1 parent d65a5e7 commit a930f5c

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

R/test-compiled-code.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,11 @@ use_catch <- function(dir = getwd()) {
392392
output_path <- file.path(dir, "R", "catch-routine-registration.R")
393393
cat(transformed, file = output_path)
394394

395-
cli::cli_inform("> Added C++ unit testing infrastructure.")
396-
cli::cli_inform(
397-
"> Please ensure you have {.field LinkingTo: testthat} in your DESCRIPTION."
398-
)
399-
cli::cli_inform(
400-
"> Please ensure you have {.field Suggests: xml2} in your DESCRIPTION."
401-
)
402-
cli::cli_inform(
403-
"> Please ensure you have {.code useDynLib({pkg}, .registration = TRUE)} in your NAMESPACE."
404-
)
395+
cli::cli_inform(c(
396+
v = "Added C++ unit testing infrastructure.",
397+
i = "Please ensure you have {.field LinkingTo: testthat} in your DESCRIPTION.",
398+
i = "Please ensure you have {.field Suggests: xml2} in your DESCRIPTION."
399+
))
405400
}
406401

407402
get_routine <- function(package, routine) {

tests/testthat/_snaps/test-compiled-code.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@
1919
Error in `run_cpp_tests()`:
2020
! `package` must be a single string, not the number 123.
2121

22+
# useful messaging
23+
24+
Code
25+
use_catch(path)
26+
Message
27+
v Added C++ unit testing infrastructure.
28+
i Please ensure you have LinkingTo: testthat in your DESCRIPTION.
29+
i Please ensure you have Suggests: xml2 in your DESCRIPTION.
30+

tests/testthat/test-test-compiled-code.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@ test_that("validates inputs", {
1414
})
1515
})
1616

17+
test_that("useful messaging", {
18+
path <- withr::local_tempdir()
19+
writeLines("Package: foo", file.path(path, "DESCRIPTION"))
20+
dir.create(file.path(path, "R"))
21+
22+
expect_snapshot(use_catch(path))
23+
})
24+
1725
skip_if_not_installed("xml2")
1826
run_cpp_tests("testthat")

0 commit comments

Comments
 (0)