Skip to content

Commit 04e580c

Browse files
committed
Add test
1 parent 804267a commit 04e580c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/testthat/test-model-expose-functions.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,24 @@ test_that("Exposing external functions errors before v2.32", {
175175

176176
reset_cmdstan_version()
177177
})
178+
179+
test_that("Exposing functions with precompiled model gives meaningful error", {
180+
skip_if(os_is_wsl())
181+
182+
stan_file <- write_stan_file("
183+
functions {
184+
real a_plus_b(real a, real b) { return a + b; }
185+
}
186+
parameters { real x; }
187+
model { x ~ std_normal(); }
188+
")
189+
mod1 <- cmdstan_model(stan_file, compile_standalone = TRUE)
190+
expect_equal(7.5, mod1$functions$a_plus_b(5, 2.5))
191+
192+
mod2 <- cmdstan_model(stan_file)
193+
expect_error(
194+
mod2$expose_functions(),
195+
"Exporting standalone functions is not possible with a pre-compiled Stan model!",
196+
fixed = TRUE
197+
)
198+
})

0 commit comments

Comments
 (0)