33import os
44import unittest
55
6+ from testfixtures import LogCapture
7+
68from cmdstanpy .compiler_opts import CompilerOptions
79
810HERE = os .path .dirname (os .path .abspath (__file__ ))
@@ -70,6 +72,28 @@ def test_opts_stanc(self):
7072 ['STANCFLAGS+=--warn-uninitialized' , 'STANCFLAGS+=--name=foo' ],
7173 )
7274
75+ def test_opts_stanc_deprecated (self ):
76+ stanc_opts = {}
77+ stanc_opts ['allow_undefined' ] = True
78+ opts = CompilerOptions (stanc_options = stanc_opts )
79+ with LogCapture () as log :
80+ opts .validate ()
81+ log .check_present (
82+ (
83+ 'cmdstanpy' ,
84+ 'WARNING' ,
85+ 'compiler option "allow_undefined" is deprecated,'
86+ ' use "allow-undefined" instead' ,
87+ )
88+ )
89+ self .assertEqual (opts .compose (), ['STANCFLAGS+=--allow-undefined' ])
90+
91+ stanc_opts ['include_paths' ] = DATAFILES_PATH
92+ opts = CompilerOptions (stanc_options = stanc_opts )
93+ opts .validate ()
94+ self .assertIn ('include-paths' , opts .stanc_options )
95+ self .assertNotIn ('include_paths' , opts .stanc_options )
96+
7397 def test_opts_stanc_opencl (self ):
7498 stanc_opts = {}
7599 stanc_opts ['use-opencl' ] = 'foo'
@@ -89,22 +113,22 @@ def test_opts_stanc_ignore(self):
89113 def test_opts_stanc_includes (self ):
90114 path2 = os .path .join (HERE , 'data' , 'optimize' )
91115 paths_str = ',' .join ([DATAFILES_PATH , path2 ]).replace ('\\ ' , '/' )
92- expect = 'STANCFLAGS+=--include_paths =' + paths_str
116+ expect = 'STANCFLAGS+=--include-paths =' + paths_str
93117
94- stanc_opts = {'include_paths ' : paths_str }
118+ stanc_opts = {'include-paths ' : paths_str }
95119 opts = CompilerOptions (stanc_options = stanc_opts )
96120 opts .validate ()
97121 opts_list = opts .compose ()
98122 self .assertTrue (expect in opts_list )
99123
100- stanc_opts = {'include_paths ' : [DATAFILES_PATH , path2 ]}
124+ stanc_opts = {'include-paths ' : [DATAFILES_PATH , path2 ]}
101125 opts = CompilerOptions (stanc_options = stanc_opts )
102126 opts .validate ()
103127 opts_list = opts .compose ()
104128 self .assertTrue (expect in opts_list )
105129
106130 def test_opts_add_include_paths (self ):
107- expect = 'STANCFLAGS+=--include_paths =' + DATAFILES_PATH .replace (
131+ expect = 'STANCFLAGS+=--include-paths =' + DATAFILES_PATH .replace (
108132 '\\ ' , '/'
109133 )
110134 stanc_opts = {'warn-uninitialized' : True }
@@ -120,7 +144,7 @@ def test_opts_add_include_paths(self):
120144
121145 path2 = os .path .join (HERE , 'data' , 'optimize' )
122146 paths_str = ',' .join ([DATAFILES_PATH , path2 ]).replace ('\\ ' , '/' )
123- expect = 'STANCFLAGS+=--include_paths =' + paths_str
147+ expect = 'STANCFLAGS+=--include-paths =' + paths_str
124148 opts .add_include_path (path2 )
125149 opts .validate ()
126150 opts_list = opts .compose ()
@@ -169,7 +193,7 @@ def test_user_header(self):
169193 header_file = os .path .join (DATAFILES_PATH , 'return_one.hpp' )
170194 opts = CompilerOptions (user_header = header_file )
171195 opts .validate ()
172- self .assertTrue (opts .stanc_options ['allow_undefined ' ])
196+ self .assertTrue (opts .stanc_options ['allow-undefined ' ])
173197
174198 bad = os .path .join (DATAFILES_PATH , 'nonexistant.hpp' )
175199 opts = CompilerOptions (user_header = bad )
@@ -209,20 +233,20 @@ def test_opts_add(self):
209233 self .assertTrue ('STAN_OPENCL=FALSE' in opts_list )
210234 self .assertTrue ('OPENCL_DEVICE_ID=2' in opts_list )
211235
212- expect = 'STANCFLAGS+=--include_paths =' + DATAFILES_PATH .replace (
236+ expect = 'STANCFLAGS+=--include-paths =' + DATAFILES_PATH .replace (
213237 '\\ ' , '/'
214238 )
215- stanc_opts2 = {'include_paths ' : DATAFILES_PATH }
239+ stanc_opts2 = {'include-paths ' : DATAFILES_PATH }
216240 new_opts2 = CompilerOptions (stanc_options = stanc_opts2 )
217241 opts .add (new_opts2 )
218242 opts_list = opts .compose ()
219243 self .assertTrue (expect in opts_list )
220244
221245 path2 = os .path .join (HERE , 'data' , 'optimize' )
222- expect = 'STANCFLAGS+=--include_paths =' + ',' .join (
246+ expect = 'STANCFLAGS+=--include-paths =' + ',' .join (
223247 [DATAFILES_PATH , path2 ]
224248 ).replace ('\\ ' , '/' )
225- stanc_opts3 = {'include_paths ' : path2 }
249+ stanc_opts3 = {'include-paths ' : path2 }
226250 new_opts3 = CompilerOptions (stanc_options = stanc_opts3 )
227251 opts .add (new_opts3 )
228252 opts_list = opts .compose ()
0 commit comments