Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / Execute.py
blob693bce47ed05098eae40c824a76b308ea3686a07
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 Test the Execute() function for executing actions directly.
29 """
30 import sys
31 import TestSCons
33 _python_ = TestSCons._python_
35 test = TestSCons.TestSCons()
37 test.write('my_copy.py', """\
38 import sys
39 with open(sys.argv[2], 'wb') as ofp, open(sys.argv[1], 'rb') as ifp:
40 ofp.write(ifp.read())
41 try:
42 exitval = int(sys.argv[3])
43 except IndexError:
44 exitval = 0
45 sys.exit(exitval)
46 """)
48 test.write('SConstruct', """\
49 Execute(r'%(_python_)s my_copy.py a.in a.out')
50 Execute(Action(r'%(_python_)s my_copy.py b.in b.out'))
51 env = Environment(COPY = 'my_copy.py')
52 env.Execute(r'%(_python_)s my_copy.py c.in c.out')
53 env.Execute(Action(r'%(_python_)s my_copy.py d.in d.out'))
54 v = env.Execute(r'%(_python_)s $COPY e.in e.out')
55 assert v == 0, v
56 v = env.Execute(Action(r'%(_python_)s $COPY f.in f.out'))
57 assert v == 0, v
58 v = env.Execute(r'%(_python_)s $COPY g.in g.out 1')
59 assert v == 1, v
60 v = env.Execute(Action(r'%(_python_)s $COPY h.in h.out 2'))
61 assert v == 2, v
62 import shutil
63 Execute(lambda target, source, env: shutil.copy('i.in', 'i.out'))
64 Execute(Action(lambda target, source, env: shutil.copy('j.in', 'j.out')))
65 env.Execute(lambda target, source, env: shutil.copy('k.in', 'k.out'))
66 env.Execute(Action(lambda target, source, env: shutil.copy('l.in', 'l.out')))
68 Execute(Copy('m.out', 'm.in'))
69 Execute(Copy('nonexistent.out', 'nonexistent.in'))
70 """ % locals())
72 test.write('a.in', "a.in\n")
73 test.write('b.in', "b.in\n")
74 test.write('c.in', "c.in\n")
75 test.write('d.in', "d.in\n")
76 test.write('e.in', "e.in\n")
77 test.write('f.in', "f.in\n")
78 test.write('g.in', "g.in\n")
79 test.write('h.in', "h.in\n")
80 test.write('i.in', "i.in\n")
81 test.write('j.in', "j.in\n")
82 test.write('k.in', "k.in\n")
83 test.write('l.in', "l.in\n")
84 test.write('m.in', "m.in\n")
86 if sys.platform == 'win32' and sys.version_info[0] == 3:
87 expect = r"""scons: \*\*\* Error 1
88 scons: \*\*\* Error 2
89 scons: \*\*\* nonexistent.in: (The system cannot find the path specified|Das System kann den angegebenen Pfad nicht finden)"""
91 else:
92 expect = r"""scons: \*\*\* Error 1
93 scons: \*\*\* Error 2
94 scons: \*\*\* nonexistent\.in: No such file or directory"""
96 test.run(arguments = '.', stdout = None, stderr = None)
98 test.must_contain_all_lines(test.stderr(), expect.splitlines(), find=TestSCons.search_re)
100 test.must_match('a.out', "a.in\n")
101 test.must_match('b.out', "b.in\n")
102 test.must_match('c.out', "c.in\n")
103 test.must_match('d.out', "d.in\n")
104 test.must_match('e.out', "e.in\n")
105 test.must_match('f.out', "f.in\n")
106 test.must_match('g.out', "g.in\n")
107 test.must_match('h.out', "h.in\n")
108 test.must_match('i.out', "i.in\n")
109 test.must_match('j.out', "j.in\n")
110 test.must_match('k.out', "k.in\n")
111 test.must_match('l.out', "l.in\n")
112 test.must_match('m.out', "m.in\n")
114 test.pass_test()
116 # Local Variables:
117 # tab-width:4
118 # indent-tabs-mode:nil
119 # End:
120 # vim: set expandtab tabstop=4 shiftwidth=4: