Clean up and simplify logic. TODO: scons -c isn't removing the .di files. Mainly...
[scons.git] / test / SPAWN.py
blobca9d3448d01417205ab1bbbca381ec757df98951
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 SPAWN construction variable.
29 """
31 import TestSCons
33 _python_ = TestSCons._python_
35 test = TestSCons.TestSCons()
37 test.write('cat.py', """\
38 import sys
39 with open(sys.argv[1], 'wb') as ofp:
40 for s in sys.argv[2:]:
41 with open(s, 'rb') as ifp:
42 ofp.write(ifp.read())
43 """)
45 test.write('SConstruct', """
46 import subprocess
47 import sys
49 def my_spawn1(sh, escape, cmd, args, env):
50 s = " ".join(args + ['extra1.txt'])
51 cp = subprocess.run(s, shell=True)
52 return cp.returncode
54 def my_spawn2(sh, escape, cmd, args, env):
55 s = " ".join(args + ['extra2.txt'])
56 cp = subprocess.run(s, shell=True)
57 return cp.returncode
59 env = Environment(MY_SPAWN1 = my_spawn1,
60 MY_SPAWN2 = my_spawn2,
61 COMMAND = r'%(_python_)s cat.py $TARGET $SOURCES')
62 env1 = env.Clone(SPAWN = my_spawn1)
63 env1.Command('file1.out', 'file1.in', '$COMMAND')
65 env2 = env.Clone(SPAWN = '$MY_SPAWN2')
66 env2.Command('file2.out', 'file2.in', '$COMMAND')
68 env3 = env.Clone(SPAWN = '${USE_TWO and MY_SPAWN2 or MY_SPAWN1}')
69 env3.Command('file3.out', 'file3.in', '$COMMAND', USE_TWO=0)
70 env3.Command('file4.out', 'file4.in', '$COMMAND', USE_TWO=1)
71 """ % locals())
73 test.write('file1.in', "file1.in\n")
74 test.write('file2.in', "file2.in\n")
75 test.write('file3.in', "file3.in\n")
76 test.write('file4.in', "file4.in\n")
77 test.write('extra1.txt', "extra1.txt\n")
78 test.write('extra2.txt', "extra2.txt\n")
80 test.run(arguments = '.')
82 test.must_match('file1.out', "file1.in\nextra1.txt\n")
83 test.must_match('file2.out', "file2.in\nextra2.txt\n")
84 test.must_match('file3.out', "file3.in\nextra1.txt\n")
85 test.must_match('file4.out', "file4.in\nextra2.txt\n")
87 test.pass_test()
89 # Local Variables:
90 # tab-width:4
91 # indent-tabs-mode:nil
92 # End:
93 # vim: set expandtab tabstop=4 shiftwidth=4: