[mirror] Opinionated R package quickstart
0
fork

Configure Feed

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

Big workflow check

VisruthSK ebeb1e9e 44f2cf4b

+236
+236
tests/testthat/test-workflow.R
··· 1 + test_that("bootstrapper end-to-end workflow creates expected repo files", { 2 + tmp <- tempfile("bootstrapper-workflow-") 3 + dir.create(tmp) 4 + old <- setwd(tmp) 5 + on.exit(setwd(old), add = TRUE) 6 + 7 + pkg <- "demoPkg" 8 + fields <- list("Package" = pkg) 9 + github_private <- NULL 10 + action_calls <- list() 11 + 12 + testthat::local_mocked_bindings( 13 + create_package = function(path, fields, ...) { 14 + expect_identical(path, pkg) 15 + expect_identical(fields, list("Package" = pkg)) 16 + expect_identical(list(...), list(open = FALSE)) 17 + 18 + fs::dir_create(path) 19 + setwd(path) 20 + writeLines( 21 + c("^.*\\.Rproj$", "^\\.Rproj\\.user$", "README\\.Rmd"), 22 + ".Rbuildignore" 23 + ) 24 + writeLines(c("Package: demoPkg", "Version: 0.0.0.9000"), "DESCRIPTION") 25 + writeLines("project", "demoPkg.Rproj") 26 + fs::dir_create(fs::path(".git", "hooks")) 27 + NULL 28 + }, 29 + use_github = function(private) { 30 + github_private <<- private 31 + writeLines( 32 + c( 33 + "[remote \"origin\"]", 34 + "\turl = git@github.com:example/demoPkg.git" 35 + ), 36 + fs::path(".git", "config") 37 + ) 38 + NULL 39 + }, 40 + use_testthat = function() { 41 + fs::dir_create(fs::path("tests", "testthat")) 42 + writeLines( 43 + "testthat::test_check(\"demoPkg\")", 44 + fs::path("tests", "testthat.R") 45 + ) 46 + NULL 47 + }, 48 + use_readme_md = function(open = FALSE) { 49 + expect_false(open) 50 + writeLines("# demoPkg", "README.md") 51 + NULL 52 + }, 53 + use_news_md = function(open = FALSE) { 54 + expect_false(open) 55 + writeLines("demoPkg (development version)", "NEWS.md") 56 + NULL 57 + }, 58 + use_github_action = function(...) { 59 + args <- list(...) 60 + action_calls <<- c(action_calls, list(args)) 61 + fs::dir_create(fs::path(".github", "workflows")) 62 + 63 + if (!is.null(args$url)) { 64 + writeLines( 65 + c( 66 + "name: format-suggest", 67 + "steps:", 68 + " - uses: actions/checkout@v4" 69 + ), 70 + fs::path(".github", "workflows", "format-suggest.yaml") 71 + ) 72 + return(invisible(NULL)) 73 + } 74 + 75 + if (identical(args[[1]], "check-standard")) { 76 + writeLines( 77 + c( 78 + "name: check", 79 + "steps:", 80 + " - uses: actions/checkout@v4", 81 + " - uses: actions/upload-artifact@v4", 82 + " - uses: JamesIves/github-pages-deploy-action@v4.5.0" 83 + ), 84 + fs::path(".github", "workflows", "check-standard.yaml") 85 + ) 86 + return(invisible(NULL)) 87 + } 88 + 89 + if (identical(args[[1]], "test-coverage")) { 90 + writeLines( 91 + c( 92 + "name: coverage", 93 + "permissions: read-all", 94 + "steps:", 95 + " - token: ${{ secrets.CODECOV_TOKEN }}" 96 + ), 97 + fs::path(".github", "workflows", "test-coverage.yaml") 98 + ) 99 + return(invisible(NULL)) 100 + } 101 + 102 + NULL 103 + }, 104 + use_pkgdown_github_pages = function() NULL, 105 + use_spell_check = function(error = FALSE) { 106 + expect_true(error) 107 + NULL 108 + }, 109 + use_air = function() { 110 + writeLines("[format]", "air.toml") 111 + NULL 112 + }, 113 + use_tidy_description = function() NULL, 114 + use_build_ignore = function(path, ...) { 115 + writeLines( 116 + c(readLines(".Rbuildignore", warn = FALSE), path), 117 + ".Rbuildignore" 118 + ) 119 + NULL 120 + }, 121 + .package = "usethis" 122 + ) 123 + 124 + testthat::local_mocked_bindings( 125 + use_license = function() { 126 + writeLines("MIT License", "LICENSE.md") 127 + NULL 128 + }, 129 + try_air_jarl_format = function() { 130 + invisible(c(air = TRUE, jarl = TRUE)) 131 + }, 132 + .package = "bootstrapper" 133 + ) 134 + 135 + expect_null( 136 + bootstrapper::bootstrapper( 137 + path = pkg, 138 + fields = fields, 139 + private = TRUE, 140 + setup_AGENTS = TRUE, 141 + open = FALSE 142 + ) 143 + ) 144 + 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")) 149 + 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") 165 + ) 166 + for (f in expected_files) { 167 + expect_true(file.exists(f), info = f) 168 + } 169 + 170 + rbuildignore <- readLines(".Rbuildignore", warn = FALSE) 171 + expect_false(any(grepl("\\.Rproj", rbuildignore))) 172 + expect_true("AGENTS.md" %in% rbuildignore) 173 + 174 + news <- readLines("NEWS.md", warn = FALSE) 175 + expect_true(any(grepl("0.0.0.9000", news, fixed = TRUE))) 176 + 177 + check_standard <- readLines( 178 + fs::path(".github", "workflows", "check-standard.yaml"), 179 + warn = FALSE 180 + ) 181 + expect_true(any(grepl("actions/checkout@v6", check_standard, fixed = TRUE))) 182 + expect_true(any(grepl( 183 + "actions/upload-artifact@v6", 184 + check_standard, 185 + fixed = TRUE 186 + ))) 187 + expect_true(any(grepl( 188 + "JamesIves/github-pages-deploy-action@v4", 189 + check_standard, 190 + fixed = TRUE 191 + ))) 192 + 193 + coverage <- readLines( 194 + fs::path(".github", "workflows", "test-coverage.yaml"), 195 + warn = FALSE 196 + ) 197 + expect_true(any(grepl("use_oidc: true", coverage, fixed = TRUE))) 198 + expect_true(any(grepl("id-token: write", coverage, fixed = TRUE))) 199 + expect_false(any(grepl("CODECOV_TOKEN", coverage, fixed = TRUE))) 200 + 201 + expect_identical( 202 + readLines(fs::path(".github", "dependabot.yml"), warn = FALSE), 203 + readLines( 204 + fs::path_package("bootstrapper", "templates", "dependabot.yml"), 205 + warn = FALSE 206 + ) 207 + ) 208 + expect_identical( 209 + readLines("AGENTS.md", warn = FALSE), 210 + readLines( 211 + fs::path_package("bootstrapper", "templates", "AGENTS.md"), 212 + warn = FALSE 213 + ) 214 + ) 215 + expect_identical( 216 + readLines(fs::path("tests", "jarl.toml"), warn = FALSE), 217 + readLines( 218 + fs::path_package("bootstrapper", "templates", "jarl.toml"), 219 + warn = FALSE 220 + ) 221 + ) 222 + expect_identical( 223 + readLines(fs::path(".vscode", "extensions.json"), warn = FALSE), 224 + readLines( 225 + fs::path_package("bootstrapper", "templates", "extensions.json"), 226 + warn = FALSE 227 + ) 228 + ) 229 + expect_identical( 230 + readLines(fs::path(".git", "hooks", "pre-commit"), warn = FALSE), 231 + readLines( 232 + fs::path_package("bootstrapper", "templates", "pre-commit"), 233 + warn = FALSE 234 + ) 235 + ) 236 + })