Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion make/tests
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif

##
# Adding a test for multiple translation units. If this fails,
# a new function is probably missing an inline
# a public umbrella header likely exposes a new non-inline external definition.
##

ifneq ($(OS),Windows_NT)
Expand Down
42 changes: 42 additions & 0 deletions runChecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,47 @@ def check_non_test_files_in_test():
return errors


def check_rev_test_fixtures():
test_files = [
x for x in files_in_folder("test/unit/math/rev")
if os.path.isfile(x) and x.endswith(testsfx)
]
errors = []
for filepath in test_files:
line_num = 0
multi_line_comment = False
old_state_multi_line_comment = False
with open(filepath, "r") as f:
for line in f:
line_num += 1
if multi_line_comment:
if re.search("\*/", line):
multi_line_comment = False
else:
if re.search("/\*", line):
multi_line_comment = True
if not multi_line_comment or (
multi_line_comment and not old_state_multi_line_comment
):
if (
not re.search(r".*\bTEST\(.*\*/.*", line)
and not re.search(r".*/\*.*\bTEST\(", line)
and not re.search(r".*//.*\bTEST\(", line)
and re.search(r"\bTEST\(", line)
):
errors.append(
filepath
+ " at line "
+ str(line_num)
+ ":\n\t[rev-tests] Reverse-mode tests in "
+ "test/unit/math/rev must use a cleanup fixture. "
+ "Replace raw TEST(...) with TEST_F(AgradRev, ...) "
+ "or another approved fixture-based form."
)
old_state_multi_line_comment = multi_line_comment
return errors


def main():
errors = []
# Check for files inside stan/math/prim that contain stan/math/rev or stan/math/fwd
Expand Down Expand Up @@ -242,6 +283,7 @@ def main():
)

errors.extend(check_non_test_files_in_test())
errors.extend(check_rev_test_fixtures())

errors.extend(check_non_unique_test_names())

Expand Down
3 changes: 1 addition & 2 deletions test/unit/math/rev/core/precomputed_gradients_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ TEST_F(AgradRev, StanAgradRevInternal_precomputed_gradients_containers) {
stan::math::recover_memory();
}

TEST(StanAgradRevInternal,
precomputed_gradients_containers_direct_construction) {
TEST_F(AgradRev, precomputed_gradients_containers_direct_construction) {
double value = 1;
std::vector<stan::math::var> vars;
std::vector<double> gradients;
Expand Down
Loading