Make scons return an error code (Anthony Roach)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 4 Feb 2002 04:44:14 +0000 (04:44 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 4 Feb 2002 04:44:14 +0000 (04:44 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@242 fdb21ef1-2011-0410-befe-b5e4ea1792b1

etc/TestSCons.py
src/engine/SCons/Script/__init__.py
test/SConstruct.py
test/dependency-cycle.py
test/errors.py

index 956b45457a2072d4d61c062861e86e088a1789ac..14c2e0b6b28038b481e2780be5ca56b32b3c7df0 100644 (file)
@@ -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()
index 842e7eefb802b90e050fabe05f4c88ddc8ee8d21..93ba795c4ff311f4edeabae4765f2e012128027e 100644 (file)
@@ -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:
index 60df1e9ed1f3dfe1f42487987d3c0e292df1c203..de5b72eda882977ff66a582d9db1b9f7621294e0 100644 (file)
@@ -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
 
index abdd50da7f8287d51d36f6509d82e578fbdc930f..3be8da4344c61940e579ef49740fe5f766a63e1b 100644 (file)
@@ -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()
index f8c5506e339267bba9ebc9eb7afe1b5351095e81..1f582f7862f685527b8eef98e5f52d0b72edb328 100644 (file)
@@ -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()