5 # Count statistics about SCons test and source files. This must be run
6 # against a fully-populated tree (for example, one that's been freshly
9 # A test file is anything under the src/ directory that begins with
10 # 'test_' or ends in 'Tests.py', or anything under the test/ directory
11 # that ends in '.py'. Note that runtest.py script does *not*, by default,
12 # consider the files that begin with 'test_' to be tests, because they're
13 # tests of SCons packaging and installation, not functional tests of
16 # A source file is anything under the src/engine/ or src/script/
17 # directories that ends in '.py' but does NOT begin with 'test_'
18 # or end in 'Tests.py'.
20 # We report the number of tests and sources, the total number of lines
21 # in each category, the number of non-blank lines, and the number of
22 # non-comment lines. The last figure (non-comment) lines is the most
23 # interesting one for most purposes.
26 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
35 return x[:5] == 'test_' or x[-8:] == 'Tests.py'
37 return x[-3:] == '.py'
39 def t(arg, dirname, names):
40 names = filter(is_test, names)
41 arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
42 os.path.walk('src', t, tests)
44 def p(arg, dirname, names):
45 names = filter(is_python, names)
46 arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
47 os.path.walk('test', p, tests)
49 def s(arg, dirname, names):
50 names = filter(lambda n: is_python(n) and not is_test(n), names)
51 arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names))
52 os.path.walk('src/engine', s, sources)
53 os.path.walk('src/script', s, sources)
58 lines.extend(open(file).readlines())
61 tlines = map(string.lstrip, gather(tests))
62 slines = map(string.lstrip, gather(sources))
64 nbtl = filter(lambda x: x != '', tlines)
65 nbsl = filter(lambda x: x != '', slines)
67 nctl = filter(lambda x: x[0] != '#', nbtl)
68 ncsl = filter(lambda x: x[0] != '#', nbsl)
70 def ratio(over, under):
71 return "%.2f" % (float(len(over)) / float(len(under)))
73 rfiles = ratio(tests, sources)
74 rlines = ratio(tlines, slines)
75 rnonblank = ratio(nbtl, nbsl)
76 rnoncomment = ratio(nctl, ncsl)
78 fmt = "%-8s %12s %12s %12s %12s"
80 print fmt % ('', 'files', 'lines', 'non-blank', 'non-comment')
81 print fmt % ('tests:', len(tests), len(tlines), len(nbtl), len(nctl))
82 print fmt % ('sources:', len(sources), len(slines), len(nbsl), len(ncsl))
83 print fmt % ('ratio:', rfiles, rlines, rnonblank, rnoncomment)