From: stevenknight Date: Mon, 4 Feb 2002 04:44:14 +0000 (+0000) Subject: Make scons return an error code (Anthony Roach) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=76593f6ee1825786e7e2ff20d071f24158266659;p=scons.git Make scons return an error code (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@242 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/etc/TestSCons.py b/etc/TestSCons.py index 956b4545..14c2e0b6 100644 --- a/etc/TestSCons.py +++ b/etc/TestSCons.py @@ -68,7 +68,7 @@ class TestSCons(TestCmd.TestCmd): apply(TestCmd.TestCmd.__init__, [self], kw) os.chdir(self.workdir) - def run(self, stdout = None, stderr = '', **kw): + def run(self, stdout = None, stderr = '', status = 0, **kw): """Runs SCons. This is the same as the base TestCmd.run() method, with @@ -82,6 +82,10 @@ class TestSCons(TestCmd.TestCmd): the command. A value of None means don't test error output. + status The expected exit status from the + command. + + By default, this does not test standard output (stdout = None), and expects that error output is empty (stderr = ""). """ @@ -93,7 +97,7 @@ class TestSCons(TestCmd.TestCmd): print "STDERR ============" print self.stderr() raise - if self.status: + if self.status>>8 != status: print "%s returned %d" % (self.program, self.status >> 8) print "STDERR ============" print self.stderr() diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 842e7eef..93ba795c 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -136,6 +136,7 @@ def _scons_syntax_error(e): lines = traceback.format_exception_only(etype, value) for line in lines: sys.stderr.write(line+'\n') + sys.exit(2) def _scons_user_error(e): """Handle user errors. Print out a message and a description of the @@ -149,6 +150,7 @@ def _scons_user_error(e): routine = tb.tb_frame.f_code.co_name sys.stderr.write("\nSCons error: %s\n" % value) sys.stderr.write('File "%s", line %d, in %s\n' % (filename, lineno, routine)) + sys.exit(2) def _scons_user_warning(e): """Handle user warnings. Print out a message and a description of @@ -169,7 +171,7 @@ def _scons_other_errors(): """ print 'other errors' traceback.print_exc() - + sys.exit(2) # @@ -700,6 +702,7 @@ def main(): pass except KeyboardInterrupt: print "Build interrupted." + sys.exit(1) except SyntaxError, e: _scons_syntax_error(e) except UserError, e: diff --git a/test/SConstruct.py b/test/SConstruct.py index 60df1e9e..de5b72ed 100644 --- a/test/SConstruct.py +++ b/test/SConstruct.py @@ -33,7 +33,7 @@ test.run(stdout = "", stderr = r""" SCons error: No SConstruct file found. File "\S+", line \d+, in \S+ -""") +""", status=2) test.match_func = TestCmd.match_exact diff --git a/test/dependency-cycle.py b/test/dependency-cycle.py index abdd50da..3be8da43 100644 --- a/test/dependency-cycle.py +++ b/test/dependency-cycle.py @@ -50,7 +50,7 @@ f1(void) test.run(arguments = ".", stdout = "", stderr=r""" SCons error: Dependency cycle: .*foo1.* -> .*foo3.* -> .*foo2.* -> .*foo1.* -> \. .* -""") +""", status=2) test.pass_test() diff --git a/test/errors.py b/test/errors.py index f8c5506e..1f582f78 100644 --- a/test/errors.py +++ b/test/errors.py @@ -43,7 +43,7 @@ test.run(arguments='-f SConstruct1', SyntaxError: invalid syntax -""") +""", status=2) test.write('SConstruct2', """ @@ -57,7 +57,7 @@ test.run(arguments='-f SConstruct2', stderr = """ SCons error: Depends\(\) require both sources and targets. File "SConstruct2", line 4, in \? -""") +""", status=2) test.write('SConstruct3', """ assert not globals().has_key("InternalError") @@ -77,6 +77,6 @@ test.run(arguments='-f SConstruct3', File "SConstruct3", line \d+, in \? raise InternalError, 'error inside' InternalError: error inside -""") +""", status=2) test.pass_test()