Skip to content

Commit 9b20bb4

Browse files
committed
[tests] Check tests conform to naming convention
Extra-Author: John Newbery <[email protected]>
1 parent 7250b4e commit 9b20bb4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/functional/test_runner.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def main():
260260
sys.exit(0)
261261

262262
check_script_list(config["environment"]["SRCDIR"])
263+
check_script_prefixes()
263264

264265
if not args.keepcache:
265266
shutil.rmtree("%s/test/cache" % config["environment"]["BUILDDIR"], ignore_errors=True)
@@ -444,6 +445,28 @@ def was_successful(self):
444445
return self.status != "Failed"
445446

446447

448+
def check_script_prefixes():
449+
"""Check that no more than `EXPECTED_VIOLATION_COUNT` of the
450+
test scripts don't start with one of the allowed name prefixes."""
451+
EXPECTED_VIOLATION_COUNT = 77
452+
453+
# LEEWAY is provided as a transition measure, so that pull-requests
454+
# that introduce new tests that don't conform with the naming
455+
# convention don't immediately cause the tests to fail.
456+
LEEWAY = 10
457+
458+
good_prefixes_re = re.compile("(example|feature|interface|mempool|mining|p2p|rpc|wallet)_")
459+
bad_script_names = [script for script in ALL_SCRIPTS if good_prefixes_re.match(script) is None]
460+
461+
if len(bad_script_names) < EXPECTED_VIOLATION_COUNT:
462+
print("{}HURRAY!{} Number of functional tests violating naming convention reduced!".format(BOLD[1], BOLD[0]))
463+
print("Consider reducing EXPECTED_VIOLATION_COUNT from %d to %d" % (EXPECTED_VIOLATION_COUNT, len(bad_script_names)))
464+
elif len(bad_script_names) > EXPECTED_VIOLATION_COUNT:
465+
print("INFO: %d tests not meeting naming conventions (expected %d):" % (len(bad_script_names), EXPECTED_VIOLATION_COUNT))
466+
print(" %s" % ("\n ".join(sorted(bad_script_names))))
467+
assert len(bad_script_names) <= EXPECTED_VIOLATION_COUNT + LEEWAY, "Too many tests not following naming convention! (%d found, expected: <= %d)" % (len(bad_script_names), EXPECTED_VIOLATION_COUNT)
468+
469+
447470
def check_script_list(src_dir):
448471
"""Check scripts directory.
449472

0 commit comments

Comments
 (0)