@@ -142,6 +142,47 @@ def check_non_test_files_in_test():
142142 return errors
143143
144144
145+ def check_rev_test_fixtures ():
146+ test_files = [
147+ x for x in files_in_folder ("test/unit/math/rev" )
148+ if os .path .isfile (x ) and x .endswith (testsfx )
149+ ]
150+ errors = []
151+ for filepath in test_files :
152+ line_num = 0
153+ multi_line_comment = False
154+ old_state_multi_line_comment = False
155+ with open (filepath , "r" ) as f :
156+ for line in f :
157+ line_num += 1
158+ if multi_line_comment :
159+ if re .search ("\*/" , line ):
160+ multi_line_comment = False
161+ else :
162+ if re .search ("/\*" , line ):
163+ multi_line_comment = True
164+ if not multi_line_comment or (
165+ multi_line_comment and not old_state_multi_line_comment
166+ ):
167+ if (
168+ not re .search (r".*\bTEST\(.*\*/.*" , line )
169+ and not re .search (r".*/\*.*\bTEST\(" , line )
170+ and not re .search (r".*//.*\bTEST\(" , line )
171+ and re .search (r"\bTEST\(" , line )
172+ ):
173+ errors .append (
174+ filepath
175+ + " at line "
176+ + str (line_num )
177+ + ":\n \t [rev-tests] Reverse-mode tests in "
178+ + "test/unit/math/rev must use a cleanup fixture. "
179+ + "Replace raw TEST(...) with TEST_F(AgradRev, ...) "
180+ + "or another approved fixture-based form."
181+ )
182+ old_state_multi_line_comment = multi_line_comment
183+ return errors
184+
185+
145186def main ():
146187 errors = []
147188 # Check for files inside stan/math/prim that contain stan/math/rev or stan/math/fwd
@@ -242,6 +283,7 @@ def main():
242283 )
243284
244285 errors .extend (check_non_test_files_in_test ())
286+ errors .extend (check_rev_test_fixtures ())
245287
246288 errors .extend (check_non_unique_test_names ())
247289
0 commit comments