Skip to content

Commit e63dca9

Browse files
authored
Add maintainance script for finding unused test files. NFC (emscripten-core#20434)
1 parent dc06099 commit e63dca9

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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())

0 commit comments

Comments
 (0)