[mirror] Opinionated R package quickstart
0
fork

Configure Feed

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

Split up generated test file

VisruthSK 406bedf9 ebeb1e9e

+68 -38
+68 -38
tests/testthat/test-workflow.R
··· 1 - test_that("bootstrapper end-to-end workflow creates expected repo files", { 1 + run_workflow_fixture <- function(setup_AGENTS = TRUE) { 2 2 tmp <- tempfile("bootstrapper-workflow-") 3 3 dir.create(tmp) 4 4 old <- setwd(tmp) ··· 6 6 7 7 pkg <- "demoPkg" 8 8 fields <- list("Package" = pkg) 9 - github_private <- NULL 10 - action_calls <- list() 9 + state <- new.env(parent = emptyenv()) 10 + state$github_private <- NULL 11 + state$action_calls <- list() 11 12 12 13 testthat::local_mocked_bindings( 13 14 create_package = function(path, fields, ...) { ··· 27 28 NULL 28 29 }, 29 30 use_github = function(private) { 30 - github_private <<- private 31 + state$github_private <- private 31 32 writeLines( 32 33 c( 33 34 "[remote \"origin\"]", ··· 57 58 }, 58 59 use_github_action = function(...) { 59 60 args <- list(...) 60 - action_calls <<- c(action_calls, list(args)) 61 + state$action_calls <- c(state$action_calls, list(args)) 61 62 fs::dir_create(fs::path(".github", "workflows")) 62 63 63 64 if (!is.null(args$url)) { ··· 137 138 path = pkg, 138 139 fields = fields, 139 140 private = TRUE, 140 - setup_AGENTS = TRUE, 141 + setup_AGENTS = setup_AGENTS, 141 142 open = FALSE 142 143 ) 143 144 ) 144 145 145 - expect_identical(basename(getwd()), pkg) 146 - expect_true(isTRUE(github_private)) 147 - expect_length(action_calls, 3) 148 - expect_false(file.exists("demoPkg.Rproj")) 146 + list( 147 + pkg_path = fs::path(tmp, pkg), 148 + github_private = state$github_private, 149 + action_calls = state$action_calls 150 + ) 151 + } 152 + 153 + file_in_pkg <- function(fixture, ...) { 154 + fs::path(fixture$pkg_path, ...) 155 + } 156 + 157 + test_that("workflow step: create_package creates git-backed package skeleton", { 158 + fixture <- run_workflow_fixture() 159 + 160 + expect_true(isTRUE(fixture$github_private)) 161 + expect_true(file.exists(file_in_pkg(fixture, "DESCRIPTION"))) 162 + expect_true(file.exists(file_in_pkg(fixture, "LICENSE.md"))) 163 + expect_true(file.exists(file_in_pkg(fixture, ".git", "config"))) 164 + expect_false(file.exists(file_in_pkg(fixture, "demoPkg.Rproj"))) 149 165 150 - expected_files <- c( 151 - "DESCRIPTION", 152 - "README.md", 153 - "NEWS.md", 154 - "LICENSE.md", 155 - fs::path("tests", "testthat.R"), 156 - fs::path("tests", "jarl.toml"), 157 - fs::path(".vscode", "extensions.json"), 158 - fs::path(".github", "dependabot.yml"), 159 - fs::path(".github", "workflows", "check-standard.yaml"), 160 - fs::path(".github", "workflows", "test-coverage.yaml"), 161 - fs::path(".github", "workflows", "format-suggest.yaml"), 162 - "AGENTS.md", 163 - fs::path(".git", "config"), 164 - fs::path(".git", "hooks", "pre-commit") 166 + rbuildignore <- readLines(file_in_pkg(fixture, ".Rbuildignore"), warn = FALSE) 167 + expect_false(any(grepl("\\.Rproj", rbuildignore))) 168 + }) 169 + 170 + test_that("workflow step: pkg_setup creates core package files", { 171 + fixture <- run_workflow_fixture() 172 + 173 + expected_core_files <- c( 174 + file_in_pkg(fixture, "README.md"), 175 + file_in_pkg(fixture, "NEWS.md"), 176 + file_in_pkg(fixture, "tests", "testthat.R") 165 177 ) 166 - for (f in expected_files) { 178 + for (f in expected_core_files) { 167 179 expect_true(file.exists(f), info = f) 168 180 } 169 181 170 - rbuildignore <- readLines(".Rbuildignore", warn = FALSE) 171 - expect_false(any(grepl("\\.Rproj", rbuildignore))) 172 - expect_true("AGENTS.md" %in% rbuildignore) 182 + news <- readLines(file_in_pkg(fixture, "NEWS.md"), warn = FALSE) 183 + expect_true(any(grepl("0.0.0.9000", news, fixed = TRUE))) 184 + }) 185 + 186 + test_that("workflow step: setup_gha writes and rewrites workflow files", { 187 + fixture <- run_workflow_fixture() 173 188 174 - news <- readLines("NEWS.md", warn = FALSE) 175 - expect_true(any(grepl("0.0.0.9000", news, fixed = TRUE))) 189 + expect_length(fixture$action_calls, 3) 190 + expect_identical(fixture$action_calls[[1]][[1]], "check-standard") 191 + expect_identical(fixture$action_calls[[2]][[1]], "test-coverage") 192 + expect_identical( 193 + fixture$action_calls[[3]]$url, 194 + "https://github.com/visruthsk/bootstrapper/blob/main/.github/workflows/format-suggest.yaml" 195 + ) 176 196 177 197 check_standard <- readLines( 178 - fs::path(".github", "workflows", "check-standard.yaml"), 198 + file_in_pkg(fixture, ".github", "workflows", "check-standard.yaml"), 179 199 warn = FALSE 180 200 ) 181 201 expect_true(any(grepl("actions/checkout@v6", check_standard, fixed = TRUE))) ··· 191 211 ))) 192 212 193 213 coverage <- readLines( 194 - fs::path(".github", "workflows", "test-coverage.yaml"), 214 + file_in_pkg(fixture, ".github", "workflows", "test-coverage.yaml"), 195 215 warn = FALSE 196 216 ) 197 217 expect_true(any(grepl("use_oidc: true", coverage, fixed = TRUE))) 198 218 expect_true(any(grepl("id-token: write", coverage, fixed = TRUE))) 199 219 expect_false(any(grepl("CODECOV_TOKEN", coverage, fixed = TRUE))) 220 + }) 221 + 222 + test_that("workflow step: setup templates are copied to expected locations", { 223 + fixture <- run_workflow_fixture(setup_AGENTS = TRUE) 200 224 201 225 expect_identical( 202 - readLines(fs::path(".github", "dependabot.yml"), warn = FALSE), 226 + readLines(file_in_pkg(fixture, ".github", "dependabot.yml"), warn = FALSE), 203 227 readLines( 204 228 fs::path_package("bootstrapper", "templates", "dependabot.yml"), 205 229 warn = FALSE 206 230 ) 207 231 ) 208 232 expect_identical( 209 - readLines("AGENTS.md", warn = FALSE), 233 + readLines(file_in_pkg(fixture, "AGENTS.md"), warn = FALSE), 210 234 readLines( 211 235 fs::path_package("bootstrapper", "templates", "AGENTS.md"), 212 236 warn = FALSE 213 237 ) 214 238 ) 215 239 expect_identical( 216 - readLines(fs::path("tests", "jarl.toml"), warn = FALSE), 240 + readLines(file_in_pkg(fixture, "tests", "jarl.toml"), warn = FALSE), 217 241 readLines( 218 242 fs::path_package("bootstrapper", "templates", "jarl.toml"), 219 243 warn = FALSE 220 244 ) 221 245 ) 222 246 expect_identical( 223 - readLines(fs::path(".vscode", "extensions.json"), warn = FALSE), 247 + readLines(file_in_pkg(fixture, ".vscode", "extensions.json"), warn = FALSE), 224 248 readLines( 225 249 fs::path_package("bootstrapper", "templates", "extensions.json"), 226 250 warn = FALSE 227 251 ) 228 252 ) 229 253 expect_identical( 230 - readLines(fs::path(".git", "hooks", "pre-commit"), warn = FALSE), 254 + readLines( 255 + file_in_pkg(fixture, ".git", "hooks", "pre-commit"), 256 + warn = FALSE 257 + ), 231 258 readLines( 232 259 fs::path_package("bootstrapper", "templates", "pre-commit"), 233 260 warn = FALSE 234 261 ) 235 262 ) 263 + 264 + rbuildignore <- readLines(file_in_pkg(fixture, ".Rbuildignore"), warn = FALSE) 265 + expect_true("AGENTS.md" %in% rbuildignore) 236 266 })