Skip to content

Commit

Permalink
test: testing golem creation + fixing removecomment issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinFay committed Sep 6, 2024
1 parent 544a7b7 commit 7cd0148
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ remove_comments <- function(file) {
lines_without_comment <- append(
lines_without_comment,
gsub(
"(\\s*#+[^'@].*$| #+[^#].*$)",
"(\\s*#+[^'@].*$| #+[^#].*$|^#+$)",
"",
line
)
Expand Down
101 changes: 99 additions & 2 deletions tests/testthat/test-create_golem.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,62 @@ is_properly_populated_golem <- function(path) {
sort(actual_files)
)
}
test_that("create_golem works", {
dir <- tempfile(pattern = "golemcreategolem")
withr::with_options(
c("usethis.quiet" = TRUE),
{
dir <- create_golem(
dir,
open = FALSE,
package_name = "testpkg"
)
}
)
expect_true(
is_properly_populated_golem(
dir
)
)
unlink(
dir,
TRUE,
TRUE
)
})

test_that("create_golem works", {{ dir <- tempfile(pattern = "golemcreategolem")
test_that("create_golem fails if the dir already exists", {
dir <- tempfile(pattern = "golemcreategolemfail")
dir.create(dir)
expect_error({
withr::with_options(
c("usethis.quiet" = TRUE),
{
dir <- create_golem(
dir,
open = FALSE,
package_name = "testpkg"
)
}
)
})

unlink(
dir,
TRUE,
TRUE
)
})

test_that("create_golem override if the dir already exists and overwrite is set to TRUE", {
dir <- tempfile(pattern = "golemcreategolemfail")
dir.create(dir)
withr::with_options(
c("usethis.quiet" = TRUE),
{
dir <- create_golem(
dir,
overwrite = TRUE,
open = FALSE,
package_name = "testpkg"
)
Expand All @@ -44,7 +93,55 @@ test_that("create_golem works", {{ dir <- tempfile(pattern = "golemcreategolem")
dir,
TRUE,
TRUE
) }})
)
})

test_that("create_golem can remove comments", {
dir <- tempfile(pattern = "golemcreategolemfail")

withr::with_options(
c("usethis.quiet" = TRUE),
{
dir <- create_golem(
dir,
without_comments = TRUE,
open = FALSE,
package_name = "testpkg"
)
}
)
expect_equal(
length(
readLines(
file.path(
dir,
"dev",
"01_start.R"
)
)
),
31
)
expect_false(
any(
grepl(
"^# *",
readLines(
file.path(
dir,
"dev",
"01_start.R"
)
)
)
)
)
unlink(
dir,
TRUE,
TRUE
)
})

test_that("create_golem_gui works", {
testthat::with_mocked_bindings(
Expand Down

0 comments on commit 7cd0148

Please sign in to comment.