2018-03-31 15:25:21 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2017-02-14 21:48:24 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import glob
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def check_src_files_have_test():
|
|
|
|
missing_test_files = []
|
|
|
|
|
2020-12-14 19:00:35 +00:00
|
|
|
excluded = [
|
2022-04-26 11:53:35 +00:00
|
|
|
"mitmproxy/contrib/",
|
|
|
|
"mitmproxy/io/proto/",
|
|
|
|
"mitmproxy/proxy/layers/http",
|
|
|
|
"mitmproxy/test/",
|
|
|
|
"mitmproxy/tools/",
|
|
|
|
"mitmproxy/platform/",
|
2022-06-28 11:38:12 +00:00
|
|
|
"mitmproxy/utils/pyinstaller/",
|
2022-04-26 11:53:35 +00:00
|
|
|
]
|
|
|
|
src_files = glob.glob("mitmproxy/**/*.py", recursive=True)
|
|
|
|
src_files = [f for f in src_files if os.path.basename(f) != "__init__.py"]
|
|
|
|
src_files = [
|
|
|
|
f for f in src_files if not any(os.path.normpath(p) in f for p in excluded)
|
2020-12-14 19:00:35 +00:00
|
|
|
]
|
2017-02-14 21:48:24 +00:00
|
|
|
for f in src_files:
|
|
|
|
p = os.path.join("test", os.path.dirname(f), "test_" + os.path.basename(f))
|
|
|
|
if not os.path.isfile(p):
|
|
|
|
missing_test_files.append((f, p))
|
|
|
|
|
|
|
|
return missing_test_files
|
|
|
|
|
|
|
|
|
|
|
|
def check_test_files_have_src():
|
|
|
|
unknown_test_files = []
|
|
|
|
|
2020-12-14 19:00:35 +00:00
|
|
|
excluded = [
|
2022-04-26 11:53:35 +00:00
|
|
|
"test/mitmproxy/data/",
|
|
|
|
"test/mitmproxy/net/data/",
|
|
|
|
"/tservers.py",
|
|
|
|
"/conftest.py",
|
|
|
|
]
|
|
|
|
test_files = glob.glob("test/mitmproxy/**/*.py", recursive=True)
|
|
|
|
test_files = [f for f in test_files if os.path.basename(f) != "__init__.py"]
|
|
|
|
test_files = [
|
|
|
|
f for f in test_files if not any(os.path.normpath(p) in f for p in excluded)
|
2020-12-14 19:00:35 +00:00
|
|
|
]
|
2017-02-14 21:48:24 +00:00
|
|
|
for f in test_files:
|
2022-04-26 11:53:35 +00:00
|
|
|
p = os.path.join(
|
|
|
|
re.sub("^test/", "", os.path.dirname(f)),
|
|
|
|
re.sub("^test_", "", os.path.basename(f)),
|
|
|
|
)
|
2017-02-14 21:48:24 +00:00
|
|
|
if not os.path.isfile(p):
|
|
|
|
unknown_test_files.append((f, p))
|
|
|
|
|
|
|
|
return unknown_test_files
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
exitcode = 0
|
|
|
|
|
|
|
|
missing_test_files = check_src_files_have_test()
|
|
|
|
if missing_test_files:
|
|
|
|
exitcode += 1
|
|
|
|
for f, p in sorted(missing_test_files):
|
2020-11-20 18:25:26 +00:00
|
|
|
print(f"{f} MUST have a matching test file: {p}")
|
2017-02-14 21:48:24 +00:00
|
|
|
|
|
|
|
unknown_test_files = check_test_files_have_src()
|
|
|
|
if unknown_test_files:
|
|
|
|
# TODO: enable this in the future
|
|
|
|
# exitcode += 1
|
|
|
|
for f, p in sorted(unknown_test_files):
|
2020-11-20 18:25:26 +00:00
|
|
|
print(f"{f} DOES NOT MATCH a source file! Expected to find: {p}")
|
2017-02-14 21:48:24 +00:00
|
|
|
|
|
|
|
sys.exit(exitcode)
|
|
|
|
|
|
|
|
|
2022-04-26 11:53:35 +00:00
|
|
|
if __name__ == "__main__":
|
2017-02-14 21:48:24 +00:00
|
|
|
main()
|