Add Variables.defualted attribute
[scons.git] / test / SideEffect / basic.py
blobb5b6381e219ba6ed8f62c7c3439572533920306b
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify basic operation of the SideEffect() method, using a "log
29 file" as the side effect "target."
30 """
32 import os.path
34 import TestSCons
36 test = TestSCons.TestSCons()
38 test.write('SConstruct', """\
39 def copy(source, target):
40 with open(target, "wb") as f, open(source, "rb") as f2:
41 f.write(f2.read())
43 def build(env, source, target):
44 copy(str(source[0]), str(target[0]))
45 if target[0].side_effects:
46 with open(str(target[0].side_effects[0]), "ab") as side_effect:
47 side_effect.write(('%%s -> %%s\\n'%%(str(source[0]), str(target[0]))).encode())
49 Build = Builder(action=build)
50 env = Environment(BUILDERS={'Build':Build}, SUBDIR='subdir')
51 env.Build('foo.out', 'foo.in')
52 env.Build('bar.out', 'bar.in')
53 env.Build('blat.out', 'blat.in')
54 SideEffect('log.txt', ['foo.out', 'bar.out', 'blat.out'])
55 env.Build('log.out', 'log.txt')
56 env.Build('subdir/baz.out', 'baz.in')
57 env.SideEffect(r'%s', ['blat.out', r'%s'])
58 env.Build('subdir/out.out', 'subdir/out.txt')
59 """ % (os.path.join('$SUBDIR', 'out.txt'),
60 os.path.join('$SUBDIR', 'baz.out')))
62 test.write('foo.in', 'foo.in\n')
63 test.write('bar.in', 'bar.in\n')
64 test.write('blat.in', 'blat.in\n')
65 test.write('baz.in', 'baz.in\n')
67 test.run(arguments = 'foo.out bar.out', stdout=test.wrap_stdout("""\
68 build(["foo.out"], ["foo.in"])
69 build(["bar.out"], ["bar.in"])
70 """))
72 expect = """\
73 foo.in -> foo.out
74 bar.in -> bar.out
75 """
76 test.must_match('log.txt', expect)
78 test.write('bar.in', 'bar.in 2 \n')
80 test.run(arguments = 'log.txt', stdout=test.wrap_stdout("""\
81 build(["bar.out"], ["bar.in"])
82 build(["blat.out"], ["blat.in"])
83 """))
85 expect = expect + """\
86 bar.in -> bar.out
87 blat.in -> blat.out
88 """
89 test.must_match('log.txt', expect)
91 test.write('foo.in', 'foo.in 2 \n')
93 test.run(arguments = ".", stdout=test.wrap_stdout("""\
94 build(["foo.out"], ["foo.in"])
95 build(["log.out"], ["log.txt"])
96 build(["%s"], ["baz.in"])
97 build(["%s"], ["%s"])
98 """ % (os.path.join('subdir', 'baz.out'),
99 os.path.join('subdir', 'out.out'),
100 os.path.join('subdir', 'out.txt'))))
102 expect = expect + """\
103 foo.in -> foo.out
106 test.must_match('log.txt', expect)
108 test.pass_test()
110 # Local Variables:
111 # tab-width:4
112 # indent-tabs-mode:nil
113 # End:
114 # vim: set expandtab tabstop=4 shiftwidth=4: