Added fix for TeX includes with same name as subdirs.
[scons.git] / test / Execute.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 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test the Execute() function for executing actions directly.
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 test = TestSCons.TestSCons()
36
37 test.write('my_copy.py', """\
38 import sys
39 open(sys.argv[2], 'wb').write(open(sys.argv[1], 'rb').read())
40 try:
41     exitval = int(sys.argv[3])
42 except IndexError:
43     exitval = 0
44 sys.exit(exitval)
45 """)
46
47 test.write('SConstruct', """\
48 Execute('%(_python_)s my_copy.py a.in a.out')
49 Execute(Action('%(_python_)s my_copy.py b.in b.out'))
50 env = Environment(COPY = 'my_copy.py')
51 env.Execute('%(_python_)s my_copy.py c.in c.out')
52 env.Execute(Action('%(_python_)s my_copy.py d.in d.out'))
53 v = env.Execute('%(_python_)s $COPY e.in e.out')
54 assert v == 0, v
55 v = env.Execute(Action('%(_python_)s $COPY f.in f.out'))
56 assert v == 0, v
57 v = env.Execute('%(_python_)s $COPY g.in g.out 1')
58 assert v == 1, v
59 v = env.Execute(Action('%(_python_)s $COPY h.in h.out 2'))
60 assert v == 2, v
61 import shutil
62 Execute(lambda target, source, env: shutil.copy('i.in', 'i.out'))
63 Execute(Action(lambda target, source, env: shutil.copy('j.in', 'j.out')))
64 env.Execute(lambda target, source, env: shutil.copy('k.in', 'k.out'))
65 env.Execute(Action(lambda target, source, env: shutil.copy('l.in', 'l.out')))
66
67 Execute(Copy('m.out', 'm.in'))
68 Execute(Copy('nonexistent.out', 'nonexistent.in'))
69 """ % locals())
70
71 test.write('a.in', "a.in\n")
72 test.write('b.in', "b.in\n")
73 test.write('c.in', "c.in\n")
74 test.write('d.in', "d.in\n")
75 test.write('e.in', "e.in\n")
76 test.write('f.in', "f.in\n")
77 test.write('g.in', "g.in\n")
78 test.write('h.in', "h.in\n")
79 test.write('i.in', "i.in\n")
80 test.write('j.in', "j.in\n")
81 test.write('k.in', "k.in\n")
82 test.write('l.in', "l.in\n")
83 test.write('m.in', "m.in\n")
84
85 import sys
86 if sys.platform == 'win32':
87     expect = """\
88 scons: *** Error 1
89 scons: *** Error 2
90 scons: *** nonexistent.in/*.*: The system cannot find the path specified
91 """
92 else:
93     # TODO(1.5):  the underlying shutil.copytree() call doesn't
94     # add the nonexistent file name to the exception it throws.
95     # This goes away soon, so just accomodate the difference.
96     if sys.version[:3] == '1.5':
97         expect = """\
98 scons: *** Error 1
99 scons: *** Error 2
100 scons: *** No such file or directory
101 """
102     else:
103         expect = """\
104 scons: *** Error 1
105 scons: *** Error 2
106 scons: *** nonexistent.in: No such file or directory
107 """
108
109 test.run(arguments = '.', stderr=expect)
110
111 test.must_match('a.out', "a.in\n")
112 test.must_match('b.out', "b.in\n")
113 test.must_match('c.out', "c.in\n")
114 test.must_match('d.out', "d.in\n")
115 test.must_match('e.out', "e.in\n")
116 test.must_match('f.out', "f.in\n")
117 test.must_match('g.out', "g.in\n")
118 test.must_match('h.out', "h.in\n")
119 test.must_match('i.out', "i.in\n")
120 test.must_match('j.out', "j.in\n")
121 test.must_match('k.out', "k.in\n")
122 test.must_match('l.out', "l.in\n")
123 test.must_match('m.out', "m.in\n")
124
125 test.pass_test()
126
127 # Local Variables:
128 # tab-width:4
129 # indent-tabs-mode:nil
130 # End:
131 # vim: set expandtab tabstop=4 shiftwidth=4: