Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/use_skill_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
27 changes: 19 additions & 8 deletions R/use_skill_r_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -40,6 +53,4 @@ use_skill_r_code <- function(
c("shared_file", "conditions")
)
}

invisible(skill_path)
}
31 changes: 30 additions & 1 deletion R/use_skill_tdd_workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}
26 changes: 26 additions & 0 deletions inst/templates/test-aaa-conditions.R
Original file line number Diff line number Diff line change
@@ -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"
)
})
21 changes: 21 additions & 0 deletions man/dot-use_conditions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/dot-use_conditions_tests.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/testthat/_snaps/aaa-conditions.md
Original file line number Diff line number Diff line change
@@ -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/pkgskills-error-subclass-test_error>
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/pkgskills-warning-subclass-test_warning>
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/pkgskills-message-subclass-test_message>
Message:
This is a test message

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/use_skill_r_code.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# use_skill_r_code() emits install message (#19, #81)
# use_skill_r_code() emits messages (#19, #81)

Code
(expect_pkg_message_classes({
expect_message(use_skill_r_code(open = FALSE), class = "pkgskills-message-ai_implementation-skill")
}, "pkgskills", "shared_file", "conditions"))
Output
<message/pkgskills-message-shared_file-conditions>
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.

12 changes: 8 additions & 4 deletions tests/testthat/_snaps/use_skill_tdd_workflow.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# use_skill_tdd_workflow() emits inform message (#11, #52)
# use_skill_tdd_workflow() emits messages (#11, #52, #97)

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/pkgskills-message-shared_file-test_conditions>
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)

Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test-aaa-conditions.R
Original file line number Diff line number Diff line change
@@ -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"
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-use_skill_r_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-use_skill_tdd_workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)", {
Expand Down
Loading