22
33import os
44import unittest
5+ import logging
56
67from testfixtures import LogCapture
78
@@ -19,7 +20,7 @@ def test_opts_empty_eq(self):
1920 opts_b = None
2021 self .assertTrue (opts_a == opts_b )
2122
22- opts_c = CompilerOptions (stanc_options = {'-- O' })
23+ opts_c = CompilerOptions (stanc_options = {'O' })
2324 self .assertTrue (opts_a != opts_c != opts_b )
2425
2526 stanc_opts = {}
@@ -72,6 +73,44 @@ def test_opts_stanc(self):
7273 ['STANCFLAGS+=--warn-uninitialized' , 'STANCFLAGS+=--name=foo' ],
7374 )
7475
76+ stanc_opts ['O1' ] = True
77+ opts = CompilerOptions (stanc_options = stanc_opts )
78+ opts .validate ()
79+ self .assertEqual (
80+ opts .compose (),
81+ [
82+ 'STANCFLAGS+=--warn-uninitialized' ,
83+ 'STANCFLAGS+=--name=foo' ,
84+ 'STANCFLAGS+=--O1' ,
85+ ],
86+ )
87+
88+ # should add to logger
89+ stanc_opts ['Oexperimental' ] = True
90+ opts = CompilerOptions (stanc_options = stanc_opts )
91+ with LogCapture () as log :
92+ logging .getLogger ()
93+
94+ opts .validate ()
95+
96+ expect = (
97+ 'More than one of (O, O1, O2, Oexperimental)'
98+ 'optimizations passed. Only the last one will'
99+ 'be used'
100+ )
101+
102+ log .check_present (('cmdstanpy' , 'WARNING' , expect ))
103+
104+ self .assertEqual (
105+ opts .compose (),
106+ [
107+ 'STANCFLAGS+=--warn-uninitialized' ,
108+ 'STANCFLAGS+=--name=foo' ,
109+ 'STANCFLAGS+=--O1' ,
110+ 'STANCFLAGS+=--Oexperimental' ,
111+ ],
112+ )
113+
75114 def test_opts_stanc_deprecated (self ):
76115 stanc_opts = {}
77116 stanc_opts ['allow_undefined' ] = True
0 commit comments