1+ stan_program <- cmdstan_example_file()
2+ file_that_doesnt_exist <- " placeholder_doesnt_exist"
3+ file_that_exists <- " placeholder_exists"
4+ file.create(file_that_exists )
5+ withr :: defer(
6+ if (file.exists(file_that_exists )) file.remove(file_that_exists ),
7+ teardown_env()
8+ )
9+
10+ skip_message <- " To be fixed in a later version."
11+
12+ test_that(" warning when no recompile and no info" , {
13+ skip(skip_message )
14+ with_mocked_cli(
15+ compile_ret = list (),
16+ info_ret = list (status = 1 ),
17+ code = expect_warning({
18+ mod <- cmdstan_model(
19+ stan_file = stan_program ,
20+ exe_file = file_that_exists ,
21+ compile = FALSE
22+ )
23+ }, " Recompiling is recommended." )
24+ )
25+ })
26+
27+ test_that(" recompiles when force_recompile flag set" ,
28+ with_mocked_cli(
29+ compile_ret = list (status = 0 ),
30+ info_ret = list (),
31+ code = expect_mock_compile({
32+ mod <- cmdstan_model(stan_file = stan_program , force_recompile = TRUE )
33+ })
34+ )
35+ )
36+
37+ test_that(" no mismatch results in no recompile" , with_mocked_cli(
38+ compile_ret = list (status = 0 ),
39+ info_ret = list (
40+ status = 0 ,
41+ stdout = "
42+ stan_version_major = 2
43+ stan_version_minor = 35
44+ stan_version_patch = 0
45+ STAN_THREADS=false
46+ STAN_MPI=false
47+ STAN_OPENCL=false
48+ STAN_NO_RANGE_CHECKS=false
49+ STAN_CPP_OPTIMS=false
50+ "
51+ ),
52+ code = expect_no_mock_compile({
53+ mod <- cmdstan_model(stan_file = stan_program , exe_file = file_that_exists )
54+ })
55+ ))
56+
57+ test_that(" mismatch results in recompile." , {
58+ skip(skip_message )
59+ with_mocked_cli(
60+ compile_ret = list (status = 0 ),
61+ info_ret = list (
62+ status = 0 ,
63+ stdout = "
64+ stan_version_major = 2
65+ stan_version_minor = 35
66+ stan_version_patch = 0
67+ STAN_THREADS=false
68+ STAN_MPI=false
69+ STAN_OPENCL=false
70+ STAN_NO_RANGE_CHECKS=false
71+ STAN_CPP_OPTIMS=false
72+ "
73+ ),
74+ code = expect_mock_compile({
75+ mod <- cmdstan_model(
76+ stan_file = stan_program ,
77+ exe_file = file_that_exists ,
78+ cpp_options = list (stan_threads = TRUE )
79+ )
80+ })
81+ )
82+ })
83+
84+ test_that(" recompile when cpp args don't match binary" , {
85+ skip(skip_message )
86+ with_mocked_cli(
87+ compile_ret = list (status = 0 ),
88+ info_ret = list (
89+ status = 0 ,
90+ stdout = "
91+ stan_version_major = 2
92+ stan_version_minor = 38
93+ stan_version_patch = 0
94+ STAN_THREADS=false
95+ STAN_MPI=false
96+ STAN_OPENCL=true
97+ STAN_NO_RANGE_CHECKS=false
98+ STAN_CPP_OPTIMS=false
99+ "
100+ ),
101+ expect_mock_compile({
102+ mod_gq <- cmdstan_model(
103+ testing_stan_file(" bernoulli_ppc" ),
104+ exe_file = file_that_exists ,
105+ cpp_options = list (stan_threads = TRUE )
106+ )
107+ })
108+ )
109+ })
0 commit comments