Update Copyright years.
[scons.git] / test / builderrors.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2001, 2002, 2003 Steven Knight
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 import os
28 import sys
29 import TestSCons
30
31 python = TestSCons.python
32
33 test = TestSCons.TestSCons()
34
35 test.subdir('one', 'two', 'three')
36
37 test.write('build.py', r"""
38 import sys
39 exitval = int(sys.argv[1])
40 if exitval == 0:
41     contents = open(sys.argv[3], 'rb').read()
42     file = open(sys.argv[2], 'wb')
43     file.write(contents)
44     file.close()
45 sys.exit(exitval)
46 """)
47
48 test.write(['one', 'SConstruct'], """
49 B0 = Builder(action = r'%s ../build.py 0 $TARGET $SOURCES')
50 B1 = Builder(action = r'%s ../build.py 1 $TARGET $SOURCES')
51 env = Environment(BUILDERS = { 'B0' : B0, 'B1' : B1 })
52 env.B1(target = 'f1.out', source = 'f1.in')
53 env.B0(target = 'f2.out', source = 'f2.in')
54 env.B0(target = 'f3.out', source = 'f3.in')
55 """ % (python, python))
56
57 test.write(['one', 'f1.in'], "one/f1.in\n")
58 test.write(['one', 'f2.in'], "one/f2.in\n")
59 test.write(['one', 'f3.in'], "one/f3.in\n")
60
61 test.run(chdir = 'one', arguments = "f1.out f2.out f3.out",
62          stderr = "scons: *** [f1.out] Error 1\n", status = 2)
63
64 test.fail_test(os.path.exists(test.workpath('f1.out')))
65 test.fail_test(os.path.exists(test.workpath('f2.out')))
66 test.fail_test(os.path.exists(test.workpath('f3.out')))
67
68 test.write(['two', 'SConstruct'], """
69 B0 = Builder(action = r'%s ../build.py 0 $TARGET $SOURCES')
70 B1 = Builder(action = r'%s ../build.py 1 $TARGET $SOURCES')
71 env = Environment(BUILDERS = { 'B0': B0, 'B1' : B1 })
72 env.B0(target = 'f1.out', source = 'f1.in')
73 env.B1(target = 'f2.out', source = 'f2.in')
74 env.B0(target = 'f3.out', source = 'f3.in')
75 """ % (python, python))
76
77 test.write(['two', 'f1.in'], "two/f1.in\n")
78 test.write(['two', 'f2.in'], "two/f2.in\n")
79 test.write(['two', 'f3.in'], "two/f3.in\n")
80
81 test.run(chdir = 'two', arguments = "f1.out f2.out f3.out",
82          stderr = "scons: *** [f2.out] Error 1\n", status = 2)
83
84 test.fail_test(test.read(['two', 'f1.out']) != "two/f1.in\n")
85 test.fail_test(os.path.exists(test.workpath('f2.out')))
86 test.fail_test(os.path.exists(test.workpath('f3.out')))
87
88 test.write(['three', 'SConstruct'], """
89 B0 = Builder(action = r'%s ../build.py 0 $TARGET $SOURCES')
90 B1 = Builder(action = r'%s ../build.py 1 $TARGET $SOURCES')
91 env = Environment(BUILDERS = { 'B0' : B0, 'B1': B1 })
92 env.B0(target = 'f1.out', source = 'f1.in')
93 env.B0(target = 'f2.out', source = 'f2.in')
94 env.B1(target = 'f3.out', source = 'f3.in')
95 """ % (python, python))
96
97 test.write(['three', 'f1.in'], "three/f1.in\n")
98 test.write(['three', 'f2.in'], "three/f2.in\n")
99 test.write(['three', 'f3.in'], "three/f3.in\n")
100
101 test.run(chdir = 'three', arguments = "f1.out f2.out f3.out",
102          stderr = "scons: *** [f3.out] Error 1\n", status = 2)
103
104 test.fail_test(test.read(['three', 'f1.out']) != "three/f1.in\n")
105 test.fail_test(test.read(['three', 'f2.out']) != "three/f2.in\n")
106 test.fail_test(os.path.exists(test.workpath('f3.out')))
107
108 test.pass_test()