Skip to content

Commit c3a9bbd

Browse files
committed
fix tests
1 parent ea01ee3 commit c3a9bbd

4 files changed

Lines changed: 39 additions & 10 deletions

File tree

R/java_build_env.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,22 @@ set_java_build_env_vars <- function(java_home, quiet = FALSE) {
173173
# Construct and set LIBS for the linker
174174
r_cmd_path <- file.path(R.home("bin"), "R")
175175
r_libs <- tryCatch(
176-
system2(r_cmd_path, "CMD config LIBS", stdout = TRUE, stderr = TRUE),
176+
system2(
177+
r_cmd_path,
178+
"CMD config LIBS",
179+
stdout = TRUE,
180+
stderr = TRUE
181+
),
177182
warning = function(w) "",
178183
error = function(e) ""
179184
)
180185
r_ldflags <- tryCatch(
181-
system2(r_cmd_path, "CMD config LDFLAGS", stdout = TRUE, stderr = TRUE),
186+
system2(
187+
r_cmd_path,
188+
"CMD config LDFLAGS",
189+
stdout = TRUE,
190+
stderr = TRUE
191+
),
182192
warning = function(w) "",
183193
error = function(e) ""
184194
)
@@ -255,7 +265,12 @@ set_java_build_env_vars <- function(java_home, quiet = FALSE) {
255265
# Set LDFLAGS for the JRI compilation step's configure script
256266
r_cmd_path <- file.path(R.home("bin"), "R")
257267
r_ldflags <- tryCatch(
258-
system2(r_cmd_path, "CMD config LDFLAGS", stdout = TRUE, stderr = TRUE),
268+
system2(
269+
r_cmd_path,
270+
"CMD config LDFLAGS",
271+
stdout = TRUE,
272+
stderr = TRUE
273+
),
259274
warning = function(w) "",
260275
error = function(e) ""
261276
)

R/java_find.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@
133133

134134
# 4. Validation & Cleaning
135135
# Normalize first to ensure unique() handles backslash/forward-slash duplicates
136-
candidates <- normalizePath(candidates, winslash = "/", mustWork = FALSE)
136+
candidates <- suppressWarnings(normalizePath(
137+
candidates,
138+
winslash = "/",
139+
mustWork = FALSE
140+
))
137141
candidates <- unique(candidates)
138142

139143
# Filter out rJavaEnv cache paths - we only want true system installations

R/mock_bindings.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# NULL bindings to allow mocking base functions in tests.
2+
# This file is only used to create entries in the package namespace
3+
# so that testthat::local_mocked_bindings can replace them.
4+
# See: https://testthat.r-lib.org/reference/local_mocked_bindings.html
5+
6+
Sys.info <- NULL
7+
file.exists <- NULL
8+
system2 <- NULL
9+
dyn.load <- NULL
10+
dirname <- NULL

tests/testthat/test-java_build_env_extra.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ test_that("set_java_build_env_vars sets JAVA_HOME and PATH", {
145145
# Mock file system operations for Linux-specific code
146146
local_mocked_bindings(
147147
Sys.info = function() c(sysname = "Darwin"),
148-
.package = "base"
148+
.package = "rJavaEnv"
149149
)
150150

151151
# Call the function with a temporary PATH
@@ -182,12 +182,12 @@ test_that("set_java_build_env_vars sets JAVAH when available", {
182182
file.exists = function(x) {
183183
if (x == javah_path) TRUE else FALSE
184184
},
185-
.package = "base"
185+
.package = "rJavaEnv"
186186
)
187187

188188
local_mocked_bindings(
189189
Sys.info = function() c(sysname = "Darwin"),
190-
.package = "base"
190+
.package = "rJavaEnv"
191191
)
192192

193193
withr::with_envvar(c("PATH" = "/usr/bin"), {
@@ -216,12 +216,12 @@ test_that("set_java_build_env_vars handles missing javah", {
216216
# Mock file.exists to say javah doesn't exist
217217
local_mocked_bindings(
218218
file.exists = function(x) FALSE,
219-
.package = "base"
219+
.package = "rJavaEnv"
220220
)
221221

222222
local_mocked_bindings(
223223
Sys.info = function() c(sysname = "Darwin"),
224-
.package = "base"
224+
.package = "rJavaEnv"
225225
)
226226

227227
withr::with_envvar(c("PATH" = "/usr/bin"), {
@@ -243,7 +243,7 @@ test_that("set_java_build_env_vars sets Linux-specific variables", {
243243

244244
local_mocked_bindings(
245245
Sys.info = function() c(sysname = "Linux"),
246-
.package = "base"
246+
.package = "rJavaEnv"
247247
)
248248

249249
local_mocked_bindings(

0 commit comments

Comments
 (0)