11context(" model-expose-functions" )
22
3+ # Standalone functions not expected to work on WSL yet
4+ skip_if(os_is_wsl())
5+
36set_cmdstan_path()
47
58function_decl <- "
@@ -81,14 +84,11 @@ fit <- mod$sample(data = data_list)
8184
8285
8386test_that(" Functions can be exposed in model object" , {
84- skip_if(os_is_wsl())
8587 expect_no_error(mod $ expose_functions(verbose = TRUE ))
8688})
8789
8890
8991test_that(" Functions handle types correctly" , {
90- skip_if(os_is_wsl())
91-
9292 # ## Scalar
9393
9494 expect_equal(mod $ functions $ rtn_int(10 ), 10 )
@@ -178,8 +178,6 @@ test_that("Functions handle types correctly", {
178178})
179179
180180test_that(" Functions handle complex types correctly" , {
181- skip_if(os_is_wsl())
182-
183181 # ## Scalar
184182
185183 complex_scalar <- complex (real = 2.1 , imaginary = 21.3 )
@@ -262,7 +260,6 @@ test_that("Functions handle complex types correctly", {
262260})
263261
264262test_that(" Functions can be exposed in fit object" , {
265- skip_if(os_is_wsl())
266263 fit $ expose_functions(verbose = TRUE )
267264
268265 expect_equal(
@@ -272,7 +269,6 @@ test_that("Functions can be exposed in fit object", {
272269})
273270
274271test_that(" Compiled functions can be copied to global environment" , {
275- skip_if(os_is_wsl())
276272 expect_message(
277273 fit $ expose_functions(global = TRUE ),
278274 " Functions already compiled, copying to global environment" ,
@@ -287,7 +283,6 @@ test_that("Compiled functions can be copied to global environment", {
287283
288284
289285test_that(" Functions can be compiled with model" , {
290- skip_if(os_is_wsl())
291286 mod <- cmdstan_model(model , force_recompile = TRUE , compile_standalone = TRUE )
292287 fit <- mod $ sample(data = data_list )
293288
@@ -314,8 +309,33 @@ test_that("Functions can be compiled with model", {
314309 )
315310})
316311
312+ test_that(" compile_standalone warns but doesn't error if no functions" , {
313+ stan_no_funs_block <- write_stan_file("
314+ parameters {
315+ real x;
316+ }
317+ model {
318+ x ~ std_normal();
319+ }
320+ " )
321+ expect_warning(
322+ mod1 <- cmdstan_model(stan_no_funs_block , compile = TRUE , compile_standalone = TRUE , force_recompile = TRUE ),
323+ " No standalone functions found to compile and expose to R"
324+ )
325+ checkmate :: expect_r6(mod1 , " CmdStanModel" )
326+
327+ stan_empty_funs_block <- write_stan_file("
328+ functions {
329+ }
330+ " )
331+ expect_warning(
332+ mod2 <- cmdstan_model(stan_empty_funs_block , compile = TRUE , compile_standalone = TRUE , force_recompile = TRUE ),
333+ " No standalone functions found to compile and expose to R"
334+ )
335+ checkmate :: expect_r6(mod2 , " CmdStanModel" )
336+ })
337+
317338test_that(" rng functions can be exposed" , {
318- skip_if(os_is_wsl())
319339 function_decl <- " functions { real wrap_normal_rng(real mu, real sigma) { return normal_rng(mu, sigma); } }"
320340 stan_prog <- paste(function_decl ,
321341 paste(readLines(testing_stan_file(" bernoulli" )),
@@ -341,8 +361,6 @@ test_that("rng functions can be exposed", {
341361})
342362
343363test_that(" Overloaded functions give meaningful errors" , {
344- skip_if(os_is_wsl())
345-
346364 funcode <- "
347365 functions {
348366 real fun1(real x) { return x; }
@@ -359,8 +377,6 @@ test_that("Overloaded functions give meaningful errors", {
359377})
360378
361379test_that(" Exposing external functions errors before v2.32" , {
362- skip_if(os_is_wsl())
363-
364380 fake_cmdstan_version(" 2.26.0" )
365381
366382 tmpfile <- tempfile(fileext = " .hpp" )
@@ -387,8 +403,6 @@ test_that("Exposing external functions errors before v2.32", {
387403})
388404
389405test_that(" Exposing functions with precompiled model gives meaningful error" , {
390- skip_if(os_is_wsl())
391-
392406 stan_file <- write_stan_file("
393407 functions {
394408 real a_plus_b(real a, real b) { return a + b; }
0 commit comments