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__"
29 _python_ = TestSCons._python_
31 test = TestSCons.TestSCons()
33 test.write('build.py', r"""
35 file = open(sys.argv[1], 'wb')
36 file.write(sys.argv[2] + "\n")
37 file.write(open(sys.argv[3], 'rb').read())
42 test.write('SConstruct', """
43 B = Builder(action = r'%(_python_)s build.py $TARGET 1 $SOURCES')
44 env = Environment(BUILDERS = { 'B' : B })
45 env.B(target = 'foo.out', source = 'foo.in')
48 test.write('foo.in', "foo.in\n")
50 test.run(arguments = '.')
52 test.fail_test(test.read('foo.out') != "1\nfoo.in\n")
54 test.up_to_date(arguments = '.')
56 test.write('SConstruct', """
57 B = Builder(action = r'%(_python_)s build.py $TARGET 2 $SOURCES')
58 env = Environment(BUILDERS = { 'B' : B })
59 env.B(target = 'foo.out', source = 'foo.in')
62 test.run(arguments = '.')
64 test.fail_test(test.read('foo.out') != "2\nfoo.in\n")
66 test.up_to_date(arguments = '.')
68 test.write('SConstruct', """
70 def func(env, target, source):
71 cmd = r'%(_python_)s build.py %%s 3 %%s' %% (' '.join(map(str, target)),
72 ' '.join(map(str, source)))
75 B = Builder(action = func)
76 env = Environment(BUILDERS = { 'B' : B })
77 env.B(target = 'foo.out', source = 'foo.in')
80 test.run(arguments = '.', stderr = None)
82 test.fail_test(test.read('foo.out') != "3\nfoo.in\n")
84 test.up_to_date(arguments = '.')
86 test.write('SConstruct', """
88 assert 'string' not in globals()
91 self.cmd = r'%(_python_)s build.py %%s 4 %%s'
92 def __call__(self, env, target, source):
93 cmd = self.get_contents(env, target, source)
96 def get_contents(self, env, target, source):
97 return self.cmd %% (' '.join(map(str, target)),
98 ' '.join(map(str, source)))
99 B = Builder(action = bld())
100 env = Environment(BUILDERS = { 'B' : B })
101 env.B(target = 'foo.out', source = 'foo.in')
104 test.run(arguments = '.')
106 test.fail_test(test.read('foo.out') != "4\nfoo.in\n")
108 test.up_to_date(arguments = '.')
110 # Make sure we can expand actions in substitutions.
111 test.write('SConstruct', """\
112 def func(env, target, source):
114 env = Environment(S = Action('foo'),
116 L = Action(['arg1', 'arg2']))
117 print env.subst('$S')
118 print env.subst('$F')
119 print env.subst('$L')
122 test.run(arguments = '-Q .', stdout = """\
124 func(target, source, env)
127 scons: `.' is up to date.
134 # indent-tabs-mode:nil
136 # vim: set expandtab tabstop=4 shiftwidth=4: