def execute(self, **kw):
raise SCons.Errors.BuildError
+class ExceptBuilder2:
+ def execute(self, **kw):
+ raise "foo"
+
class Environment:
def Dictionary(self, *args):
pass
else:
raise TestFailed, "did not catch expected BuildError"
+ node = SCons.Node.Node()
+ node.builder_set(ExceptBuilder2())
+ node.env_set(Environment())
+ try:
+ node.build()
+ except SCons.Errors.BuildError, e:
+ # On a generic (non-BuildError) exception from a Builder,
+ # the Node should throw a BuildError exception with
+ # the args set to the exception value, type, and traceback.
+ assert len(e.args) == 3, `e.args`
+ assert e.args[0] == 'foo', e.args[0]
+ assert e.args[1] is None
+ assert type(e.args[2]) is type(sys.exc_traceback), e.args[2]
+ else:
+ raise TestFailed, "did not catch expected BuildError"
+
def test_build(self):
"""Test building a node
"""
import string
import types
import copy
+import sys
# Node states
#
stat = self.builder.execute(env = self.env.Dictionary(),
target = self, source = self.sources)
except:
- raise BuildError(node = self, errstr = "Exception")
+ raise BuildError(self, "Exception",
+ sys.exc_type,
+ sys.exc_value,
+ sys.exc_traceback)
if stat:
raise BuildError(node = self, errstr = "Error %d" % stat)
self.target.build()
except BuildError, e:
sys.stderr.write("scons: *** [%s] %s\n" % (e.node, e.errstr))
+ if e.errstr == 'Exception':
+ traceback.print_exception(e.args[0], e.args[1],
+ e.args[2])
raise
def executed(self):
if os.name == 'nt':
errs = [
bad_command,
- unrecognized % (no_such_file, 'f2'),
+ unrecognized % (not_executable, 'f2'),
unspecified % 'f2'
]
test.fail_test(not test.stderr() in errs)
if os.name == 'nt':
errs = [
bad_command,
- unrecognized % (no_such_file, 'f3'),
+ unrecognized % (test.workdir, 'f3'),
unspecified % 'f3'
]
test.fail_test(not test.stderr() in errs)
import os
import sys
import TestSCons
+import TestCmd
-test = TestSCons.TestSCons()
+test = TestSCons.TestSCons(match = TestCmd.match_re)
test.write('SConstruct', """
def func(source = None, target = None, env = None):
test.write('foo.in', "foo.in\n")
-test.run(arguments = "foo.out", stderr = "scons: *** [foo.out] Exception\n")
-
+test.run(arguments = "foo.out", stderr = """scons: \*\*\* \[foo.out\] Exception
+Traceback \((most recent call|innermost) last\):
+ File ".+", line \d+, in .+
+ .+
+ File ".+", line \d+, in .+
+ .+
+ File ".+", line \d+, in .+
+ .+
+ File "SConstruct", line 3, in func
+ raise "func exception"
+func exception
+""")
test.pass_test()