Merged revisions 2527-2645 via svnmerge from
[scons.git] / test / option--warn.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 import os.path
28 import sys
29
30 import TestSCons
31 import TestCmd
32
33 test = TestSCons.TestSCons(match = TestCmd.match_re_dotall)
34
35 # How to warn about deprecated features (whenever we have one again).
36 #
37 #test.write("SConstruct","""
38 #b=Builder(name='b', action='foo')
39 #""")
40 #
41 #test.run(arguments='.', stderr=r"""
42 #scons: warning: The use of the 'name' parameter to Builder\(\) is deprecated\.
43 #File "SConstruct", line 2, in \?
44 #""")
45 #
46 #test.run(arguments='--warn=no-deprecated .', stderr='')
47 #
48 #test.run(arguments='--warn=no-all .', stderr='')
49 #
50 #test.run(arguments='--warn=no-all --warn=deprecated .', stderr=r"""
51 #scons: warning: The use of the 'name' parameter to Builder\(\) is deprecated\.
52 #File "SConstruct", line 2, in \?
53 #""")
54
55
56
57 test.write("SConstruct", """\
58 import SCons.Defaults
59
60 def build(target, source, env):
61     pass
62
63 env=Environment()
64 env['BUILDERS']['test'] = Builder(action=build,
65                                   source_scanner=SCons.Defaults.ObjSourceScan)
66 env.test(target='foo', source='foo.c')
67 """)
68
69 test.write("foo.c","""
70 #include "not_there.h"
71 """)
72
73 test.run(arguments='--warn=dependency .', stderr=r"""
74 scons: warning: No dependency generated for file: not_there\.h \(included from: foo\.c\) \-\- file not found
75 """ + TestSCons.file_expr)
76
77 test.run(arguments='--warn=all .', stderr=r"""
78 scons: warning: No dependency generated for file: not_there\.h \(included from: foo\.c\) \-\- file not found
79 """ + TestSCons.file_expr)
80
81 test.run(arguments='--warn=all --warn=no-dependency .', stderr="")
82
83 test.run(arguments='--warn=no-dependency --warn=all .', stderr=r"""
84 scons: warning: No dependency generated for file: not_there\.h \(included from: foo\.c\) \-\- file not found
85 """ + TestSCons.file_expr)
86
87
88
89 test.write("SConstruct", """\
90 def build(target, source, env):
91     pass
92
93 env=Environment()
94 env['BUILDERS']['test'] = Builder(action=build)
95 env.test(target='foo', source='foo.c')
96 SConscript('no_such_file')
97 """)
98
99 test.run(arguments = '--warn=missing-sconscript .', stderr = r"""
100 scons: warning: Ignoring missing SConscript 'no_such_file'
101 """ + TestSCons.file_expr)
102
103 test.run(arguments = '--warn=no-missing-sconscript .', stderr = "")
104
105
106
107 test.write('SConstruct', """
108 def build(env, target, source):
109     file = open(str(target[0]), 'wb')
110     for s in source:
111         file.write(open(str(s), 'rb').read())
112
113 B = Builder(action=build, multi=1)
114 env = Environment(BUILDERS = { 'B' : B })
115 env2 = env.Clone(DIFFERENT_VARIABLE = 'true')
116 env.B(target = 'file1.out', source = 'file1a.in')
117 env2.B(target = 'file1.out', source = 'file1b.in')
118 """)
119
120 test.write('file1a.in', 'file1a.in\n')
121 test.write('file1b.in', 'file1b.in\n')
122
123 test.run(arguments='file1.out', 
124          stderr=r"""
125 scons: warning: Two different environments were specified for target file1.out,
126 \tbut they appear to have the same action: build\(target, source, env\)
127 """ + TestSCons.file_expr)
128
129 test.must_match('file1.out', "file1a.in\nfile1b.in\n")
130
131 test.run(arguments='--warn=duplicate-environment file1.out', 
132          stderr=r"""
133 scons: warning: Two different environments were specified for target file1.out,
134 \tbut they appear to have the same action: build\(target, source, env\)
135 """ + TestSCons.file_expr)
136
137 test.run(arguments='--warn=no-duplicate-environment file1.out')
138
139
140
141 test.write('SConstruct', """
142 def build(env, target, source):
143     file = open(str(target[0]), 'wb')
144     for s in source:
145         file.write(open(str(s), 'rb').read())
146
147 B = Builder(action=build, multi=1)
148 env = Environment(BUILDERS = { 'B' : B })
149 env.B(targets = 'file3a.out', source = 'file3a.in')
150 env.B(target = 'file3b.out', sources = 'file3b.in')
151 """)
152
153 test.write('file3a.in', 'file3a.in\n')
154 test.write('file3b.out', 'file3b.out\n')
155
156 test.run(arguments='.', 
157          stderr=r"""
158 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
159 """ + TestSCons.file_expr + r"""
160 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
161 """ + TestSCons.file_expr)
162
163 test.must_match(['file3a'], 'file3a.in\n')
164 test.must_match(['file3b'], 'file3b.out\n')
165
166 test.run(arguments='--warn=misleading-keywords .', 
167          stderr=r"""
168 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
169 """ + TestSCons.file_expr + r"""\
170 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
171 """ + TestSCons.file_expr)
172
173 test.run(arguments='--warn=no-misleading-keywords .')
174
175
176 test.pass_test()