assert str(act.built_target[0]) == "xxx", str(act.built_target[0])
assert act.built_source == ["yyy", "zzz"], act.built_source
+ def test_get_executor(self):
+ """Test the reset_executor() method"""
+ n = SCons.Node.Node()
+
+ try:
+ n.get_executor(0)
+ except AttributeError:
+ pass
+ else:
+ self.fail("did not catch expected AttributeError")
+
+ class Builder:
+ action = 'act'
+ env = 'env1'
+ overrides = {}
+
+ n = SCons.Node.Node()
+ n.builder_set(Builder())
+ x = n.get_executor()
+ assert x.env == 'env1', x.env
+
+ n = SCons.Node.Node()
+ n.builder_set(Builder())
+ n.env_set('env2')
+ x = n.get_executor()
+ assert x.env == 'env2', x.env
+
+ def test_set_executor(self):
+ """Test the reset_executor() method"""
+ n = SCons.Node.Node()
+ n.set_executor(1)
+ assert n.executor == 1, n.executor
+
+ def test_reset_executor(self):
+ """Test the reset_executor() method"""
+ n = SCons.Node.Node()
+ n.set_executor(1)
+ assert n.executor == 1, n.executor
+ n.reset_executor()
+ assert not hasattr(n, 'executor'), "unexpected executor attribute"
+
def test_built(self):
"""Test the built() method"""
class SubNode(SCons.Node.Node):
test = TestSCons.TestSCons()
-test.write('SConstruct', """
+test.subdir('work1', 'work2')
+
+
+
+test.write(['work1', 'SConstruct'], """
import os.path
+import stat
-env = Environment(XXX='bar%s')
+env = Environment(XXX='bar%(_exe)s')
def before(env, target, source):
f=open(str(target[0]), "wb")
f.write("Foo\\n")
f.close()
f=open("before.txt", "ab")
- f.write(str(target[0]) + "\\n")
+ f.write(os.path.splitext(str(target[0]))[0] + "\\n")
f.close()
def after(env, target, source):
- fin = open(str(target[0]), "rb")
- fout = open("after_" + str(target[0]), "wb")
+ t = str(target[0])
+ a = "after_" + os.path.splitext(t)[0]
+ fin = open(t, "rb")
+ fout = open(a, "wb")
fout.write(fin.read())
fout.close()
fin.close()
+ os.chmod(a, os.stat(a)[stat.ST_MODE] | stat.S_IXUSR)
foo = env.Program(source='foo.c', target='foo')
AddPreAction(foo, before)
-AddPostAction('foo%s', after)
+AddPostAction('foo%(_exe)s', after)
bar = env.Program(source='bar.c', target='bar')
env.AddPreAction('$XXX', before)
env.AddPostAction('$XXX', after)
-""" % (_exe, _exe))
+""" % locals())
-test.write('foo.c', r"""
+test.write(['work1', 'foo.c'], r"""
#include <stdio.h>
int main(void)
}
""")
-test.write('bar.c', r"""
+test.write(['work1', 'bar.c'], r"""
#include <stdio.h>
int main(void)
}
""")
+test.run(chdir='work1', arguments='.')
+
+test.run(program=test.workpath('work1', 'foo'+ _exe), stdout="foo.c\n")
+test.run(program=test.workpath('work1', 'bar'+ _exe), stdout="bar.c\n")
+
+test.must_match(['work1', 'before.txt'], "bar\nfoo\n")
+
+after_foo_exe = test.workpath('work1', 'after_foo' + _exe)
+test.run(program=after_foo_exe, stdout="foo.c\n")
+
+after_bar_exe = test.workpath('work1', 'after_bar' + _exe)
+test.run(program=after_bar_exe, stdout="bar.c\n")
+
+
+
+
+test.write(['work2', 'SConstruct'], """\
+def b(target, source, env):
+ open(str(target[0]), 'w').write(env['X'] + '\\n')
+env1 = Environment(X='111')
+env2 = Environment(X='222')
+B = Builder(action = b, env = env1, multi=1)
+print "B =", B
+print "B.env =", B.env
+env1.Append(BUILDERS = {'B' : B})
+env2.Append(BUILDERS = {'B' : B})
+env3 = env1.Copy(X='333')
+print "env1 =", env1
+print "env2 =", env2
+print "env3 =", env3
+f1 = env1.B(File('file1.out'), [])
+f2 = env2.B('file2.out', [])
+f3 = env3.B('file3.out', [])
+def do_nothing(env, target, source):
+ pass
+AddPreAction(f2[0], do_nothing)
+AddPostAction(f3[0], do_nothing)
+print "f1[0].builder =", f1[0].builder
+print "f2[0].builder =", f2[0].builder
+print "f3[0].builder =", f3[0].builder
+print "f1[0].env =", f1[0].env
+print "f2[0].env =", f2[0].env
+print "f3[0].env =", f3[0].env
+""")
-test.run(arguments='.')
-
-test.run(program=test.workpath('foo'+ _exe), stdout="foo.c\n")
-test.run(program=test.workpath('bar'+ _exe), stdout="bar.c\n")
+test.run(chdir='work2', arguments = '.')
-test.fail_test(test.read('before.txt', 'rb') != "bar%s\nfoo%s\n" % (_exe, _exe))
+test.must_match(['work2', 'file1.out'], "111\n")
+test.must_match(['work2', 'file2.out'], "222\n")
+test.must_match(['work2', 'file3.out'], "333\n")
-after_foo_exe = test.workpath('after_foo' + _exe)
-os.chmod(after_foo_exe, os.stat(after_foo_exe)[stat.ST_MODE] | stat.S_IXUSR)
-test.run(program=test.workpath(after_foo_exe), stdout="foo.c\n")
-after_bar_exe = test.workpath('after_bar' + _exe)
-os.chmod(after_bar_exe, os.stat(after_bar_exe)[stat.ST_MODE] | stat.S_IXUSR)
-test.run(program=test.workpath(after_bar_exe), stdout="bar.c\n")
test.pass_test()