Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Actions / append.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 # This test exercises the addition operator of Action objects.
25 # Using Environment.Prepend() and Environment.Append(), you should be
26 # able to add new actions to existing ones, effectively adding steps
27 # to a build process.
28
29 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
30
31 import os
32 import stat
33 import sys
34 import TestSCons
35
36 if sys.platform == 'win32':
37     _exe = '.exe'
38 else:
39     _exe = ''
40
41 test = TestSCons.TestSCons()
42
43 test.write('foo.c', r"""
44 #include <stdio.h>
45
46 int main(void)
47 {
48     printf("Foo\n");
49     return 0;
50 }
51 """)
52
53 test.write('SConstruct', """
54
55 env=Environment()
56
57 def before(env, target, source):
58     f=open(str(target[0]), "wb")
59     f.write("Foo\\n")
60     f.close()
61     f=open("before.txt", "wb")
62     f.write("Bar\\n")
63     f.close()
64
65 def after(env, target, source):
66     fin = open(str(target[0]), "rb")
67     fout = open("after%s", "wb")
68     fout.write(fin.read())
69     fout.close()
70     fin.close()
71
72 env.Prepend(LINKCOM=Action(before))
73 env.Append(LINKCOM=Action(after))
74 env.Program(source='foo.c', target='foo')
75 """ % _exe)
76
77 after_exe = test.workpath('after' + _exe)
78
79 test.run(arguments='.')
80 test.fail_test(open('before.txt', 'rb').read() != "Bar\n")
81 os.chmod(after_exe, os.stat(after_exe)[stat.ST_MODE] | stat.S_IXUSR)
82 test.run(program=after_exe, stdout="Foo\n")
83 test.pass_test()
84
85 # Local Variables:
86 # tab-width:4
87 # indent-tabs-mode:nil
88 # End:
89 # vim: set expandtab tabstop=4 shiftwidth=4: