Move 2.0 changes collected in branches/pending back to trunk for further
[scons.git] / test / Alias / action.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 """
26 Test that Aliases with actions work.
27 """
28
29 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
30
31 import TestSCons
32
33 test = TestSCons.TestSCons()
34
35 test.write('SConstruct', """
36 def cat(target, source, env):
37     target = str(target[0])
38     f = open(target, "wb")
39     for src in source:
40         f.write(open(str(src), "rb").read())
41     f.close()
42
43 def foo(target, source, env):
44     target = list(map(str, target))
45     source = list(map(str, source))
46     open('foo', 'wb').write("foo(%s, %s)\\n" % (target, source))
47
48 def bar(target, source, env):
49     target = list(map(str, target))
50     source = list(map(str, source))
51     open('bar', 'wb').write("bar(%s, %s)\\n" % (target, source))
52
53 env = Environment(BUILDERS = {'Cat':Builder(action=cat)})
54 env.Alias(target = ['build-f1'], source = 'f1.out', action = foo)
55 f1 = env.Cat('f1.out', 'f1.in')
56 f2 = env.Cat('f2.out', 'f2.in')
57 f3 = env.Cat('f3.out', 'f3.in')
58 f4 = env.Cat('f4.out', 'f4.in')
59 f5 = env.Cat('f5.out', 'f5.in')
60 f6 = env.Cat('f6.out', 'f6.in')
61 env.Alias('build-all', [f1, f2, f3], foo)
62 env.Alias('build-add1', f3, foo)
63 env.Alias('build-add1', f2)
64 env.Alias('build-add2a',  f4)
65 env.Alias('build-add2b',  f5)
66 env.Alias(['build-add2a', 'build-add2b'], action=foo)
67 env.Alias('build-add3', f6)
68 env.Alias('build-add3', action=foo)
69 env.Alias('build-add3', action=bar)
70 """)
71
72 test.write('f1.in', "f1.in 1\n")
73 test.write('f2.in', "f2.in 1\n")
74 test.write('f3.in', "f3.in 1\n")
75 test.write('f4.in', "f4.in 1\n")
76 test.write('f5.in', "f5.in 1\n")
77 test.write('f6.in', "f6.in 1\n")
78
79 test.run(arguments = 'build-f1')
80
81 test.must_match('f1.out', "f1.in 1\n")
82 test.must_match('foo', "foo(['build-f1'], ['f1.out'])\n")
83
84 test.up_to_date(arguments = 'build-f1')
85
86 test.write('f1.in', "f1.in 2\n")
87 test.unlink('foo')
88
89 test.run(arguments = 'build-f1')
90
91 test.must_match('f1.out', "f1.in 2\n")
92 test.must_match('foo', "foo(['build-f1'], ['f1.out'])\n")
93
94 test.run(arguments = 'build-all')
95
96 test.must_match('f1.out', "f1.in 2\n")
97 test.must_match('f2.out', "f2.in 1\n")
98 test.must_match('f3.out', "f3.in 1\n")
99 test.must_match('foo', "foo(['build-all'], ['f1.out', 'f2.out', 'f3.out'])\n")
100
101 test.up_to_date(arguments = 'build-all')
102 test.up_to_date(arguments = 'build-add1')
103
104 test.write('f1.in', "f1.in 3\n")
105 test.write('f3.in', "f3.in 2\n")
106 test.unlink('foo')
107
108 test.run(arguments = 'build-add1')
109
110 test.must_match('f1.out', "f1.in 2\n")
111 test.must_match('f2.out', "f2.in 1\n")
112 test.must_match('f3.out', "f3.in 2\n")
113 test.must_match('foo', "foo(['build-add1'], ['f3.out', 'f2.out'])\n")
114
115 test.up_to_date(arguments = 'build-add1')
116
117 test.run(arguments = 'build-add2a')
118
119 test.must_match('f4.out', "f4.in 1\n")
120 test.must_not_exist('f5.out')
121 test.must_match('foo', "foo(['build-add2a'], ['f4.out'])\n")
122
123 test.run(arguments = 'build-add2b')
124
125 test.must_match('f5.out', "f5.in 1\n")
126 test.must_match('foo', "foo(['build-add2b'], ['f5.out'])\n")
127
128 test.run(arguments = 'build-add3')
129
130 test.must_match('f6.out', "f6.in 1\n")
131 test.must_match('foo', "foo(['build-add3'], ['f6.out'])\n")
132 test.must_match('bar', "bar(['build-add3'], ['f6.out'])\n")
133
134 test.pass_test()
135
136 # Local Variables:
137 # tab-width:4
138 # indent-tabs-mode:nil
139 # End:
140 # vim: set expandtab tabstop=4 shiftwidth=4: