Move 2.0 changes collected in branches/pending back to trunk for further
[scons.git] / test / QT / warnings.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 Qt tool warnings.
29 """
30
31 import os
32 import re
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 SConstruct_path = test.workpath('SConstruct')
39
40 test.Qt_dummy_installation()
41
42 test.Qt_create_SConstruct(SConstruct_path)
43
44 test.write('aaa.cpp', r"""
45 #include "my_qobject.h"
46 void aaa(void) Q_OBJECT
47 """)
48
49 test.write('SConscript', r"""
50 Import("env")
51 import os
52 env.StaticLibrary('aaa.cpp')
53 """)
54
55 test.run(stderr=None)
56
57 match12 = r"""
58 scons: warning: Generated moc file 'aaa.moc' is not included by 'aaa.cpp'
59 """ + TestSCons.file_expr
60
61 if not re.search(match12, test.stderr()):
62     print "Did not find expected regular expression in stderr:"
63     print test.stderr()
64     test.fail_test()
65
66 os.environ['QTDIR'] = test.QT
67
68 test.run(arguments='-n noqtdir=1')
69
70 # We'd like to eliminate $QTDIR from the environment as follows:
71 #       del os.environ['QTDIR']
72 # But unfortunately, in at least some versions of Python, the Environment
73 # class doesn't implement a __delitem__() method to make the library
74 # call to actually remove the deleted variable from the *external*
75 # environment, so it only gets removed from the Python dictionary.
76 # Consequently, we need to just wipe out its value as follows>
77 os.environ['QTDIR'] = ''
78 test.run(stderr=None, arguments='-n noqtdir=1')
79
80 moc = test.where_is('moc')
81 if moc:
82     import os.path
83     qtdir = os.path.dirname(os.path.dirname(moc))
84     qtdir = qtdir.replace('\\', '\\\\' )
85
86     expect = """
87 scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%s\)
88 File "%s", line \d+, in (\?|<module>)
89 """ % (qtdir, re.escape(SConstruct_path))
90 else:
91
92     expect = r"""
93 scons: warning: Could not detect qt, using empty QTDIR
94 File "%s", line \d+, in (\?|<module>)
95 """ % re.escape(SConstruct_path)
96
97 test.fail_test(not test.match_re(test.stderr(), expect))
98
99 test.pass_test()
100
101 # Local Variables:
102 # tab-width:4
103 # indent-tabs-mode:nil
104 # End:
105 # vim: set expandtab tabstop=4 shiftwidth=4: