Skip to content

Commit 74c22bb

Browse files
committed
update
1 parent 527218d commit 74c22bb

4 files changed

Lines changed: 77 additions & 42 deletions

File tree

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
* Made `use_zzz()` compatible with `usethis`
1111

12+
* Added cov ignorance in `use_zzz()`
13+
1214

1315
# rpkgkit 0.1.2 (2026-06-29)
1416

R/45_use_zzz.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ use_zzz <- function(
6262
package = "rpkgkit",
6363
mustWork = TRUE
6464
)
65-
tmpl <- readLines(con = template, warn = FALSE)
65+
tmpl <- c(
66+
paste("# nocov", "start"),
67+
"",
68+
readLines(con = template, warn = FALSE)
69+
)
6670
tmpl <- gsub(pattern = "\\bPKG\\b", replacement = pkg, x = tmpl)
6771
tmpl <- gsub(pattern = "\\bTITLE\\b", replacement = title, x = tmpl)
6872
tmpl <- gsub(
@@ -76,7 +80,9 @@ use_zzz <- function(
7680
"",
7781
"## usethis namespace: start",
7882
"## usethis namespace: end",
79-
"NULL"
83+
"NULL",
84+
"",
85+
paste("# nocov", "end")
8086
)
8187
target_path <- file.path(path, "R", file_name)
8288
if (file.exists(target_path)) {

R/rpkgkit-package.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# nocov start
2+
13
#' @title Create and Maintain R Packages
24
#'
35
#' @description Utilities for R package development including NEWS.md
@@ -34,3 +36,5 @@
3436
## usethis namespace: start
3537
## usethis namespace: end
3638
NULL
39+
40+
# nocov end

tests/testthat/test-use_zzz.R

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
test_that("aborts when path is not a package root", {
2-
tmp <- tempfile("not_pkg")
3-
dir.create(tmp)
4-
on.exit(unlink(tmp, recursive = TRUE))
2+
tmp <- withr::local_tempdir()
53

64
expect_error(
75
use_zzz(path = tmp),
@@ -10,9 +8,12 @@ test_that("aborts when path is not a package root", {
108
})
119

1210
test_that("aborts when zzz.R already exists and overwrite = FALSE", {
13-
tmp <- tempfile("pkg")
14-
dir.create(tmp)
15-
on.exit(unlink(tmp, recursive = TRUE))
11+
tmp <- withr::local_tempdir()
12+
local_mocked_bindings(
13+
proj_set = function(...) NULL,
14+
use_package = function(...) NULL,
15+
.package = "usethis"
16+
)
1617

1718
writeLines(
1819
c(
@@ -33,9 +34,12 @@ test_that("aborts when zzz.R already exists and overwrite = FALSE", {
3334
})
3435

3536
test_that("creates zzz.R with PKG replaced in template", {
36-
tmp <- tempfile("pkg")
37-
dir.create(tmp)
38-
on.exit(unlink(tmp, recursive = TRUE))
37+
tmp <- withr::local_tempdir()
38+
local_mocked_bindings(
39+
proj_set = function(...) NULL,
40+
use_package = function(...) NULL,
41+
.package = "usethis"
42+
)
3943

4044
writeLines(
4145
c(
@@ -54,15 +58,18 @@ test_that("creates zzz.R with PKG replaced in template", {
5458
expect_true(file.exists(expected_path))
5559

5660
lines <- readLines(expected_path, warn = FALSE)
57-
expect_match(lines[1L], "#' @title My Test Package", fixed = TRUE)
58-
expect_match(lines[9L], "^#' @name testpkg-package$", perl = TRUE)
59-
expect_match(lines[10L], "^#' @aliases testpkg$", perl = TRUE)
61+
expect_match(lines[3L], "#' @title My Test Package", fixed = TRUE)
62+
expect_match(lines[11L], "^#' @name testpkg-package$", perl = TRUE)
63+
expect_match(lines[12L], "^#' @aliases testpkg$", perl = TRUE)
6064
})
6165

6266
test_that("creates zzz.R with correct TITLE replacement", {
63-
tmp <- tempfile("pkg")
64-
dir.create(tmp)
65-
on.exit(unlink(tmp, recursive = TRUE))
67+
tmp <- withr::local_tempdir()
68+
local_mocked_bindings(
69+
proj_set = function(...) NULL,
70+
use_package = function(...) NULL,
71+
.package = "usethis"
72+
)
6673

6774
writeLines(
6875
c(
@@ -77,13 +84,16 @@ test_that("creates zzz.R with correct TITLE replacement", {
7784
use_zzz(path = tmp)
7885

7986
lines <- readLines(file.path(tmp, "R", "testpkg-package.R"), warn = FALSE)
80-
expect_match(lines[1L], "#' @title Custom Title Here", fixed = TRUE)
87+
expect_match(lines[3L], "#' @title Custom Title Here", fixed = TRUE)
8188
})
8289

8390
test_that("creates zzz.R with DESCRIPTION replacement (including multiline)", {
84-
tmp <- tempfile("pkg")
85-
dir.create(tmp)
86-
on.exit(unlink(tmp, recursive = TRUE))
91+
tmp <- withr::local_tempdir()
92+
local_mocked_bindings(
93+
proj_set = function(...) NULL,
94+
use_package = function(...) NULL,
95+
.package = "usethis"
96+
)
8797

8898
writeLines(
8999
c(
@@ -99,20 +109,21 @@ test_that("creates zzz.R with DESCRIPTION replacement (including multiline)", {
99109
use_zzz(path = tmp)
100110

101111
lines <- readLines(file.path(tmp, "R", "testpkg-package.R"), warn = FALSE)
102-
# Description spans lines 3-4: "#' @description A package for testing."
103-
# then "#' It has multiple lines."
104112
expect_match(
105-
lines[3L],
113+
lines[5L],
106114
"#' @description A package for testing.",
107115
fixed = TRUE
108116
)
109-
expect_match(lines[4L], "#' It has multiple lines.", fixed = TRUE)
117+
expect_match(lines[6L], "#' It has multiple lines.", fixed = TRUE)
110118
})
111119

112120
test_that("creates zzz.R with correct LICENSE replacement", {
113-
tmp <- tempfile("pkg")
114-
dir.create(tmp)
115-
on.exit(unlink(tmp, recursive = TRUE))
121+
tmp <- withr::local_tempdir()
122+
local_mocked_bindings(
123+
proj_set = function(...) NULL,
124+
use_package = function(...) NULL,
125+
.package = "usethis"
126+
)
116127

117128
writeLines(
118129
c(
@@ -127,13 +138,16 @@ test_that("creates zzz.R with correct LICENSE replacement", {
127138
use_zzz(path = tmp)
128139

129140
lines <- readLines(file.path(tmp, "R", "testpkg-package.R"), warn = FALSE)
130-
expect_match(lines[6L], "^#' GPL-3$", perl = TRUE)
141+
expect_match(lines[8L], "^#' GPL-3$", perl = TRUE)
131142
})
132143

133144
test_that("overwrite = TRUE replaces existing zzz.R file", {
134-
tmp <- tempfile("pkg")
135-
dir.create(tmp)
136-
on.exit(unlink(tmp, recursive = TRUE))
145+
tmp <- withr::local_tempdir()
146+
local_mocked_bindings(
147+
proj_set = function(...) NULL,
148+
use_package = function(...) NULL,
149+
.package = "usethis"
150+
)
137151

138152
writeLines(
139153
c(
@@ -151,13 +165,16 @@ test_that("overwrite = TRUE replaces existing zzz.R file", {
151165
result <- use_zzz(path = tmp, overwrite = TRUE)
152166

153167
lines <- readLines(result, warn = FALSE)
154-
expect_match(lines[1L], "#' @title My Package", fixed = TRUE)
168+
expect_match(lines[3L], "#' @title My Package", fixed = TRUE)
155169
})
156170

157171
test_that("custom file_name is respected", {
158-
tmp <- tempfile("pkg")
159-
dir.create(tmp)
160-
on.exit(unlink(tmp, recursive = TRUE))
172+
tmp <- withr::local_tempdir()
173+
local_mocked_bindings(
174+
proj_set = function(...) NULL,
175+
use_package = function(...) NULL,
176+
.package = "usethis"
177+
)
161178

162179
writeLines(
163180
c(
@@ -177,9 +194,12 @@ test_that("custom file_name is respected", {
177194
})
178195

179196
test_that("returns invisible file path", {
180-
tmp <- tempfile("pkg")
181-
dir.create(tmp)
182-
on.exit(unlink(tmp, recursive = TRUE))
197+
tmp <- withr::local_tempdir()
198+
local_mocked_bindings(
199+
proj_set = function(...) NULL,
200+
use_package = function(...) NULL,
201+
.package = "usethis"
202+
)
183203

184204
writeLines(
185205
c(
@@ -199,9 +219,12 @@ test_that("returns invisible file path", {
199219
})
200220

201221
test_that("creates R/ directory if missing", {
202-
tmp <- tempfile("pkg")
203-
dir.create(tmp)
204-
on.exit(unlink(tmp, recursive = TRUE))
222+
tmp <- withr::local_tempdir()
223+
local_mocked_bindings(
224+
proj_set = function(...) NULL,
225+
use_package = function(...) NULL,
226+
.package = "usethis"
227+
)
205228

206229
writeLines(
207230
c(

0 commit comments

Comments
 (0)