3
Run the test(s) listed on the command line. If a directory is listed, the script will recursively
4
walk the directory for files named .mk and run each.
6
For each test, we run gmake -f test.mk. By default, make must exit with an exit code of 0, and must print 'TEST-PASS'.
8
Each test is run in an empty directory.
10
The test file may contain lines at the beginning to alter the default behavior. These are all evaluated as python:
12
#T commandline: ['extra', 'params', 'here']
14
#T returncode-on: {'win32': 2}
15
#T environment: {'VAR': 'VALUE}
19
from subprocess import Popen, PIPE, STDOUT
20
from optparse import OptionParser
21
import os, re, sys, shutil, glob
23
class ParentDict(dict):
24
def __init__(self, parent, **kwargs):
28
def __setitem__(self, k, v):
31
def __getitem__(self, k):
37
thisdir = os.path.dirname(os.path.abspath(__file__))
39
pymake = [sys.executable, os.path.join(os.path.dirname(thisdir), 'make.py')]
40
manifest = os.path.join(thisdir, 'tests.manifest')
43
o.add_option('-g', '--gmake',
44
dest="gmake", default="gmake")
45
o.add_option('-d', '--tempdir',
46
dest="tempdir", default="_mktests")
47
opts, args = o.parse_args()
56
elif os.path.isdir(a):
57
makefiles.extend(sorted(glob.glob(os.path.join(a, '*.mk'))))
59
def runTest(makefile, make, logfile, options):
61
Given a makefile path, test it with a given `make` and return
65
if os.path.exists(opts.tempdir): shutil.rmtree(opts.tempdir)
66
os.mkdir(opts.tempdir, 0755)
68
logfd = open(logfile, 'w')
69
p = Popen(make + options['commandline'], stdout=logfd, stderr=STDOUT, env=options['env'])
73
if retcode != options['returncode']:
74
return False, "FAIL (returncode=%i)" % retcode
80
if stdout.find('TEST-FAIL') != -1:
82
return False, "FAIL (TEST-FAIL printed)"
84
if options['grepfor'] and stdout.find(options['grepfor']) == -1:
86
return False, "FAIL (%s not in output)" % options['grepfor']
88
if options['returncode'] == 0 and stdout.find('TEST-PASS') == -1:
90
return False, 'FAIL (No TEST-PASS printed)'
92
if options['returncode'] != 0:
93
return True, 'PASS (retcode=%s)' % retcode
97
print "%-30s%-28s%-28s" % ("Test:", "gmake:", "pymake:")
102
tre = re.compile('^#T (gmake |pymake )?([a-z-]+)(?:: (.*))?$')
104
for makefile in makefiles:
105
# For some reason, MAKEFILE_LIST uses native paths in GNU make on Windows
106
# (even in MSYS!) so we pass both TESTPATH and NATIVE_TESTPATH
107
cline = ['-C', opts.tempdir, '-f', os.path.abspath(makefile), 'TESTPATH=%s' % thisdir.replace('\\','/'), 'NATIVE_TESTPATH=%s' % thisdir]
108
if sys.platform == 'win32':
109
#XXX: hack so we can specialize the separator character on windows.
110
# we really shouldn't need this, but y'know
111
cline += ['__WIN32__=1']
116
'env': dict(os.environ),
117
'commandline': cline,
122
gmakeoptions = ParentDict(options)
123
pymakeoptions = ParentDict(options)
125
dmap = {None: options, 'gmake ': gmakeoptions, 'pymake ': pymakeoptions}
127
mdata = open(makefile)
134
make, key, data = m.group(1, 2, 3)
138
if key == 'commandline':
140
d['commandline'].extend(data)
141
elif key == 'returncode':
142
d['returncode'] = data
143
elif key == 'returncode-on':
144
if sys.platform in data:
145
d['returncode'] = data[sys.platform]
146
elif key == 'environment':
147
for k, v in data.iteritems():
149
elif key == 'grep-for':
156
print >>sys.stderr, "%s: Unexpected #T key: %s" % (makefile, key)
161
if gmakeoptions['skip']:
162
gmakepass, gmakemsg = True, ''
164
gmakepass, gmakemsg = runTest(makefile, [opts.gmake],
165
makefile + '.gmakelog', gmakeoptions)
167
if gmakeoptions['pass']:
173
gmakemsg = "UNEXPECTED PASS"
175
gmakemsg = "KNOWN FAIL"
177
if pymakeoptions['skip']:
178
pymakepass, pymakemsg = True, ''
180
pymakepass, pymakemsg = runTest(makefile, pymake,
181
makefile + '.pymakelog', pymakeoptions)
183
if pymakeoptions['pass']:
189
pymakemsg = "UNEXPECTED PASS"
191
pymakemsg = "OK (known fail)"
193
print "%-30.30s%-28.28s%-28.28s" % (os.path.basename(makefile),
198
print "%-30s%-28s%-28s" % ("", "gmake:", "pymake:")
203
gmakemsg = 'FAIL (%i failures)' % gmakefails
208
pymakemsg = 'FAIL (%i failures)' % pymakefails
210
print "%-30.30s%-28.28s%-28.28s" % ('', gmakemsg, pymakemsg)
212
shutil.rmtree(opts.tempdir)
214
if gmakefails or pymakefails: