Skip to content

Commit

Permalink
with tests for server utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinFay committed Dec 24, 2021
1 parent 27b70a5 commit 89daf52
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 deletions.
22 changes: 17 additions & 5 deletions R/use_utils.R
Expand Up @@ -88,17 +88,17 @@ use_utils_server <- function(pkg = get_golem_wd(),
open_file = FALSE
)
} else {
# use_utils_test_server()
use_utils_test_server()
}
}
}
}

#' @export
#' @rdname utils_files
use_utils_test_ui <- function(pkg = get_golem_wd()) {
use_utils_test_ <- function(pkg = get_golem_wd(),
type = c("ui", "server")) {
type <- match.arg(type)
added <- use_utils(
file_name = "test-golem_utils_server.R",
file_name = sprintf("test-golem_utils_%s.R", type),
folder_name = "tests/testthat",
pkg = pkg
)
Expand All @@ -108,6 +108,18 @@ use_utils_test_ui <- function(pkg = get_golem_wd()) {
}
}

#' @export
#' @rdname utils_files
use_utils_test_ui <- function(pkg = get_golem_wd()) {
use_utils_test_(pkg, "ui")
}
#' @export
#' @rdname utils_files
use_utils_test_server <- function(pkg = get_golem_wd()) {
use_utils_test_(pkg, "server")
}


#' @importFrom fs file_copy path_abs path_file
use_utils <- function(file_name,
folder_name,
Expand Down
60 changes: 60 additions & 0 deletions inst/utils/test-golem_utils_server.R
@@ -0,0 +1,60 @@
test_that("not_in works", {
expect_true(1 %not_in% 2:10)
expect_false(1 %not_in% 1:10)
})

test_that("not_null works", {
expect_true(not_null(1))
expect_false(not_null(NULL))
})

test_that("not_na works", {
expect_true(not_na(1))
expect_false(not_na(NA))
})

test_that("drop_nulls works", {
expect_equal(
drop_nulls(
list(x = NULL, y = 2)
),
list(y = 2)
)
})

test_that("%||% works", {
expect_equal(
NULL %||% 1,
1
)
expect_equal(
2 %||% 1,
2
)
})

test_that("%NA% works", {
expect_equal(
NA %NA% 1,
1
)
expect_equal(
2 %NA% 1,
2
)
})

test_that("rv and rvtl work", {
x <- rv(x = 12)
expect_s3_class(
x,
"reactivevalues"
)
x <- rvtl(rv(x = 12))
expect_true(
inherits(
x,
"list"
)
)
})
23 changes: 17 additions & 6 deletions tests/testthat/test-use_utils.R
@@ -1,16 +1,27 @@
test_that("test use_utils_ui",{
with_dir(pkg,{
test_that("test use_utils_ui", {
with_dir(pkg, {
remove_file("R/golem_utils_ui.R")
use_utils_ui()
expect_exists("R/golem_utils_ui.R")
remove_file("R/golem_utils_ui.R")

remove_file("R/golem_utils_ui.R")
use_utils_ui(with_test = TRUE)
expect_exists("R/golem_utils_ui.R")
expect_exists("tests/testthat/test-golem_utils_ui.R")
})
})

test_that("test use_utils_server",{
with_dir(pkg,{
test_that("test use_utils_server", {
with_dir(pkg, {
remove_file("R/golem_utils_server.R")
use_utils_server()
expect_exists("R/golem_utils_server.R")
})
})
remove_file("R/golem_utils_server.R")

remove_file("R/golem_utils_server.R")
use_utils_server(with_test = TRUE)
expect_exists("R/golem_utils_server.R")
expect_exists("tests/testthat/test-golem_utils_server.R")
})
})

0 comments on commit 89daf52

Please sign in to comment.