[mirror] Opinionated R package quickstart
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Generated some tests

VisruthSK 509b9f55 5aaa97f5

+264 -3
+2
DESCRIPTION
··· 8 8 GHA, suggested extensions, etc. 9 9 License: GPL (>= 3) 10 10 URL: https://visruthsk.github.io/bootstrapper/ 11 + Depends: 12 + R (>= 4.2.0) 11 13 Imports: 12 14 fs, 13 15 usethis,
+1 -1
NEWS.md
··· 1 - # bootstrapper (development version) 1 + # bootstrapper 0.0.0.9000 2 2 3 3 * Initial CRAN submission.
+6
R/bootstrapper.R
··· 87 87 ) 88 88 usethis::use_readme_md(open = FALSE) 89 89 usethis::use_news_md(open = FALSE) 90 + # TODO: check if this is necessary to make r cmd check pass. 91 + find_replace_in_file( 92 + "(development version)", 93 + "0.0.0.9000", 94 + fs::path("NEWS.md") 95 + ) 90 96 91 97 # GitHub Actions setup 92 98 usethis::use_github_action("check-standard", badge = TRUE)
+2 -2
R/utils.R
··· 7 7 x <- readLines(file, warn = FALSE) 8 8 if (any(grepl(from, x, fixed = fixed))) { 9 9 writeLines(gsub(from, to, x, fixed = fixed), file) 10 - TRUE 10 + invisible(TRUE) 11 11 } else { 12 - FALSE 12 + invisible(FALSE) 13 13 } 14 14 } 15 15
+6
inst/WORDLIST
··· 1 1 CMD 2 2 Codecov 3 + GHA 4 + Kandali 5 + ORCID 6 + Quickstart 7 + README 8 + Srimath
+247
tests/testthat/test-bootstrapper.R
··· 1 + test_that("bootstrapper orchestrates package creation and setup", { 2 + calls <- character() 3 + 4 + testthat::local_mocked_bindings( 5 + create_package = function(path, fields, private, ...) { 6 + calls <<- c(calls, "create_package") 7 + expect_identical(path, "pkg") 8 + expect_identical(fields, list(name = "value")) 9 + expect_false(private) 10 + expect_identical(list(...), list(open = FALSE)) 11 + NULL 12 + }, 13 + pkg_setup = function() { 14 + calls <<- c(calls, "pkg_setup") 15 + NULL 16 + }, 17 + .package = "bootstrapper" 18 + ) 19 + 20 + expect_null( 21 + bootstrapper::bootstrapper( 22 + path = "pkg", 23 + fields = list(name = "value"), 24 + private = FALSE, 25 + open = FALSE 26 + ) 27 + ) 28 + expect_identical(calls, c("create_package", "pkg_setup")) 29 + }) 30 + 31 + test_that("create_package delegates to usethis and cleans local files", { 32 + tmp <- tempfile("bootstrapper-") 33 + dir.create(tmp) 34 + old <- setwd(tmp) 35 + on.exit(setwd(old), add = TRUE) 36 + 37 + writeLines( 38 + c("^.*\\.Rproj$", "^\\.Rproj\\.user$", "keep", ""), 39 + ".Rbuildignore" 40 + ) 41 + writeLines("project", "pkg.Rproj") 42 + 43 + fields <- list("Authors@R" = utils::person("Jane", "Doe")) 44 + seen <- list() 45 + 46 + testthat::local_mocked_bindings( 47 + create_package = function(path, fields, ...) { 48 + seen$create <<- list(path = path, fields = fields, dots = list(...)) 49 + NULL 50 + }, 51 + use_github = function(private) { 52 + seen$private <<- private 53 + NULL 54 + }, 55 + .package = "usethis" 56 + ) 57 + 58 + testthat::local_mocked_bindings( 59 + use_license = function() { 60 + seen$license <<- TRUE 61 + NULL 62 + }, 63 + .package = "bootstrapper" 64 + ) 65 + 66 + expect_null( 67 + bootstrapper::create_package( 68 + path = "pkg", 69 + fields = fields, 70 + private = FALSE, 71 + open = FALSE 72 + ) 73 + ) 74 + 75 + expect_identical(seen$create$path, "pkg") 76 + expect_identical(seen$create$fields, fields) 77 + expect_identical(seen$create$dots, list(open = FALSE)) 78 + expect_false(file.exists("pkg.Rproj")) 79 + expect_identical(readLines(".Rbuildignore", warn = FALSE), "keep") 80 + expect_false(seen$private) 81 + expect_true(isTRUE(seen$license)) 82 + }) 83 + 84 + test_that("pkg_setup runs expected usethis and helper calls", { 85 + calls <- list( 86 + actions = character(), 87 + github_actions = list(), 88 + writes = character(), 89 + replacements = character() 90 + ) 91 + 92 + testthat::local_mocked_bindings( 93 + use_testthat = function() { 94 + calls$actions <<- c(calls$actions, "testthat") 95 + }, 96 + use_readme_md = function(open = FALSE) { 97 + calls$actions <<- c(calls$actions, paste0("readme:", open)) 98 + }, 99 + use_news_md = function(open = FALSE) { 100 + calls$actions <<- c(calls$actions, paste0("news:", open)) 101 + }, 102 + use_github_action = function(...) { 103 + calls$github_actions <<- c(calls$github_actions, list(list(...))) 104 + }, 105 + use_pkgdown_github_pages = function() { 106 + calls$actions <<- c(calls$actions, "pkgdown") 107 + }, 108 + use_spell_check = function(error = FALSE) { 109 + calls$actions <<- c(calls$actions, paste0("spell:", error)) 110 + }, 111 + use_air = function() { 112 + calls$actions <<- c(calls$actions, "air") 113 + }, 114 + use_tidy_description = function() { 115 + calls$actions <<- c(calls$actions, "tidy_description") 116 + }, 117 + .package = "usethis" 118 + ) 119 + 120 + testthat::local_mocked_bindings( 121 + write_to_path = function(text, filepath) { 122 + calls$writes <<- c(calls$writes, filepath) 123 + NULL 124 + }, 125 + find_replace_in_gha = function(from, to) { 126 + calls$replacements <<- c( 127 + calls$replacements, 128 + paste(from, to, sep = " -> ") 129 + ) 130 + NULL 131 + }, 132 + .package = "bootstrapper" 133 + ) 134 + 135 + expect_null(bootstrapper::pkg_setup()) 136 + 137 + expect_true("testthat" %in% calls$actions) 138 + expect_true("readme:FALSE" %in% calls$actions) 139 + expect_true("news:FALSE" %in% calls$actions) 140 + expect_true("spell:TRUE" %in% calls$actions) 141 + expect_true("air" %in% calls$actions) 142 + expect_true("tidy_description" %in% calls$actions) 143 + 144 + expect_length(calls$github_actions, 3) 145 + expect_identical(calls$github_actions[[1]][[1]], "check-standard") 146 + expect_true(isTRUE(calls$github_actions[[1]]$badge)) 147 + expect_identical(calls$github_actions[[2]][[1]], "test-coverage") 148 + expect_identical( 149 + calls$github_actions[[3]]$url, 150 + "https://github.com/visruthsk/bootstrapper/blob/main/.github/workflows/format-suggest.yaml" 151 + ) 152 + 153 + expect_setequal( 154 + basename(calls$writes), 155 + c("dependabot.yml", "extensions.json", "jarl.toml") 156 + ) 157 + expect_identical( 158 + calls$replacements, 159 + c( 160 + "actions/checkout@v4 -> actions/checkout@v6", 161 + "JamesIves/github-pages-deploy-action@v4.5.0 -> JamesIves/github-pages-deploy-action@v4" 162 + ) 163 + ) 164 + }) 165 + 166 + test_that("pkg_setup rethrows a generic message when test setup fails", { 167 + readme_called <- FALSE 168 + 169 + testthat::local_mocked_bindings( 170 + use_testthat = function() stop("boom"), 171 + use_readme_md = function(open = FALSE) { 172 + readme_called <<- TRUE 173 + NULL 174 + }, 175 + .package = "usethis" 176 + ) 177 + 178 + expect_error( 179 + bootstrapper::pkg_setup(), 180 + "This doesn't appear to be a package" 181 + ) 182 + expect_false(readme_called) 183 + }) 184 + 185 + test_that("use_license warns and returns NULL in non-interactive mode", { 186 + messages <- character() 187 + 188 + testthat::local_mocked_bindings( 189 + ui_info = function(message, ...) { 190 + messages <<- c(messages, message) 191 + NULL 192 + }, 193 + ui_warn = function(message, ...) { 194 + messages <<- c(messages, message) 195 + NULL 196 + }, 197 + .package = "usethis" 198 + ) 199 + 200 + expect_null(bootstrapper::use_license()) 201 + expect_true(any(grepl("Select a license", messages, fixed = TRUE))) 202 + expect_true(any(grepl("No license selected", messages, fixed = TRUE))) 203 + }) 204 + 205 + test_that("file helpers create directories and replace text", { 206 + tmp <- tempfile("bootstrapper-helpers-") 207 + dir.create(tmp) 208 + old <- setwd(tmp) 209 + on.exit(setwd(old), add = TRUE) 210 + 211 + write_to_path <- getFromNamespace("write_to_path", "bootstrapper") 212 + find_replace_in_file <- getFromNamespace( 213 + "find_replace_in_file", 214 + "bootstrapper" 215 + ) 216 + find_replace_in_dir <- getFromNamespace("find_replace_in_dir", "bootstrapper") 217 + find_replace_in_gha <- getFromNamespace("find_replace_in_gha", "bootstrapper") 218 + 219 + write_to_path(c("alpha", "beta"), fs::path("nested", "file.txt")) 220 + expect_identical( 221 + readLines(fs::path("nested", "file.txt"), warn = FALSE), 222 + c("alpha", "beta") 223 + ) 224 + 225 + writeLines(c("alpha", "beta"), "one.txt") 226 + expect_true(find_replace_in_file("alpha", "ALPHA", "one.txt")) 227 + expect_identical(readLines("one.txt", warn = FALSE), c("ALPHA", "beta")) 228 + expect_false(find_replace_in_file("gamma", "GAMMA", "one.txt")) 229 + 230 + dir.create("sub") 231 + writeLines("token", fs::path("sub", "a.yaml")) 232 + writeLines("token", fs::path("sub", "b.txt")) 233 + find_replace_in_dir("token", "TOKEN", "sub", "\\.ya?ml$") 234 + expect_identical(readLines(fs::path("sub", "a.yaml"), warn = FALSE), "TOKEN") 235 + expect_identical(readLines(fs::path("sub", "b.txt"), warn = FALSE), "token") 236 + 237 + dir.create(fs::path(".github", "workflows"), recursive = TRUE) 238 + writeLines( 239 + "uses: actions/checkout@v4", 240 + fs::path(".github", "workflows", "check.yml") 241 + ) 242 + find_replace_in_gha("actions/checkout@v4", "actions/checkout@v6") 243 + expect_true(grepl( 244 + "checkout@v6", 245 + readLines(fs::path(".github", "workflows", "check.yml")) 246 + )) 247 + })