@@ -49,8 +49,8 @@ test_that("quickr_r_cmd_config_value returns empty on command failure", {
4949 )
5050})
5151
52- test_that(" quickr_flang_path and quickr_prefer_flang are deterministic with stubs " , {
53- which <- function (x ) {
52+ test_that(" quickr_flang_path prefers flang-new " , {
53+ which_stub <- function (x ) {
5454 if (x == " flang-new" ) {
5555 " /tmp/flang-new"
5656 } else if (x == " flang" ) {
@@ -59,28 +59,28 @@ test_that("quickr_flang_path and quickr_prefer_flang are deterministic with stub
5959 " "
6060 }
6161 }
62- system2_stub <- function (command , args , stdout = TRUE , stderr = TRUE , ... ) {
63- " flang version"
64- }
6562
66- expect_identical( quickr ::: quickr_flang_path( which = which ), " /tmp/flang-new " )
63+ local_mocked_bindings( Sys. which = which_stub , .package = " base " )
6764
68- withr :: local_options(quickr.fortran_compiler = " auto" )
65+ expect_identical(quickr_flang_path(), " /tmp/flang-new" )
66+ })
6967
70- expect_true(quickr ::: quickr_prefer_flang(
71- sysname = " Darwin" ,
72- which = which ,
73- system2 = system2_stub
74- ))
75- expect_false(quickr ::: quickr_prefer_flang(sysname = " Linux" , which = which ))
68+ test_that(" flang probe helpers do not expose test-only process hooks" , {
69+ expect_false(" which" %in% names(formals(quickr_flang_path )))
70+ expect_false(" which" %in% names(formals(quickr_flang_available )))
71+ expect_false(" system2" %in% names(formals(quickr_flang_available )))
72+ expect_false(" which" %in% names(formals(quickr_prefer_flang )))
73+ expect_false(" system2" %in% names(formals(quickr_prefer_flang )))
74+ expect_false(" which" %in% names(formals(quickr ::: quickr_fcompiler_env )))
75+ expect_false(" system2" %in% names(formals(quickr ::: quickr_fcompiler_env )))
7676})
7777
7878test_that(" quickr_prefer_flang respects quickr.fortran_compiler" , {
7979 withr :: local_options(quickr.fortran_compiler = " flang" )
80- expect_true(quickr ::: quickr_prefer_flang(sysname = " Linux " ))
80+ expect_true(quickr_prefer_flang())
8181
8282 withr :: local_options(quickr.fortran_compiler = " gfortran" )
83- expect_false(quickr ::: quickr_prefer_flang(sysname = " Darwin " ))
83+ expect_false(quickr_prefer_flang())
8484})
8585
8686test_that(" quickr_default_fortran_makevars_lines relaxes gfortran cost model" , {
@@ -140,8 +140,6 @@ test_that("quickr_fcompiler_env writes Makevars when flang is usable", {
140140 file.create(flang )
141141 file.create(file.path(prefix , " lib" , " libflang_rt.runtime.dylib" ))
142142
143- which <- function (x ) if (x == " flang-new" ) flang else " "
144-
145143 cache_env <- environment(quickr ::: quickr_flang_runtime_flags )
146144 old_cache <- cache_env $ cache
147145 cache_env $ cache <- NULL
@@ -150,11 +148,15 @@ test_that("quickr_fcompiler_env writes Makevars when flang is usable", {
150148 build_dir <- file.path(temp , " build" )
151149 dir.create(build_dir )
152150
151+ local_mocked_bindings(
152+ Sys.which = function (x ) if (x == " flang-new" ) flang else " " ,
153+ system2 = function (... ) " " ,
154+ .package = " base"
155+ )
156+
153157 withr :: local_options(quickr.fortran_compiler = " flang" )
154158 env <- quickr ::: quickr_fcompiler_env(
155159 build_dir = build_dir ,
156- which = which ,
157- system2 = function (... ) " " ,
158160 sysname = " Darwin"
159161 )
160162 expect_true(startsWith(env , " R_MAKEVARS_USER=" ))
@@ -167,8 +169,6 @@ test_that("quickr_fcompiler_env writes Makevars for default gfortran flags", {
167169 withr :: local_options(quickr.fortran_compiler = " gfortran" )
168170 env <- quickr ::: quickr_fcompiler_env(
169171 build_dir = build_dir ,
170- which = function (cmd ) " " ,
171- system2 = function (... ) " " ,
172172 sysname = " Linux" ,
173173 config_value = function (name ) {
174174 if (identical(name , " FC" )) " gfortran -m64" else " "
@@ -186,12 +186,12 @@ test_that("quickr_fcompiler_env writes Makevars for default gfortran flags", {
186186test_that(" quickr_fcompiler_env errors when flang is explicitly requested but unavailable" , {
187187 build_dir <- withr :: local_tempdir()
188188
189+ local_mocked_bindings(Sys.which = function (cmd ) " " , .package = " base" )
190+
189191 withr :: local_options(quickr.fortran_compiler = " flang" )
190192 expect_error(
191193 quickr ::: quickr_fcompiler_env(
192- build_dir = build_dir ,
193- which = function (cmd ) " " ,
194- system2 = function (... ) structure(" " , status = 1L )
194+ build_dir = build_dir
195195 ),
196196 " configured to use flang" ,
197197 fixed = TRUE
@@ -202,10 +202,12 @@ test_that("quickr_flang_available returns unavailable when system2 fails", {
202202 which_stub <- function (x ) if (x == " flang-new" ) " /tmp/flang-new" else " "
203203 system2_fail <- function (... ) structure(" error" , status = 1L )
204204
205- result <- quickr ::: quickr_flang_available(
206- which = which_stub ,
207- system2 = system2_fail
205+ local_mocked_bindings(
206+ Sys.which = which_stub ,
207+ system2 = system2_fail ,
208+ .package = " base"
208209 )
210+ result <- quickr ::: quickr_flang_available()
209211 expect_identical(result $ path , " /tmp/flang-new" )
210212 expect_false(result $ available )
211213})
@@ -317,7 +319,7 @@ test_that("quickr_prefer_flang returns FALSE when flang_auto_disabled", {
317319 .package = " quickr"
318320 )
319321
320- expect_false(quickr ::: quickr_prefer_flang(sysname = " Darwin " ))
322+ expect_false(quickr_prefer_flang())
321323})
322324
323325test_that(" quickr_fcompiler_env handles flang unavailable for non-explicit request" , {
@@ -337,8 +339,6 @@ test_that("quickr_fcompiler_env handles flang unavailable for non-explicit reque
337339 # Should return character() since not explicit and flang unavailable
338340 result <- quickr ::: quickr_fcompiler_env(
339341 build_dir = build_dir ,
340- which = function (x ) " " ,
341- system2 = function (... ) " " ,
342342 sysname = " Darwin" ,
343343 config_value = function (name ) if (identical(name , " FC" )) " clang" else " "
344344 )
@@ -361,12 +361,15 @@ test_that("quickr_fcompiler_env errors when flang runtime not found on Darwin ex
361361 dir.create(build_dir )
362362
363363 withr :: local_options(quickr.fortran_compiler = " flang" )
364+ local_mocked_bindings(
365+ Sys.which = function (x ) if (x == " flang-new" ) flang else " " ,
366+ system2 = function (... ) " " ,
367+ .package = " base"
368+ )
364369
365370 expect_error(
366371 quickr ::: quickr_fcompiler_env(
367372 build_dir = build_dir ,
368- which = function (x ) if (x == " flang-new" ) flang else " " ,
369- system2 = function (... ) " " ,
370373 sysname = " Darwin"
371374 ),
372375 " could not locate the flang runtime library"
@@ -390,11 +393,16 @@ test_that("quickr_fcompiler_env falls back when flang runtime not found non-expl
390393 dir.create(build_dir )
391394
392395 withr :: local_options(quickr.fortran_compiler = " auto" )
396+ local_mocked_bindings(
397+ quickr_prefer_flang = function (... ) TRUE ,
398+ quickr_flang_available = function (... ) {
399+ list (path = flang , available = TRUE )
400+ },
401+ .package = " quickr"
402+ )
393403
394404 result <- quickr ::: quickr_fcompiler_env(
395405 build_dir = build_dir ,
396- which = function (x ) if (x == " flang-new" ) flang else " " ,
397- system2 = function (... ) " " ,
398406 sysname = " Darwin" ,
399407 config_value = function (name ) if (identical(name , " FC" )) " clang" else " "
400408 )
0 commit comments