Skip to content

Commit 95212c9

Browse files
authored
fix: 🐛 abort use_targets_template() if file name is not _targets.R (#181)
# Description And update tests for match this. Needs no review. ## Checklist - [X] Ran `just run-all`
1 parent 7209f68 commit 95212c9

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

R/use-targets.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use_targets_template <- function(
1313
path = "_targets.R",
1414
open = rlang::is_interactive()
1515
) {
16-
checkmate::assert_string(fs::path_file(path), "_targets.R")
16+
if (fs::path_file(path) != "_targets.R") {
17+
cli::cli_abort("File name must be {.file _targets.R}.")
18+
}
1719

1820
template_path <- fs::path_package("fastreg", "template-targets.R")
1921

tests/testthat/test-targets.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ test_that("created file matches template content", {
1919
)
2020
})
2121

22-
test_that("returns path invisibly", {
23-
temp_path <- fs::path_temp("test_return.R")
24-
result <- use_targets_template(temp_path, open = FALSE)
25-
expect_equal(result, temp_path)
26-
})
27-
2822
test_that("template is valid R code", {
2923
expect_no_error(parse(file = template_path))
3024
})
3125

26+
test_that("use_targets_template() errors with incorrect `path`", {
27+
expect_error(
28+
use_targets_template(fs::path_temp("not-targets.R")),
29+
regexp = "_targets.R"
30+
)
31+
})
32+
3233
# Test pipeline ----------------------------------------------------------------
3334

3435
test_that("targets pipeline template converts SAS files to Parquet", {

0 commit comments

Comments
 (0)