http://scons.tigris.org/issues/show_bug.cgi?id=2345
[scons.git] / src / engine / SCons / ErrorsTests.py
1 #
2 # __COPYRIGHT__
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
23
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25
26 import sys
27 import unittest
28 import SCons.Errors
29
30
31 class ErrorsTestCase(unittest.TestCase):
32     def test_BuildError(self):
33         """Test the BuildError exception."""
34         try:
35             raise SCons.Errors.BuildError(
36                 errstr = "foo", status=57, filename="file", exc_info=(1,2,3),
37                 node = "n", executor="e", action="a", command="c")
38         except SCons.Errors.BuildError, e:
39             assert e.errstr == "foo"
40             assert e.status == 57
41             assert e.exitstatus == 2, e.exitstatus
42             assert e.filename == "file"
43             assert e.exc_info == (1,2,3)
44
45             assert e.node == "n"
46             assert e.executor == "e"
47             assert e.action == "a"
48             assert e.command == "c"
49
50         try:
51             raise SCons.Errors.BuildError("n", "foo", 57, 3, "file", 
52                                           "e", "a", "c", (1,2,3))
53         except SCons.Errors.BuildError, e:
54             assert e.errstr == "foo", e.errstr
55             assert e.status == 57, e.status
56             assert e.exitstatus == 3, e.exitstatus
57             assert e.filename == "file", e.filename
58             assert e.exc_info == (1,2,3), e.exc_info
59
60             assert e.node == "n"
61             assert e.executor == "e"
62             assert e.action == "a"
63             assert e.command == "c"
64
65         try:
66             raise SCons.Errors.BuildError()
67         except SCons.Errors.BuildError, e:
68             assert e.errstr == "Unknown error"
69             assert e.status == 2
70             assert e.exitstatus == 2
71             assert e.filename is None
72             assert e.exc_info == (None, None, None)
73
74             assert e.node is None
75             assert e.executor is None
76             assert e.action is None
77             assert e.command is None
78
79     def test_InternalError(self):
80         """Test the InternalError exception."""
81         try:
82             raise SCons.Errors.InternalError("test internal error")
83         except SCons.Errors.InternalError, e:
84             assert e.args == ("test internal error",)
85
86     def test_UserError(self):
87         """Test the UserError exception."""
88         try:
89             raise SCons.Errors.UserError("test user error")
90         except SCons.Errors.UserError, e:
91             assert e.args == ("test user error",)
92
93     def test_ExplicitExit(self):
94         """Test the ExplicitExit exception."""
95         try:
96             raise SCons.Errors.ExplicitExit("node")
97         except SCons.Errors.ExplicitExit, e:
98             assert e.node == "node"
99
100 if __name__ == "__main__":
101     suite = unittest.makeSuite(ErrorsTestCase, 'test_')
102     if not unittest.TextTestRunner().run(suite).wasSuccessful():
103         sys.exit(1)
104
105 # Local Variables:
106 # tab-width:4
107 # indent-tabs-mode:nil
108 # End:
109 # vim: set expandtab tabstop=4 shiftwidth=4: