|
1 |
| -#!/usr/bin/env python |
2 |
| -# |
3 |
| -# __COPYRIGHT__ |
4 |
| -# |
5 |
| -# Permission is hereby granted, free of charge, to any person obtaining |
6 |
| -# a copy of this software and associated documentation files (the |
7 |
| -# "Software"), to deal in the Software without restriction, including |
8 |
| -# without limitation the rights to use, copy, modify, merge, publish, |
9 |
| -# distribute, sublicense, and/or sell copies of the Software, and to |
10 |
| -# permit persons to whom the Software is furnished to do so, subject to |
11 |
| -# the following conditions: |
12 |
| -# |
13 |
| -# The above copyright notice and this permission notice shall be included |
14 |
| -# in all copies or substantial portions of the Software. |
15 |
| -# |
16 |
| -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
17 |
| -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
18 |
| -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
19 |
| -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
20 |
| -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
21 |
| -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
22 |
| -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
23 |
| -# |
24 |
| - |
25 |
| -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" |
26 |
| - |
27 |
| -""" |
28 |
| -Verify that setting exitstatfunc on an Action works as advertised. |
29 |
| -""" |
30 |
| - |
31 |
| -import TestSCons |
32 |
| - |
33 |
| -test = TestSCons.TestSCons() |
34 |
| - |
35 |
| -test.write('SConstruct', """\ |
36 |
| -def always_succeed(s): |
37 |
| - # Always return 0, which indicates success. |
38 |
| - return 0 |
39 |
| -
|
40 |
| -def copy_fail(target, source, env): |
41 |
| - with open(str(source[0]), 'rb') as infp, open(str(target[0]), 'wb') as f: |
42 |
| - f.write(infp.read()) |
43 |
| - return 2 |
44 |
| -
|
45 |
| -a = Action(copy_fail, exitstatfunc=always_succeed) |
46 |
| -Alias('test1', Command('test1.out', 'test1.in', a)) |
47 |
| -
|
48 |
| -def fail(target, source, env): |
49 |
| - return 2 |
50 |
| -
|
51 |
| -t2 = Command('test2.out', 'test2.in', Copy('$TARGET', '$SOURCE')) |
52 |
| -AddPostAction(t2, Action(fail, exitstatfunc=always_succeed)) |
53 |
| -Alias('test2', t2) |
54 |
| -""") |
55 |
| - |
56 |
| -test.write('test1.in', "test1.in\n") |
57 |
| -test.write('test2.in', "test2.in\n") |
58 |
| - |
59 |
| -test.run(arguments = 'test1') |
60 |
| - |
61 |
| -test.must_match('test1.out', "test1.in\n") |
62 |
| - |
63 |
| -test.run(arguments = 'test2') |
64 |
| - |
65 |
| -test.must_match('test2.out', "test2.in\n") |
66 |
| - |
67 |
| -test.pass_test() |
68 |
| - |
69 |
| -# Local Variables: |
70 |
| -# tab-width:4 |
71 |
| -# indent-tabs-mode:nil |
72 |
| -# End: |
73 |
| -# vim: set expandtab tabstop=4 shiftwidth=4: |
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# MIT License |
| 4 | +# |
| 5 | +# Copyright The SCons Foundation |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining |
| 8 | +# a copy of this software and associated documentation files (the |
| 9 | +# "Software"), to deal in the Software without restriction, including |
| 10 | +# without limitation the rights to use, copy, modify, merge, publish, |
| 11 | +# distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | +# permit persons to whom the Software is furnished to do so, subject to |
| 13 | +# the following conditions: |
| 14 | +# |
| 15 | +# The above copyright notice and this permission notice shall be included |
| 16 | +# in all copies or substantial portions of the Software. |
| 17 | +# |
| 18 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
| 19 | +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 20 | +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 22 | +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | + |
| 26 | +""" |
| 27 | +Verify that setting exitstatfunc on an Action works as advertised. |
| 28 | +""" |
| 29 | + |
| 30 | +import TestSCons |
| 31 | + |
| 32 | +test = TestSCons.TestSCons() |
| 33 | + |
| 34 | +test.write('SConstruct', """\ |
| 35 | +DefaultEnvironment(tools=[]) |
| 36 | +def always_succeed(s): |
| 37 | + # Always return 0, which indicates success. |
| 38 | + return 0 |
| 39 | +
|
| 40 | +def copy_fail(target, source, env): |
| 41 | + with open(str(source[0]), 'rb') as infp, open(str(target[0]), 'wb') as f: |
| 42 | + f.write(infp.read()) |
| 43 | + return 2 |
| 44 | +
|
| 45 | +a = Action(copy_fail, exitstatfunc=always_succeed) |
| 46 | +Alias('test1', Command('test1.out', 'test1.in', a)) |
| 47 | +
|
| 48 | +def fail(target, source, env): |
| 49 | + return 2 |
| 50 | +
|
| 51 | +t2 = Command('test2.out', 'test2.in', Copy('$TARGET', '$SOURCE')) |
| 52 | +AddPostAction(t2, Action(fail, exitstatfunc=always_succeed)) |
| 53 | +Alias('test2', t2) |
| 54 | +""") |
| 55 | + |
| 56 | +test.write('test1.in', "test1.in\n") |
| 57 | +test.write('test2.in', "test2.in\n") |
| 58 | + |
| 59 | +test.run(arguments = 'test1') |
| 60 | + |
| 61 | +test.must_match('test1.out', "test1.in\n") |
| 62 | + |
| 63 | +test.run(arguments = 'test2') |
| 64 | + |
| 65 | +test.must_match('test2.out', "test2.in\n") |
| 66 | + |
| 67 | +test.pass_test() |
| 68 | + |
| 69 | +# Local Variables: |
| 70 | +# tab-width:4 |
| 71 | +# indent-tabs-mode:nil |
| 72 | +# End: |
| 73 | +# vim: set expandtab tabstop=4 shiftwidth=4: |
0 commit comments