-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest-optional_package.R
33 lines (30 loc) · 1.18 KB
/
test-optional_package.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
test_that("optional_package dependency test", {
fold <- system.file("extdata", "messy", package = "tidycells", mustWork = TRUE)
dm <- tibble::tibble(fn = list.files(fold, full.names = TRUE))
dm <- dm %>%
dplyr::mutate(original = dm$fn %>%
purrr::map_chr(~ basename(.x) %>%
stringr::str_split("\\.") %>%
purrr::map_chr(1)))
# both option for csv must result in same output (on test data at least)
if (is_available("readr")) {
d1 <- read_cells(dm$fn[dm$original == "csv"])
not_available("readr")
d2 <- read_cells(dm$fn[dm$original == "csv"])
not_available()
expect_equal(d1, d2)
}
# both option for xls must result in same output (on test data at least)
if (is_available("xlsx") & is_available("readxl")) {
d1 <- read_cells(dm$fn[dm$original == "xls"])
not_available("xlsx")
expect_message(d2 <- read_cells(dm$fn[dm$original == "xls"]), "readxl")
expect_equal(d1, d2)
not_available(c("readxl", "docxtractr"))
not_available("cli")
expect_output(possible_to_support(), "readxl")
expect_output(possible_to_support(), "docxtractr")
expect_null(read_cells(dm$fn[dm$original == "xls"]))
not_available()
}
})