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