Skip to content

Commit

Permalink
[tests] Check tests conform to naming convention
Browse files Browse the repository at this point in the history
Extra-Author: John Newbery <john@johnnewbery.com>
  • Loading branch information
ajtowns committed Dec 7, 2017
1 parent 7250b4e commit 9b20bb4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/functional/test_runner.py
Expand Up @@ -260,6 +260,7 @@ def main():
sys.exit(0)

check_script_list(config["environment"]["SRCDIR"])
check_script_prefixes()

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


def check_script_prefixes():
"""Check that no more than `EXPECTED_VIOLATION_COUNT` of the
test scripts don't start with one of the allowed name prefixes."""
EXPECTED_VIOLATION_COUNT = 77

# LEEWAY is provided as a transition measure, so that pull-requests
# that introduce new tests that don't conform with the naming
# convention don't immediately cause the tests to fail.
LEEWAY = 10

good_prefixes_re = re.compile("(example|feature|interface|mempool|mining|p2p|rpc|wallet)_")
bad_script_names = [script for script in ALL_SCRIPTS if good_prefixes_re.match(script) is None]

if len(bad_script_names) < EXPECTED_VIOLATION_COUNT:
print("{}HURRAY!{} Number of functional tests violating naming convention reduced!".format(BOLD[1], BOLD[0]))
print("Consider reducing EXPECTED_VIOLATION_COUNT from %d to %d" % (EXPECTED_VIOLATION_COUNT, len(bad_script_names)))
elif len(bad_script_names) > EXPECTED_VIOLATION_COUNT:
print("INFO: %d tests not meeting naming conventions (expected %d):" % (len(bad_script_names), EXPECTED_VIOLATION_COUNT))
print(" %s" % ("\n ".join(sorted(bad_script_names))))
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)


def check_script_list(src_dir):
"""Check scripts directory.
Expand Down

0 comments on commit 9b20bb4

Please sign in to comment.