From c79a9aa4e473428d0da79b95e12b17b8dd00635a Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Sat, 16 May 2026 08:03:14 -0500 Subject: [PATCH 1/2] Install tests with tdd-workflow Closes #97 --- R/use_skill_document.R | 2 +- R/use_skill_r_code.R | 27 +++++++++++----- R/use_skill_tdd_workflow.R | 31 ++++++++++++++++++- inst/templates/test-aaa-conditions.R | 26 ++++++++++++++++ man/dot-use_conditions.Rd | 21 +++++++++++++ man/dot-use_conditions_tests.Rd | 21 +++++++++++++ tests/testthat/_snaps/aaa-conditions.md | 30 ++++++++++++++++++ tests/testthat/_snaps/use_skill_r_code.md | 6 ++-- .../testthat/_snaps/use_skill_tdd_workflow.md | 12 ++++--- tests/testthat/test-aaa-conditions.R | 26 ++++++++++++++++ tests/testthat/test-use_skill_r_code.R | 2 +- tests/testthat/test-use_skill_tdd_workflow.R | 14 +++++++-- 12 files changed, 198 insertions(+), 20 deletions(-) create mode 100644 inst/templates/test-aaa-conditions.R create mode 100644 man/dot-use_conditions.Rd create mode 100644 man/dot-use_conditions_tests.Rd create mode 100644 tests/testthat/_snaps/aaa-conditions.md create mode 100644 tests/testthat/test-aaa-conditions.R diff --git a/R/use_skill_document.R b/R/use_skill_document.R index d9b5780..42dfbe8 100644 --- a/R/use_skill_document.R +++ b/R/use_skill_document.R @@ -26,7 +26,7 @@ use_skill_document <- function( shared_params_path <- usethis::proj_path("R/aaa-shared_params.R") if (!fs::file_exists(shared_params_path)) { - .use_template("aaa-shared_params.R", "R/aaa-shared_params.R") + .use_template("aaa-shared_params.R", "R/aaa-shared_params.R", open = open) .pkg_inform( c( "{.file R/aaa-shared_params.R} created.", diff --git a/R/use_skill_r_code.R b/R/use_skill_r_code.R index f63ba16..a225d8d 100644 --- a/R/use_skill_r_code.R +++ b/R/use_skill_r_code.R @@ -16,22 +16,35 @@ use_skill_r_code <- function( overwrite = FALSE, open = rlang::is_interactive() ) { - skill_path <- .use_skill( + .use_conditions(overwrite, open) + invisible(.use_skill( "r-code", target_dir = target_dir, use_skills_subdir = use_skills_subdir, overwrite = overwrite, open = open - ) + )) +} +#' Install the conditions template +#' +#' @inheritParams .shared-params +#' @returns The path to the installed conditions file, invisibly. +#' @keywords internal +.use_conditions <- function(overwrite = FALSE, open = rlang::is_interactive()) { + usethis::use_package("stbl", min_version = "0.3.0.9000") conditions_path <- usethis::proj_path("R/aaa-conditions.R") - if (!fs::file_exists(conditions_path)) { + if (!fs::file_exists(conditions_path) || overwrite) { data <- .get_desc_fields("Package") - .use_template("aaa-conditions.R", "R/aaa-conditions.R", data = data) - usethis::use_package("stbl", min_version = "0.3.0") + .use_template( + "aaa-conditions.R", + "R/aaa-conditions.R", + data = data, + open = open + ) .pkg_inform( c( - "{.file R/aaa-conditions.R} created.", + "{.file R/aaa-conditions.R} created or updated.", "i" = paste( "Use {.fn .pkg_abort} for package errors.", "Add more error helpers here as your package grows." @@ -40,6 +53,4 @@ use_skill_r_code <- function( c("shared_file", "conditions") ) } - - invisible(skill_path) } diff --git a/R/use_skill_tdd_workflow.R b/R/use_skill_tdd_workflow.R index 8d0ff3f..f93b088 100644 --- a/R/use_skill_tdd_workflow.R +++ b/R/use_skill_tdd_workflow.R @@ -21,7 +21,9 @@ use_skill_tdd_workflow <- function( "no_package_field" ) } - usethis::use_package("stbl", min_version = "0.3.0") + usethis::use_package("stbl", min_version = "0.3.0.9000") + usethis::use_testthat() + .use_conditions_tests(overwrite, open) invisible(.use_skill( "tdd-workflow", data = list(package = pkg_name), @@ -31,3 +33,30 @@ use_skill_tdd_workflow <- function( open = open )) } + +#' Install the conditions tests template +#' +#' @inheritParams .shared-params +#' @returns The path to the installed test file, invisibly. +#' @keywords internal +.use_conditions_tests <- function( + overwrite = FALSE, + open = rlang::is_interactive() +) { + usethis::use_package("stbl", min_version = "0.3.0.9000") + conditions_path <- usethis::proj_path("tests/testthat/test-aaa-conditions.R") + if (!fs::file_exists(conditions_path) || overwrite) { + data <- .get_desc_fields("Package") + .use_template( + "test-aaa-conditions.R", + "tests/testthat/test-aaa-conditions.R", + data = data, + open = open + ) + .pkg_inform( + "{.file tests/testthat/test-aaa-conditions.R} created or updated.", + c("shared_file", "test_conditions") + ) + } + invisible(conditions_path) +} diff --git a/inst/templates/test-aaa-conditions.R b/inst/templates/test-aaa-conditions.R new file mode 100644 index 0000000..59e2a48 --- /dev/null +++ b/inst/templates/test-aaa-conditions.R @@ -0,0 +1,26 @@ +test_that(".pkg_abort works", { + stbl::expect_pkg_error_snapshot( + .pkg_abort("This is a test error", c("subclass", "test_error")), + "{{{Package}}}", + "subclass", + "test_error" + ) +}) + +test_that(".pkg_warn works", { + stbl::expect_pkg_warning_snapshot( + .pkg_warn("This is a test warning", c("subclass", "test_warning")), + "{{{Package}}}", + "subclass", + "test_warning" + ) +}) + +test_that(".pkg_inform works", { + stbl::expect_pkg_message_snapshot( + .pkg_inform("This is a test message", c("subclass", "test_message")), + "{{{Package}}}", + "subclass", + "test_message" + ) +}) diff --git a/man/dot-use_conditions.Rd b/man/dot-use_conditions.Rd new file mode 100644 index 0000000..85320e6 --- /dev/null +++ b/man/dot-use_conditions.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/use_skill_r_code.R +\name{.use_conditions} +\alias{.use_conditions} +\title{Install the conditions template} +\usage{ +.use_conditions(overwrite = FALSE, open = rlang::is_interactive()) +} +\arguments{ +\item{overwrite}{(\code{logical(1)}) Whether to overwrite existing file(s). +Defaults to \code{FALSE}.} + +\item{open}{(\code{logical(1)}) Whether to open the file after creation.} +} +\value{ +The path to the installed conditions file, invisibly. +} +\description{ +Install the conditions template +} +\keyword{internal} diff --git a/man/dot-use_conditions_tests.Rd b/man/dot-use_conditions_tests.Rd new file mode 100644 index 0000000..f585051 --- /dev/null +++ b/man/dot-use_conditions_tests.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/use_skill_tdd_workflow.R +\name{.use_conditions_tests} +\alias{.use_conditions_tests} +\title{Install the conditions tests template} +\usage{ +.use_conditions_tests(overwrite = FALSE, open = rlang::is_interactive()) +} +\arguments{ +\item{overwrite}{(\code{logical(1)}) Whether to overwrite existing file(s). +Defaults to \code{FALSE}.} + +\item{open}{(\code{logical(1)}) Whether to open the file after creation.} +} +\value{ +The path to the installed test file, invisibly. +} +\description{ +Install the conditions tests template +} +\keyword{internal} diff --git a/tests/testthat/_snaps/aaa-conditions.md b/tests/testthat/_snaps/aaa-conditions.md new file mode 100644 index 0000000..12b8f44 --- /dev/null +++ b/tests/testthat/_snaps/aaa-conditions.md @@ -0,0 +1,30 @@ +# .pkg_abort works + + Code + (expect_pkg_error_classes(.pkg_abort("This is a test error", c("subclass", + "test_error")), "pkgskills", "subclass", "test_error")) + Output + + Error: + ! This is a test error + +# .pkg_warn works + + Code + (expect_pkg_warning_classes(.pkg_warn("This is a test warning", c("subclass", + "test_warning")), "pkgskills", "subclass", "test_warning")) + Output + + Warning: + This is a test warning + +# .pkg_inform works + + Code + (expect_pkg_message_classes(.pkg_inform("This is a test message", c("subclass", + "test_message")), "pkgskills", "subclass", "test_message")) + Output + + Message: + This is a test message + diff --git a/tests/testthat/_snaps/use_skill_r_code.md b/tests/testthat/_snaps/use_skill_r_code.md index d84d707..d6f5f12 100644 --- a/tests/testthat/_snaps/use_skill_r_code.md +++ b/tests/testthat/_snaps/use_skill_r_code.md @@ -1,4 +1,4 @@ -# use_skill_r_code() emits install message (#19, #81) +# use_skill_r_code() emits messages (#19, #81) Code (expect_pkg_message_classes({ @@ -6,7 +6,7 @@ }, "pkgskills", "shared_file", "conditions")) Output - Message in `use_skill_r_code()`: - 'R/aaa-conditions.R' created. + Message in `.use_conditions()`: + 'R/aaa-conditions.R' created or updated. i Use `.pkg_abort()` for package errors. Add more error helpers here as your package grows. diff --git a/tests/testthat/_snaps/use_skill_tdd_workflow.md b/tests/testthat/_snaps/use_skill_tdd_workflow.md index a0d3f05..5290266 100644 --- a/tests/testthat/_snaps/use_skill_tdd_workflow.md +++ b/tests/testthat/_snaps/use_skill_tdd_workflow.md @@ -1,9 +1,13 @@ -# use_skill_tdd_workflow() emits inform message (#11, #52) +# use_skill_tdd_workflow() emits messages (#11, #52) Code - use_skill_tdd_workflow(open = FALSE) - Message - Skill '.github/skills/tdd-workflow/SKILL.md' installed. + (expect_pkg_message_classes({ + expect_message(use_skill_tdd_workflow(open = FALSE), class = "pkgskills-message-ai_implementation-skill") + }, "pkgskills", "shared_file", "test_conditions")) + Output + + Message in `.use_conditions_tests()`: + 'tests/testthat/test-aaa-conditions.R' created or updated. # use_skill_tdd_workflow() errors when Package field is absent (#11) diff --git a/tests/testthat/test-aaa-conditions.R b/tests/testthat/test-aaa-conditions.R new file mode 100644 index 0000000..55c848d --- /dev/null +++ b/tests/testthat/test-aaa-conditions.R @@ -0,0 +1,26 @@ +test_that(".pkg_abort works", { + stbl::expect_pkg_error_snapshot( + .pkg_abort("This is a test error", c("subclass", "test_error")), + "pkgskills", + "subclass", + "test_error" + ) +}) + +test_that(".pkg_warn works", { + stbl::expect_pkg_warning_snapshot( + .pkg_warn("This is a test warning", c("subclass", "test_warning")), + "pkgskills", + "subclass", + "test_warning" + ) +}) + +test_that(".pkg_inform works", { + stbl::expect_pkg_message_snapshot( + .pkg_inform("This is a test message", c("subclass", "test_message")), + "pkgskills", + "subclass", + "test_message" + ) +}) diff --git a/tests/testthat/test-use_skill_r_code.R b/tests/testthat/test-use_skill_r_code.R index 5e0c817..2a8f8fb 100644 --- a/tests/testthat/test-use_skill_r_code.R +++ b/tests/testthat/test-use_skill_r_code.R @@ -16,7 +16,7 @@ test_that("use_skill_r_code() returns path invisibly (#19)", { ) }) -test_that("use_skill_r_code() emits install message (#19, #81)", { +test_that("use_skill_r_code() emits messages (#19, #81)", { local_pkg() stbl::expect_pkg_message_snapshot( { diff --git a/tests/testthat/test-use_skill_tdd_workflow.R b/tests/testthat/test-use_skill_tdd_workflow.R index f416358..4f1f03e 100644 --- a/tests/testthat/test-use_skill_tdd_workflow.R +++ b/tests/testthat/test-use_skill_tdd_workflow.R @@ -34,9 +34,19 @@ test_that("use_skill_tdd_workflow() renders package name into skill file (#11)", expect_false(any(grepl("\\{\\{\\{package\\}\\}\\}", content))) }) -test_that("use_skill_tdd_workflow() emits inform message (#11, #52)", { +test_that("use_skill_tdd_workflow() emits messages (#11, #52, #97)", { local_pkg() - expect_snapshot(use_skill_tdd_workflow(open = FALSE)) + stbl::expect_pkg_message_snapshot( + { + expect_message( + use_skill_tdd_workflow(open = FALSE), + class = "pkgskills-message-ai_implementation-skill" + ) + }, + "pkgskills", + "shared_file", + "test_conditions" + ) }) test_that("use_skill_tdd_workflow() errors when Package field is absent (#11)", { From 9a5b42b9b6809ad6dd2551645f24557c9ecc623f Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Sat, 16 May 2026 08:06:59 -0500 Subject: [PATCH 2/2] Update snaps --- tests/testthat/_snaps/use_skill_tdd_workflow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/use_skill_tdd_workflow.md b/tests/testthat/_snaps/use_skill_tdd_workflow.md index 5290266..bf5878e 100644 --- a/tests/testthat/_snaps/use_skill_tdd_workflow.md +++ b/tests/testthat/_snaps/use_skill_tdd_workflow.md @@ -1,4 +1,4 @@ -# use_skill_tdd_workflow() emits messages (#11, #52) +# use_skill_tdd_workflow() emits messages (#11, #52, #97) Code (expect_pkg_message_classes({