1
1
context(" model-expose-functions" )
2
2
3
+ # Standalone functions not expected to work on WSL yet
4
+ skip_if(os_is_wsl())
5
+
3
6
set_cmdstan_path()
4
7
5
8
function_decl <- "
@@ -81,14 +84,11 @@ fit <- mod$sample(data = data_list)
81
84
82
85
83
86
test_that(" Functions can be exposed in model object" , {
84
- skip_if(os_is_wsl())
85
87
expect_no_error(mod $ expose_functions(verbose = TRUE ))
86
88
})
87
89
88
90
89
91
test_that(" Functions handle types correctly" , {
90
- skip_if(os_is_wsl())
91
-
92
92
# ## Scalar
93
93
94
94
expect_equal(mod $ functions $ rtn_int(10 ), 10 )
@@ -178,8 +178,6 @@ test_that("Functions handle types correctly", {
178
178
})
179
179
180
180
test_that(" Functions handle complex types correctly" , {
181
- skip_if(os_is_wsl())
182
-
183
181
# ## Scalar
184
182
185
183
complex_scalar <- complex (real = 2.1 , imaginary = 21.3 )
@@ -262,7 +260,6 @@ test_that("Functions handle complex types correctly", {
262
260
})
263
261
264
262
test_that(" Functions can be exposed in fit object" , {
265
- skip_if(os_is_wsl())
266
263
fit $ expose_functions(verbose = TRUE )
267
264
268
265
expect_equal(
@@ -272,7 +269,6 @@ test_that("Functions can be exposed in fit object", {
272
269
})
273
270
274
271
test_that(" Compiled functions can be copied to global environment" , {
275
- skip_if(os_is_wsl())
276
272
expect_message(
277
273
fit $ expose_functions(global = TRUE ),
278
274
" Functions already compiled, copying to global environment" ,
@@ -287,7 +283,6 @@ test_that("Compiled functions can be copied to global environment", {
287
283
288
284
289
285
test_that(" Functions can be compiled with model" , {
290
- skip_if(os_is_wsl())
291
286
mod <- cmdstan_model(model , force_recompile = TRUE , compile_standalone = TRUE )
292
287
fit <- mod $ sample(data = data_list )
293
288
@@ -314,8 +309,33 @@ test_that("Functions can be compiled with model", {
314
309
)
315
310
})
316
311
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
+
317
338
test_that(" rng functions can be exposed" , {
318
- skip_if(os_is_wsl())
319
339
function_decl <- " functions { real wrap_normal_rng(real mu, real sigma) { return normal_rng(mu, sigma); } }"
320
340
stan_prog <- paste(function_decl ,
321
341
paste(readLines(testing_stan_file(" bernoulli" )),
@@ -341,8 +361,6 @@ test_that("rng functions can be exposed", {
341
361
})
342
362
343
363
test_that(" Overloaded functions give meaningful errors" , {
344
- skip_if(os_is_wsl())
345
-
346
364
funcode <- "
347
365
functions {
348
366
real fun1(real x) { return x; }
@@ -359,8 +377,6 @@ test_that("Overloaded functions give meaningful errors", {
359
377
})
360
378
361
379
test_that(" Exposing external functions errors before v2.32" , {
362
- skip_if(os_is_wsl())
363
-
364
380
fake_cmdstan_version(" 2.26.0" )
365
381
366
382
tmpfile <- tempfile(fileext = " .hpp" )
@@ -387,8 +403,6 @@ test_that("Exposing external functions errors before v2.32", {
387
403
})
388
404
389
405
test_that(" Exposing functions with precompiled model gives meaningful error" , {
390
- skip_if(os_is_wsl())
391
-
392
406
stan_file <- write_stan_file("
393
407
functions {
394
408
real a_plus_b(real a, real b) { return a + b; }
0 commit comments