6 from __future__
import print_function
7 import glob, os, re, sys
19 _EXPECT_FAILURE =
"EXPECT_FAILURE"
51 def __init__(self, env, ignoreList=None, expectedFailures=None, args=None,
52 tmpDir=
".tests", verbose=
False):
53 if 'PYTHONPATH' in os.environ:
54 env.AppendENVPath(
'PYTHONPATH', os.environ[
'PYTHONPATH'])
59 self.
_cwd = os.path.abspath(os.path.curdir)
66 if re.search(
r"^@", f):
69 if not os.path.exists(f):
70 state.log.warn(
"You're ignoring a non-existent file, %s" % f)
74 for f
in expectedFailures:
89 print(
"Not running examples; \"chmod 755 %s\" to run them again" % self.
_tmpDir,
94 return self.
_args[test]
100 not re.search(
r"\.py$", test)
and \
101 len(self._env.Glob(test)) == 0:
107 print(
"Skipping", test, file=sys.stderr)
112 """Return the messages to be used in case of success/failure; the logicals
113 (note that they are strings) tell whether the test is expected to pass"""
116 msg = self.
_info[test][1]
117 return "false",
"Passed, but should have failed: %s" % msg, \
118 "true",
"Failed as expected: %s" % msg
120 return "true",
"passed", \
124 if not isinstance(fileGlob, basestring):
125 fileGlob = str(fileGlob)
129 for f
in glob.glob(fileGlob):
132 if re.search(
r"\.cc", f):
133 f = os.path.splitext(f)[0]
135 interpreter =
"python"
140 target = os.path.join(self.
_tmpDir, f)
143 for a
in self.
args(f).split(
" "):
146 if re.search(
r"^" + filePrefix, a):
147 a = os.path.join(self.
_cwd, a[len(filePrefix):])
151 a = os.path.join(self.
_cwd, a)
157 (should_pass, passedMsg, should_fail, failedMsg) = self.
messages(f)
162 expandedArgs =
" ".join(args)
163 result = self._env.Command(target, f,
"""
164 @rm -f ${TARGET}.failed;
165 @printf "%%s" 'running ${SOURCES}... ';
166 @echo $SOURCES %s > $TARGET; echo >> $TARGET;
167 @if TRAVIS=1 %s $SOURCES %s >> $TARGET 2>&1; then \
168 if ! %s; then mv $TARGET ${TARGET}.failed; fi; \
171 if ! %s; then mv $TARGET ${TARGET}.failed; fi; \
174 """ % (expandedArgs, interpreter, expandedArgs, should_pass, passedMsg, should_fail, failedMsg))
176 targets.extend(result)
178 self._env.Alias(os.path.basename(target), target)
180 self._env.Clean(target, self.
_tmpDir)
A class to control unit tests.
def __init__
Create an object to run tests.