Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/maint/find_unused_test_files.py
4150 views
1
#!/usr/bin/env python3
2
"""Search the test directory for un-referenced files.
3
4
This might be slow because it runs a `git grep` for every
5
file in the test directory.
6
"""
7
8
import os
9
import sys
10
import subprocess
11
12
script_dir = os.path.dirname(os.path.abspath(__file__))
13
root_dir = os.path.dirname(os.path.dirname(script_dir))
14
15
ignore_files = {'runner.bat'}
16
17
18
def clear_line():
19
if sys.stdout.isatty():
20
sys.stdout.write('\x1b[2K\r')
21
22
23
def main():
24
all_files = subprocess.check_output(['git', 'ls-files', 'test'], encoding='utf-8', cwd=root_dir).split('\n')
25
for i, filename in enumerate(all_files):
26
if sys.stdout.isatty():
27
clear_line()
28
sys.stdout.write(f'checking [{i}/{len(all_files)}] ({filename})')
29
sys.stdout.flush()
30
dirname, basename = os.path.split(filename)
31
if basename in ignore_files:
32
continue
33
ext = os.path.splitext(filename)[1]
34
if basename.startswith('test_') and ext == '.py':
35
continue
36
lookfor = basename
37
if ext == '.out':
38
lookfor = os.path.splitext(basename)[1]
39
rtn = subprocess.call(['git', 'grep', '--quiet', lookfor, 'test'], cwd=root_dir)
40
if rtn != 0:
41
if sys.stdout.isatty():
42
clear_line()
43
print(f'Not found: {basename}')
44
45
46
if __name__ == '__main__':
47
sys.exit(main())
48
49