7b41360686d50688c2ce9e0b199835fa68955987
[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 string
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 test.Qt_dummy_installation()
39
40 test.Qt_create_SConstruct('SConstruct')
41
42 test.write('aaa.cpp', r"""
43 #include "my_qobject.h"
44 void aaa(void) Q_OBJECT
45 """)
46
47 test.write('SConscript', r"""
48 Import("env")
49 import os
50 env.StaticLibrary('aaa.cpp')
51 """)
52
53 test.run(stderr=None)
54
55 match12 = r"""
56 scons: warning: Generated moc file 'aaa.moc' is not included by 'aaa.cpp'
57 """ + TestSCons.file_expr
58
59 # In case 'ar' gives a warning about creating a library.
60 test.fail_test(not test.match_re(test.stderr(), match12) and \
61                not test.match_re(test.stderr(), match12 + ".+\n"))
62
63 os.environ['QTDIR'] = test.QT
64
65 test.run(arguments='-n noqtdir=1')
66
67 # We'd like to eliminate $QTDIR from the environment as follows:
68 #       del os.environ['QTDIR']
69 # But unfortunately, in at least some versions of Python, the Environment
70 # class doesn't implement a __delitem__() method to make the library
71 # call to actually remove the deleted variable from the *external*
72 # environment, so it only gets removed from the Python dictionary.
73 # Consequently, we need to just wipe out its value as follows>
74 os.environ['QTDIR'] = ''
75 test.run(stderr=None, arguments='-n noqtdir=1')
76
77 moc = test.where_is('moc')
78 if moc:
79     import os.path
80     expect = """
81 scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%s\)
82 File "SConstruct", line \d+, in \?
83 """ % string.replace( os.path.dirname(os.path.dirname(moc)), '\\', '\\\\' )
84 else:
85     expect = """
86 scons: warning: Could not detect qt, using empty QTDIR
87 File "SConstruct", line \d+, in \?
88 """
89
90 test.fail_test(not test.match_re(test.stderr(), expect))
91
92 test.pass_test()