1 #!/usr/bin/env python3
2 #
3 # Copyright (c) 2018-present The Bitcoin Core developers
4 # Distributed under the MIT software license, see the accompanying
5 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 7 """
8 Check the test suite naming conventions
9 """
10 11 import re
12 import subprocess
13 import sys
14 15 16 def grep_boost_test_suites():
17 command = [
18 "git",
19 "grep",
20 "-E",
21 r"^(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\(",
22 "--",
23 "src/ipc/test/**.cpp",
24 "src/test/**.cpp",
25 "src/wallet/test/**.cpp",
26 ]
27 return subprocess.check_output(command, text=True)
28 29 30 def main():
31 test_suite_list = grep_boost_test_suites().splitlines()
32 not_matching = [
33 x
34 for x in test_suite_list
35 if re.search(r"/(.*?)\.cpp:(?:BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\(\1(_[a-z0-9]+)?[,)]", x) is None
36 ]
37 if len(not_matching) > 0:
38 not_matching = "\n".join(not_matching)
39 error_msg = (
40 "The test suite in file src/test/foo_tests.cpp should be named\n"
41 '`foo_tests`, or if there are multiple test suites, `foo_tests_bar`.\n'
42 'Please make sure the following test suites follow that convention:\n\n'
43 f"{not_matching}\n"
44 )
45 print(error_msg)
46 sys.exit(1)
47 48 49 if __name__ == "__main__":
50 main()
51