summaryrefslogtreecommitdiffstats
path: root/test/GetBuildFailures
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2015-09-21 17:03:12 (GMT)
committerWilliam Deegan <bill@baddogconsulting.com>2015-09-21 17:03:12 (GMT)
commit0941093e0e5a030faa49968457638a3a6aee7ad8 (patch)
tree6d33513c14eb6eac0531dd050de0ecca4c39bd79 /test/GetBuildFailures
downloadSCons-2.4.0.zip
SCons-2.4.0.tar.gz
SCons-2.4.0.tar.bz2
release 2.4.02.4.0
Diffstat (limited to 'test/GetBuildFailures')
-rw-r--r--test/GetBuildFailures/option-k.py109
-rw-r--r--test/GetBuildFailures/parallel.py141
-rw-r--r--test/GetBuildFailures/serial.py237
3 files changed, 487 insertions, 0 deletions
diff --git a/test/GetBuildFailures/option-k.py b/test/GetBuildFailures/option-k.py
new file mode 100644
index 0000000..b4e8d54
--- /dev/null
+++ b/test/GetBuildFailures/option-k.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+"""
+Verify that a failed build action with -k works as expected.
+"""
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+try:
+ import threading
+except ImportError:
+ # if threads are not supported, then
+ # there is nothing to test
+ TestCmd.no_result()
+ sys.exit()
+
+
+test = TestSCons.TestSCons()
+
+contents = r"""\
+import sys
+if sys.argv[0] == 'mypass.py':
+ open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
+ exit_value = 0
+elif sys.argv[0] == 'myfail.py':
+ exit_value = 1
+sys.exit(exit_value)
+"""
+
+test.write('mypass.py', contents)
+test.write('myfail.py', contents)
+
+test.write('SConstruct', """\
+Command('f3', 'f3.in', r'@%(_python_)s mypass.py - f3 $TARGET $SOURCE')
+Command('f4', 'f4.in', r'@%(_python_)s myfail.py f3 f4 $TARGET $SOURCE')
+Command('f5', 'f5.in', r'@%(_python_)s myfail.py f4 f5 $TARGET $SOURCE')
+Command('f6', 'f6.in', r'@%(_python_)s mypass.py f5 - $TARGET $SOURCE')
+
+def print_build_failures():
+ from SCons.Script import GetBuildFailures
+ for bf in sorted(GetBuildFailures(), key=lambda a: a.filename):
+ print "%%s failed: %%s" %% (bf.node, bf.errstr)
+
+import atexit
+atexit.register(print_build_failures)
+""" % locals())
+
+test.write('f3.in', "f3.in\n")
+test.write('f4.in', "f4.in\n")
+test.write('f5.in', "f5.in\n")
+test.write('f6.in', "f6.in\n")
+
+expect_stdout = """\
+scons: Reading SConscript files ...
+scons: done reading SConscript files.
+scons: Building targets ...
+scons: done building targets (errors occurred during build).
+f4 failed: Error 1
+f5 failed: Error 1
+""" % locals()
+
+expect_stderr = """\
+scons: *** [f4] Error 1
+scons: *** [f5] Error 1
+"""
+
+test.run(arguments = '-k .', status = 2, stdout=None, stderr=None)
+test.must_contain_exactly_lines(test.stdout(), expect_stdout, title='stdout')
+test.must_contain_exactly_lines(test.stderr(), expect_stderr, title='stderr')
+
+test.must_match(test.workpath('f3'), 'f3.in\n')
+test.must_not_exist(test.workpath('f4'))
+test.must_not_exist(test.workpath('f5'))
+test.must_match(test.workpath('f6'), 'f6.in\n')
+
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/GetBuildFailures/parallel.py b/test/GetBuildFailures/parallel.py
new file mode 100644
index 0000000..b7576af
--- /dev/null
+++ b/test/GetBuildFailures/parallel.py
@@ -0,0 +1,141 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+"""
+Verify that a failed build action with -j works as expected.
+"""
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+try:
+ import threading
+except ImportError:
+ # if threads are not supported, then
+ # there is nothing to test
+ TestCmd.no_result()
+ sys.exit()
+
+
+test = TestSCons.TestSCons()
+
+# We want to verify that -j 4 starts all four jobs, the first and last of
+# which fail and the second and third of which succeed, and then stops
+# processing due to the build failures. To try to control the timing,
+# the created build scripts use marker directories to avoid doing their
+# processing until the previous script has finished.
+
+contents = r"""\
+import os.path
+import sys
+import time
+wait_marker = sys.argv[1] + '.marker'
+write_marker = sys.argv[2] + '.marker'
+if wait_marker != '-.marker':
+ while not os.path.exists(wait_marker):
+ time.sleep(1)
+if sys.argv[0] == 'mypass.py':
+ open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
+ exit_value = 0
+elif sys.argv[0] == 'myfail.py':
+ exit_value = 1
+if write_marker != '-.marker':
+ os.mkdir(write_marker)
+sys.exit(exit_value)
+"""
+
+test.write('mypass.py', contents)
+test.write('myfail.py', contents)
+
+test.write('SConstruct', """\
+Command('f3', 'f3.in', r'@%(_python_)s mypass.py - f3 $TARGET $SOURCE')
+Command('f4', 'f4.in', r'@%(_python_)s myfail.py f3 f4 $TARGET $SOURCE')
+Command('f5', 'f5.in', r'@%(_python_)s myfail.py f4 f5 $TARGET $SOURCE')
+Command('f6', 'f6.in', r'@%(_python_)s mypass.py f5 - $TARGET $SOURCE')
+
+def print_build_failures():
+ from SCons.Script import GetBuildFailures
+ for bf in sorted(GetBuildFailures(), key=lambda t: t.filename):
+ print "%%s failed: %%s" %% (bf.node, bf.errstr)
+
+import atexit
+atexit.register(print_build_failures)
+""" % locals())
+
+test.write('f3.in', "f3.in\n")
+test.write('f4.in', "f4.in\n")
+test.write('f5.in', "f5.in\n")
+test.write('f6.in', "f6.in\n")
+
+test.run(arguments = '-Q -j 4 .',
+ status = 2,
+ stderr = None)
+
+f4_error = "scons: *** [f4] Error 1\n"
+f5_error = "scons: *** [f5] Error 1\n"
+
+error_45 = f4_error + f5_error
+error_54 = f5_error + f4_error
+
+if test.stderr() not in [error_45, error_54]:
+ print "Did not find the following output in list of expected strings:"
+ print test.stderr(),
+ test.fail_test()
+
+# We jump through hoops above to try to make sure that the individual
+# commands execute and exit in the order we want, but we still can't be
+# 100% sure that SCons will actually detect and record the failures in
+# that order; the thread for f5 may detect its command's failure before
+# the thread for f4. Just sidestep the issue by allowing the failure
+# strings in the output to come in either order. If there's a genuine
+# problem in the way things get ordered, it'll show up in stderr.
+
+f4_failed = "f4 failed: Error 1\n"
+f5_failed = "f5 failed: Error 1\n"
+
+failed_45 = f4_failed + f5_failed
+failed_54 = f5_failed + f4_failed
+
+if test.stdout() not in [failed_45, failed_54]:
+ print "Did not find the following output in list of expected strings:"
+ print test.stdout(),
+ test.fail_test()
+
+test.must_match(test.workpath('f3'), 'f3.in\n')
+test.must_not_exist(test.workpath('f4'))
+test.must_not_exist(test.workpath('f5'))
+test.must_match(test.workpath('f6'), 'f6.in\n')
+
+
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/GetBuildFailures/serial.py b/test/GetBuildFailures/serial.py
new file mode 100644
index 0000000..9c56bb1
--- /dev/null
+++ b/test/GetBuildFailures/serial.py
@@ -0,0 +1,237 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+"""
+Verify that the GetBuildFailures() function returns a list of
+BuildError exceptions. Also verify printing the BuildError
+attributes we expect to be most commonly used.
+"""
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import TestSCons
+import re
+
+_python_ = TestSCons._python_
+
+try:
+ import threading
+except ImportError:
+ # if threads are not supported, then
+ # there is nothing to test
+ TestCmd.no_result()
+ sys.exit()
+
+
+test = TestSCons.TestSCons()
+
+contents = r"""\
+import sys
+if sys.argv[0] == 'mypass.py':
+ open(sys.argv[3], 'wb').write(open(sys.argv[4], 'rb').read())
+ exit_value = 0
+elif sys.argv[0] == 'myfail.py':
+ exit_value = 1
+sys.exit(exit_value)
+"""
+
+test.write('mypass.py', contents)
+test.write('myfail.py', contents)
+
+test.write('SConstruct', """\
+Command('f03', 'f03.in', r'@%(_python_)s mypass.py - f03 $TARGET $SOURCE')
+Command('f04', 'f04.in', r'@%(_python_)s myfail.py f03 f04 $TARGET $SOURCE')
+Command('f05', 'f05.in', r'@%(_python_)s myfail.py f04 f05 $TARGET $SOURCE')
+Command('f06', 'f06.in', r'@%(_python_)s mypass.py f05 - $TARGET $SOURCE')
+Command('f07', 'f07.in', r'@%(_python_)s mypass.py f07 - $TARGET $SOURCE')
+
+import SCons.Errors
+def raiseExcAction(exc):
+ def action(env, target, source, exc=exc):
+ raise exc
+ return action
+def returnExcAction(exc):
+ def action(env, target, source, exc=exc):
+ return exc
+ return action
+class MyBuildError(SCons.Errors.BuildError):
+ pass
+
+Command('f08', 'f08.in', raiseExcAction(SCons.Errors.UserError("My User Error")))
+Command('f09', 'f09.in', returnExcAction(SCons.Errors.UserError("My User Error")))
+Command('f10', 'f10.in', raiseExcAction(MyBuildError(errstr="My Build Error", status=7)))
+Command('f11', 'f11.in', returnExcAction(MyBuildError(errstr="My Build Error", status=7)))
+Command('f12', 'f12.in', raiseExcAction(EnvironmentError(123, "My EnvironmentError", "f12")))
+Command('f13', 'f13.in', returnExcAction(EnvironmentError(123, "My EnvironmentError", "f13")))
+Command('f14', 'f14.in', raiseExcAction(SCons.Errors.InternalError("My InternalError")))
+Command('f15', 'f15.in', returnExcAction(SCons.Errors.InternalError("My InternalError")))
+
+def print_build_failures():
+ from SCons.Script import GetBuildFailures
+ for bf in sorted(GetBuildFailures(), key=lambda t: str(t.node)):
+ assert( isinstance(bf, SCons.Errors.BuildError) )
+ print "BF: %%s failed (%%s): %%s" %% (bf.node, bf.status, bf.errstr)
+ if bf.command:
+ print "BF: %%s" %% " ".join(Flatten(bf.command))
+
+import atexit
+atexit.register(print_build_failures)
+""" % locals())
+
+test.write('f03.in', "f03.in\n")
+test.write('f04.in', "f04.in\n")
+test.write('f05.in', "f05.in\n")
+test.write('f06.in', "f06.in\n")
+# f07.in is intentionally missing...
+test.write('f08.in', "f08.in\n")
+test.write('f09.in', "f09.in\n")
+test.write('f10.in', "f10.in\n")
+test.write('f11.in', "f11.in\n")
+test.write('f12.in', "f12.in\n")
+test.write('f13.in', "f13.in\n")
+test.write('f14.in', "f14.in\n")
+test.write('f15.in', "f15.in\n")
+
+expect_stdout = """\
+scons: Reading SConscript files ...
+scons: done reading SConscript files.
+scons: Building targets ...
+scons: building terminated because of errors.
+BF: f04 failed (1): Error 1
+BF: %(_python_)s myfail.py f03 f04 "f04" "f04.in"
+""" % locals()
+
+expect_stderr = """\
+scons: *** [f04] Error 1
+"""
+
+test.run(arguments = '.',
+ status = 2,
+ stdout = expect_stdout,
+ stderr = expect_stderr)
+
+test.must_match(test.workpath('f03'), 'f03.in\n')
+test.must_not_exist(test.workpath('f04'))
+test.must_not_exist(test.workpath('f05'))
+test.must_not_exist(test.workpath('f06'))
+test.must_not_exist(test.workpath('f07'))
+test.must_not_exist(test.workpath('f08'))
+test.must_not_exist(test.workpath('f09'))
+test.must_not_exist(test.workpath('f10'))
+test.must_not_exist(test.workpath('f11'))
+test.must_not_exist(test.workpath('f12'))
+test.must_not_exist(test.workpath('f13'))
+test.must_not_exist(test.workpath('f14'))
+test.must_not_exist(test.workpath('f15'))
+
+
+expect_stdout = re.escape("""\
+scons: Reading SConscript files ...
+scons: done reading SConscript files.
+scons: Building targets ...
+action(["f08"], ["f08.in"])
+action(["f09"], ["f09.in"])
+action(["f10"], ["f10.in"])
+action(["f11"], ["f11.in"])
+action(["f12"], ["f12.in"])
+action(["f13"], ["f13.in"])
+action(["f14"], ["f14.in"])
+action(["f15"], ["f15.in"])
+scons: done building targets (errors occurred during build).
+BF: f04 failed (1): Error 1
+BF: %(_python_)s myfail.py f03 f04 "f04" "f04.in"
+BF: f05 failed (1): Error 1
+BF: %(_python_)s myfail.py f04 f05 "f05" "f05.in"
+BF: f07 failed (2): Source `f07.in' not found, needed by target `f07'.
+BF: f08 failed (2): My User Error
+BF: action(["f08"], ["f08.in"])
+BF: f09 failed (2): My User Error
+BF: action(["f09"], ["f09.in"])
+BF: f10 failed (7): My Build Error
+BF: action(["f10"], ["f10.in"])
+BF: f11 failed (7): My Build Error
+BF: action(["f11"], ["f11.in"])
+BF: f12 failed (123): My EnvironmentError
+BF: action(["f12"], ["f12.in"])
+BF: f13 failed (123): My EnvironmentError
+BF: action(["f13"], ["f13.in"])
+BF: f14 failed (2): InternalError : My InternalError
+BF: action(["f14"], ["f14.in"])
+BF: f15 failed (2): InternalError : My InternalError
+BF: action(["f15"], ["f15.in"])
+""" % locals())
+
+expect_stderr = re.escape("""\
+scons: *** [f04] Error 1
+scons: *** [f05] Error 1
+scons: *** [f07] Source `f07.in' not found, needed by target `f07'.
+scons: *** [f08] My User Error
+scons: *** [f09] My User Error
+scons: *** [f10] My Build Error
+scons: *** [f11] My Build Error
+scons: *** [f12] f12: My EnvironmentError
+scons: *** [f13] f13: My EnvironmentError
+scons: *** [f14] InternalError : My InternalError
+""") + \
+"""\
+Traceback \((most recent call|innermost) last\):
+( File ".+", line \d+, in \S+
+ [^\n]+
+)*( File ".+", line \d+, in \S+
+)*( File ".+", line \d+, in \S+
+ [^\n]+
+)*\S.+
+""" + \
+re.escape("""\
+scons: *** [f15] InternalError : My InternalError
+""")
+
+test.run(arguments = '-k .',
+ status = 2,
+ stdout = expect_stdout,
+ stderr = expect_stderr,
+ match = TestSCons.match_re_dotall)
+
+test.must_match(test.workpath('f03'), 'f03.in\n')
+test.must_not_exist(test.workpath('f04'))
+test.must_not_exist(test.workpath('f05'))
+test.must_match(test.workpath('f06'), 'f06.in\n')
+test.must_not_exist(test.workpath('f07'))
+test.must_not_exist(test.workpath('f08'))
+test.must_not_exist(test.workpath('f09'))
+test.must_not_exist(test.workpath('f10'))
+test.must_not_exist(test.workpath('f11'))
+test.must_not_exist(test.workpath('f12'))
+test.must_not_exist(test.workpath('f13'))
+test.must_not_exist(test.workpath('f14'))
+test.must_not_exist(test.workpath('f15'))
+
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: