Added fix for TeX includes with same name as subdirs.
[scons.git] / test / exceptions.py
index 04b9988caba5ab24864dab1ef01f5108eedbe108..79d869c4301c4a869f3cb21f078523940762486b 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright (c) 2001, 2002, 2003 Steven Knight
+# __COPYRIGHT__
 #
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import os
-import sys
+import re
+
 import TestSCons
-import TestCmd
 
-test = TestSCons.TestSCons(match = TestCmd.match_re_dotall)
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
+
+SConstruct_path = test.workpath('SConstruct')
 
-test.write('SConstruct', """
+test.write(SConstruct_path, """\
 def func(source = None, target = None, env = None):
-    raise "func exception"
+    raise Exception("func exception")
 B = Builder(action = func)
 env = Environment(BUILDERS = { 'B' : B })
 env.B(target = 'foo.out', source = 'foo.in')
@@ -41,15 +44,88 @@ env.B(target = 'foo.out', source = 'foo.in')
 
 test.write('foo.in', "foo.in\n")
 
-test.run(arguments = "foo.out", stderr = """scons: \*\*\* \[foo.out\] Exception
+expected_stderr = r"""scons: \*\*\* \[foo.out\] Exception : func exception
 Traceback \((most recent call|innermost) last\):
-  File ".+", line \d+, in \S+
+(  File ".+", line \d+, in \S+
     [^\n]+
-  File ".+", line \d+, in \S+
+)*(  File ".+", line \d+, in \S+
+)*(  File ".+", line \d+, in \S+
     [^\n]+
-  File "SConstruct", line 3, in func
-    raise "func exception"
-func exception
-""", status = 2)
+)*  File "%s", line 2, in func
+    raise Exception\("func exception"\)
+Exception: func exception
+""" % re.escape(SConstruct_path)
+
+test.run(arguments = "foo.out", stderr = expected_stderr, status = 2)
+
+test.run(arguments = "-j2 foo.out", stderr = expected_stderr, status = 2)
+
+
+# Verify that exceptions caused by exit values of builder actions are
+# correctly signalled, for both Serial and Parallel jobs.
+
+test.write('myfail.py', r"""\
+import sys
+sys.exit(1)
+""")
+
+test.write(SConstruct_path, """
+Fail = Builder(action = r'%(_python_)s myfail.py $TARGETS $SOURCE')
+env = Environment(BUILDERS = { 'Fail' : Fail })
+env.Fail(target = 'out.f1', source = 'in.f1')
+""" % locals())
+
+test.write('in.f1', "in.f1\n")
+
+expected_stderr = "scons: \\*\\*\\* \\[out.f1\\] Error 1\n"
+
+test.run(arguments = '.', status = 2, stderr = expected_stderr)
+test.run(arguments = '-j2 .', status = 2, stderr = expected_stderr)
+
+
+# Verify that all exceptions from simultaneous tasks are reported,
+# even if the exception is raised during the Task.prepare()
+# [Node.prepare()]
+
+test.write(SConstruct_path, """
+Fail = Builder(action = r'%(_python_)s myfail.py $TARGETS $SOURCE')
+env = Environment(BUILDERS = { 'Fail' : Fail })
+env.Fail(target = 'out.f1', source = 'in.f1')
+env.Fail(target = 'out.f2', source = 'in.f2')
+env.Fail(target = 'out.f3', source = 'in.f3')
+""" % locals())
+
+# in.f2 is not created to cause a Task.prepare exception
+test.write('in.f1', 'in.f1\n')
+test.write('in.f3', 'in.f3\n')
+
+# In Serial task mode, get the first exception and stop
+test.run(arguments = '.', status = 2, stderr = expected_stderr)
+
+# In Parallel task mode, we will get all three exceptions.
+
+expected_stderr_list = [
+    "scons: *** [out.f1] Error 1\n",
+    "scons: *** [out.f2] Source `in.f2' not found, needed by target `out.f2'.\n",
+    "scons: *** [out.f3] Error 1\n",
+]
+
+# To get all three exceptions simultaneously, we execute -j7 to create
+# one thread each for the SConstruct file and {in,out}.f[123].  Note that
+# it's important that the input (source) files sort earlier alphabetically
+# than the output files, so they're visited first in the dependency graph
+# walk of '.' and are already considered up-to-date when we kick off the
+# "simultaneous" builds of the output (target) files.
+
+test.run(arguments = '-j7 -k .', status = 2, stderr = None)
+
+test.must_contain_all_lines(test.stderr(), expected_stderr_list)
+
 
 test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: