Issue 2265: Add additional --taskmastertrace= messages in the Task class.
[scons.git] / test / option / debug-count.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 that the --debug=count option works.
29 """
30
31 import TestSCons
32 import sys
33 import string
34 import re
35 import time
36
37 test = TestSCons.TestSCons()
38
39 try:
40     import weakref
41 except ImportError:
42     x = "Python version has no 'weakref' module; skipping tests.\n"
43     test.skip_test(x)
44
45
46
47 test.write('SConstruct', """
48 def cat(target, source, env):
49     open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read())
50 env = Environment(BUILDERS={'Cat':Builder(action=Action(cat))})
51 env.Cat('file.out', 'file.in')
52 """)
53
54 test.write('file.in', "file.in\n")
55
56 # Just check that object counts for some representative classes
57 # show up in the output.
58
59 def find_object_count(s, stdout):
60     re_string = '\d+ +\d+   %s' % re.escape(s)
61     return re.search(re_string, stdout)
62
63 objects = [
64     'Action.CommandAction',
65     'Builder.BuilderBase',
66     'Environment.Base',
67     'Executor.Executor',
68     'Node.FS',
69     'Node.FS.Base',
70     'Node.Node',
71 ]
72
73 for args in ['-h --debug=count', '--debug=count']:
74     test.run(arguments = args)
75     stdout = test.stdout()
76
77     missing = filter(lambda o: find_object_count(o, stdout) is None, objects)
78
79     if missing:
80         print "Missing the following object lines from '%s' output:" % args
81         print "\t", string.join(missing)
82         print "STDOUT =========="
83         print stdout
84         test.fail_test(1)
85
86 expect_warning = """
87 scons: warning: --debug=count is not supported when running SCons
88 \twith the python -O option or optimized \\(.pyo\\) modules.
89 """ + TestSCons.file_expr
90
91 test.run(arguments = '--debug=count -h',
92          interpreter = ['python', '-O'],
93          stderr = expect_warning,
94          match = TestSCons.match_re)
95
96
97 test.pass_test()