Some minor test tweaking
[scons.git] / test / implicit-cache / DualTargets.py
blob174d39c149d4b5cca1913f7fef3c09c9f0c293ae
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test that --implicit-cache works correctly in conjonction with a
28 builder that produces multiple targets.
29 """
31 import TestSCons
33 test = TestSCons.TestSCons()
35 test.write('SConstruct', """\
36 DefaultEnvironment(tools=[])
37 import os.path
39 def emitter(target, source, env):
40 tgt0 = target[0].get_abspath()
41 base,ext = os.path.splitext(tgt0)
42 target.append(base + '.b')
43 return(target, source)
46 def source_scan(node, env, path):
47 path = node.get_abspath()
48 base,ext = os.path.splitext(path)
49 return [base + '.lib']
52 env = Environment(tools=[])
53 env['BUILDERS']['DualTarget'] = Builder(
54 action = Action(
56 Copy( '$TARGET', '$SOURCE' ),
57 Copy( '${TARGET.base}.b', '$SOURCE' ),
60 suffix = '.a',
61 src_suffix = '.cpp',
62 single_source = True,
63 emitter=emitter,
64 source_scanner=Scanner(source_scan),
67 env.Command( 'x.cpp', '', Touch('$TARGET') )
68 env.Command( 'x.lib', '', Touch('$TARGET') )
70 env.DualTarget('x.cpp')
71 """)
73 test.must_not_exist('x.cpp')
74 test.must_not_exist('x.lib')
75 test.must_not_exist('x.a')
76 test.must_not_exist('x.b')
78 # Build everything first.
79 test.run(arguments = '.')
80 test.must_exist('x.cpp')
81 test.must_exist('x.lib')
82 test.must_exist('x.a')
83 test.must_exist('x.b')
85 test.must_contain_all_lines(test.stdout(), ['Copy'])
87 # Double check that targets are not rebuilt.
88 test.run(arguments = '.')
89 test.must_exist('x.cpp')
90 test.must_exist('x.lib')
91 test.must_exist('x.a')
92 test.must_exist('x.b')
94 test.must_not_contain_any_line(test.stdout(), ['Copy'])
96 # Double check that targets are not rebuilt even with --implicit-cache
97 test.run(arguments = '--implicit-cache x.a')
98 test.must_exist('x.cpp')
99 test.must_exist('x.lib')
100 test.must_exist('x.a')
101 test.must_exist('x.b')
103 test.must_not_contain_any_line(test.stdout(), ['Copy'])
105 # Double check that targets are not rebuilt even with --implicit-cache
106 # a second time.
107 test.run(arguments = '--implicit-cache x.a')
108 test.must_exist('x.cpp')
109 test.must_exist('x.lib')
110 test.must_exist('x.a')
111 test.must_exist('x.b')
113 test.must_not_contain_any_line(test.stdout(), ['Copy'])
115 # Double check that targets are not rebuilt if we reran without
116 # --implicit-cache
117 test.run(arguments = '.')
118 test.must_exist('x.cpp')
119 test.must_exist('x.lib')
120 test.must_exist('x.a')
121 test.must_exist('x.b')
123 test.must_not_contain_any_line(test.stdout(), ['Copy'])
125 # Double check again
126 test.run(arguments = '.')
127 test.must_exist('x.cpp')
128 test.must_exist('x.lib')
129 test.must_exist('x.a')
130 test.must_exist('x.b')
132 test.must_not_contain_any_line(test.stdout(), ['Copy'])
134 # Then only of the targets using --implicit-cache
135 test.pass_test()
137 # Local Variables:
138 # tab-width:4
139 # indent-tabs-mode:nil
140 # End:
141 # vim: set expandtab tabstop=4 shiftwidth=4: