Skip to content

Commit ea01ee3

Browse files
committed
fix tests
1 parent 7637710 commit ea01ee3

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

tests/testthat/test-java_build_env_extra.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,6 @@ test_that("set_java_build_env_vars sets Linux-specific variables", {
254254
.package = "rJavaEnv"
255255
)
256256

257-
# Also need to mock some base functions that are called in the Linux block
258-
local_mocked_bindings(
259-
file.exists = function(x) TRUE,
260-
dirname = function(x) "/mock/java/home/lib/server",
261-
.package = "base"
262-
)
263-
264257
withr::with_envvar(c("LD_LIBRARY_PATH" = "/usr/lib"), {
265258
set_java_build_env_vars(java_home, quiet = TRUE)
266259

tests/testthat/test-java_find.R

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,7 @@ test_that("._java_find_system_cached returns cached result on second call", {
646646
skip_if(!identical(Sys.getenv("CI"), "true"), "Only run on CI")
647647

648648
# Reset cache for this test
649-
if (exists(".java_find_system_cache", envir = asNamespace("rJavaEnv"))) {
650-
assignInNamespace(".java_find_system_cache", NULL, ns = "rJavaEnv")
651-
}
649+
memoise::forget(rJavaEnv:::._java_find_system_cached)
652650

653651
call_count <- 0
654652
mock_scan_result <- data.frame(
@@ -677,26 +675,27 @@ test_that("._java_find_system_cached returns cached result on second call", {
677675
expect_equal(result1, result2)
678676
})
679677

680-
test_that("._java_find_system_cached respects .use_cache = FALSE", {
678+
test_that("java_find_system respects .use_cache = FALSE", {
681679
skip_on_cran()
682680
skip_if(!identical(Sys.getenv("CI"), "true"), "Only run on CI")
683681

684-
# Reset cache for this test
685-
if (exists(".java_find_system_cache", envir = asNamespace("rJavaEnv"))) {
686-
assignInNamespace(".java_find_system_cache", NULL, ns = "rJavaEnv")
687-
}
688-
689682
call_count <- 0
690683
local_mocked_bindings(
691684
._java_find_system_scan_impl = function(...) {
692685
call_count <<- call_count + 1
693-
data.frame(java_home = "/mock", major_version = "21", is_default = TRUE)
686+
data.frame(
687+
java_home = "/mock",
688+
version = "21",
689+
is_default = TRUE,
690+
stringsAsFactors = FALSE
691+
)
694692
},
695693
.package = "rJavaEnv"
696694
)
697695

698-
rJavaEnv:::._java_find_system_cached()
699-
rJavaEnv:::._java_find_system_cached()
696+
# Should call scan_impl every time when .use_cache = FALSE
697+
java_find_system(.use_cache = FALSE)
698+
java_find_system(.use_cache = FALSE)
700699

701-
expect_equal(call_count, 1) # First call scans, second call uses memoised result
700+
expect_equal(call_count, 2)
702701
})

0 commit comments

Comments
 (0)