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__"
28 Test the SPAWN construction variable.
33 _python_
= TestSCons
._python
_
35 test
= TestSCons
.TestSCons()
37 test
.write('cat.py', """\
39 with open(sys.argv[1], 'wb') as ofp:
40 for s in sys.argv[2:]:
41 with open(s, 'rb') as ifp:
45 test
.write('SConstruct', """
49 def my_spawn1(sh, escape, cmd, args, env):
50 s = " ".join(args + ['extra1.txt'])
51 cp = subprocess.run(s, shell=True)
54 def my_spawn2(sh, escape, cmd, args, env):
55 s = " ".join(args + ['extra2.txt'])
56 cp = subprocess.run(s, shell=True)
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)
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")
91 # indent-tabs-mode:nil
93 # vim: set expandtab tabstop=4 shiftwidth=4: