Add Variables.defualted attribute
[scons.git] / test / Alias / action.py
blobecff388c39986bcad0c556b725337b7be60e2189
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 Aliases with actions work.
28 """
30 import TestSCons
32 test = TestSCons.TestSCons()
34 test.write('SConstruct', """
35 def cat(target, source, env):
36 target = str(target[0])
37 with open(target, "wb") as f:
38 for src in source:
39 with open(str(src), "rb") as ifp:
40 f.write(ifp.read())
42 def foo(target, source, env):
43 target = list(map(str, target))
44 source = list(map(str, source))
45 with open('foo', 'wb') as f:
46 f.write(bytearray("foo(%s, %s)\\n" % (target, source),'utf-8'))
48 def bar(target, source, env):
49 target = list(map(str, target))
50 source = list(map(str, source))
51 with open('bar', 'wb') as f:
52 f.write(bytearray("bar(%s, %s)\\n" % (target, source),'utf-8'))
54 DefaultEnvironment(tools=[]) # test speedup
55 env = Environment(tools=[], BUILDERS = {'Cat':Builder(action=cat)})
56 env.Alias(target = ['build-f1'], source = 'f1.out', action = foo)
57 f1 = env.Cat('f1.out', 'f1.in')
58 f2 = env.Cat('f2.out', 'f2.in')
59 f3 = env.Cat('f3.out', 'f3.in')
60 f4 = env.Cat('f4.out', 'f4.in')
61 f5 = env.Cat('f5.out', 'f5.in')
62 f6 = env.Cat('f6.out', 'f6.in')
63 env.Alias('build-all', [f1, f2, f3], foo)
64 env.Alias('build-add1', f3, foo)
65 env.Alias('build-add1', f2)
66 env.Alias('build-add2a', f4)
67 env.Alias('build-add2b', f5)
68 env.Alias(['build-add2a', 'build-add2b'], action=foo)
69 env.Alias('build-add3', f6)
70 env.Alias('build-add3', action=foo)
71 env.Alias('build-add3', action=bar)
72 """)
74 test.write('f1.in', "f1.in 1\n")
75 test.write('f2.in', "f2.in 1\n")
76 test.write('f3.in', "f3.in 1\n")
77 test.write('f4.in', "f4.in 1\n")
78 test.write('f5.in', "f5.in 1\n")
79 test.write('f6.in', "f6.in 1\n")
81 test.run(arguments = 'build-f1')
83 test.must_match('f1.out', "f1.in 1\n")
84 test.must_match('foo', "foo(['build-f1'], ['f1.out'])\n")
86 test.up_to_date(arguments = 'build-f1')
88 test.write('f1.in', "f1.in 2\n")
89 test.unlink('foo')
91 test.run(arguments = 'build-f1')
93 test.must_match('f1.out', "f1.in 2\n")
94 test.must_match('foo', "foo(['build-f1'], ['f1.out'])\n")
96 test.run(arguments = 'build-all')
98 test.must_match('f1.out', "f1.in 2\n")
99 test.must_match('f2.out', "f2.in 1\n")
100 test.must_match('f3.out', "f3.in 1\n")
101 test.must_match('foo', "foo(['build-all'], ['f1.out', 'f2.out', 'f3.out'])\n")
103 test.up_to_date(arguments = 'build-all')
104 test.up_to_date(arguments = 'build-add1')
106 test.write('f1.in', "f1.in 3\n")
107 test.write('f3.in', "f3.in 2\n")
108 test.unlink('foo')
110 test.run(arguments = 'build-add1')
112 test.must_match('f1.out', "f1.in 2\n")
113 test.must_match('f2.out', "f2.in 1\n")
114 test.must_match('f3.out', "f3.in 2\n")
115 test.must_match('foo', "foo(['build-add1'], ['f3.out', 'f2.out'])\n")
117 test.up_to_date(arguments = 'build-add1')
119 test.run(arguments = 'build-add2a')
121 test.must_match('f4.out', "f4.in 1\n")
122 test.must_not_exist('f5.out')
123 test.must_match('foo', "foo(['build-add2a'], ['f4.out'])\n")
125 test.run(arguments = 'build-add2b')
127 test.must_match('f5.out', "f5.in 1\n")
128 test.must_match('foo', "foo(['build-add2b'], ['f5.out'])\n")
130 test.run(arguments = 'build-add3')
132 test.must_match('f6.out', "f6.in 1\n")
133 test.must_match('foo', "foo(['build-add3'], ['f6.out'])\n")
134 test.must_match('bar', "bar(['build-add3'], ['f6.out'])\n")
136 test.pass_test()
138 # Local Variables:
139 # tab-width:4
140 # indent-tabs-mode:nil
141 # End:
142 # vim: set expandtab tabstop=4 shiftwidth=4: