pyobjc / pyobjc / Scripts / runalltests

#!/usr/bin/env python

# Run all PyObjC tests. Every testscript will be started in a 
# fresh interpreter: Some tests depend on the availability or
# non-availability of some frameworks.
# Run from the root of the source-tree.
# NOTE: There should probably be a script that can run the
# scripts from the installed tree, but this should be enough
# to make it easy to actually run the full testsuite.

import sys
import os

tests = {}
test_sum = { 'OK': 0, 'FAIL':0, 'CRASH': 0 }

def perform_some_tests(dummy, dirname, fnames):
        if os.path.split(dirname)[-1] != 'test': return

        for nm in fnames:
                if not nm.startswith('test_'): continue
                if not nm.endswith('.py'): continue
        	path = os.path.join(dirname, nm)
        	print "-- Running '%s'"%path
        	fd = os.popen("'%s' '%s' 2>&1"%(sys.executable, path), 'r')
                ln = ''
                for _ln in fd.xreadlines():

                    # Odd GNUstep bug...
                    if _ln.startswith('Unable to retrieve information about SIGPIPE'): continue

                    ln = _ln

                xit = fd.close()
                if ln.startswith('OK'):
                    if xit is not None:
                        tests[path] = 'Exit with %s: %s'%(xit, ln.strip())
                        test_sum['CRASH'] += 1
                        tests[path] = ln.strip()
                        test_sum['OK'] += 1

                elif ln.startswith('FAIL'):
                    tests[path] = ln.strip()
                    test_sum['FAIL'] += 1

                    tests[path] = 'CRASHED'
                    test_sum['CRASH'] += 1

        	print "-- Done"

#os.path.walk('Lib/objc', perform_some_tests, None)
#os.path.walk('Lib/Foundation', perform_some_tests, None)
os.path.walk('Lib', perform_some_tests, None)

keys = tests.keys()
print "\nSummary of not-OK tests:"
for k in keys:
    if tests[k] != "OK":
        print "  %-50s: %s"%(k[4:], tests[k])

print "\n%(OK)s OK, %(FAIL)s FAILED, %(CRASH)s CRASHED"%test_sum