Add documentation for MSVC_USE_SCRIPT.
[scons.git] / test / BadBuilder.py
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 Test the ability to catch Builder creation with poorly specified Actions.
29 """
30
31 import os.path
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 SConstruct_path = test.workpath('SConstruct')
38
39 sconstruct = """
40 def buildop(env, source, target):
41     outf = open(str(target[0]), 'wb')
42     inpf = open(str(source[0]), 'r')
43     for line in inpf.readlines():
44         if line.find(str(target[0])) == -1:
45             outf.write(line)
46     inpf.close()
47     outf.close()
48 b1 = Builder(action=buildop, src_suffix='.a', suffix='.b')
49 %s
50 env=Environment(tools=[], BUILDERS={'b1':b1, 'b2':b2})
51 foo_b = env.b1(source='foo.a')
52 env.b2(source=foo_b)
53 """
54
55 test.write('foo.a', """\
56 foo.c
57 foo.b
58 built
59 """)
60
61 python_file_line = test.python_file_line(SConstruct_path, 14)
62
63 ### Gross mistake in Builder spec
64
65 test.write(SConstruct_path, sconstruct % '\
66 b2 = Builder(act__ion=buildop, src_suffix=".b", suffix=".c")')
67
68 expect_stderr = """\
69
70 scons: *** Builder b2 must have an action to build ['foo.c'].
71 """ + python_file_line
72
73 test.run(arguments='.', stderr=expect_stderr, status = 2)
74
75 ### Subtle mistake in Builder spec
76
77 test.write(SConstruct_path, sconstruct % '\
78 b2 = Builder(actoin=buildop, src_suffix=".b", suffix=".c")')
79
80 expect_stderr="""\
81
82 scons: *** Builder b2 must have an action to build ['foo.c'].
83 """ + python_file_line
84
85 test.run(arguments='test2', stderr=expect_stderr, status=2)
86
87 ### Missing action in Builder spec
88
89 test.write(SConstruct_path, sconstruct % '\
90 b2 = Builder(src_suffix=".b", suffix=".c")')
91
92 expect_stderr = """\
93
94 scons: *** Builder b2 must have an action to build ['foo.c'].
95 """ + python_file_line
96
97 test.run(arguments='test2', stderr=expect_stderr, status = 2)
98
99
100 test.pass_test()
101
102 # Local Variables:
103 # tab-width:4
104 # indent-tabs-mode:nil
105 # End:
106 # vim: set expandtab tabstop=4 shiftwidth=4: