summaryrefslogtreecommitdiff
path: root/src/engine/SCons/ActionTests.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/ActionTests.py')
-rw-r--r--src/engine/SCons/ActionTests.py98
1 files changed, 96 insertions, 2 deletions
diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py
index 6d4863e..627186c 100644
--- a/src/engine/SCons/ActionTests.py
+++ b/src/engine/SCons/ActionTests.py
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The SCons Foundation
+# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -21,7 +21,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/ActionTests.py 4577 2009/12/27 19:44:43 scons"
+__revision__ = "src/engine/SCons/ActionTests.py 4629 2010/01/17 22:23:21 scons"
# Define a null function and a null class for use as builder actions.
# Where these are defined in the file seems to affect their byte-code
@@ -1485,6 +1485,59 @@ class CommandGeneratorActionTestCase(unittest.TestCase):
c = a.get_contents(target=[], source=[], env=env)
assert c == "guux FFF BBB test", c
+ def test_get_contents_of_function_action(self):
+ """Test contents of a CommandGeneratorAction-generated FunctionAction
+ """
+
+ def LocalFunc():
+ pass
+
+ func_matches = [
+ "0,0,0,0,(),(),(d\000\000S),(),()",
+ "0,0,0,0,(),(),(d\x00\x00S),(),()",
+ ]
+
+ meth_matches = [
+ "1,1,0,0,(),(),(d\000\000S),(),()",
+ "1,1,0,0,(),(),(d\x00\x00S),(),()",
+ ]
+
+ def f_global(target, source, env, for_signature):
+ return SCons.Action.Action(GlobalFunc)
+
+ # TODO(1.5):
+ #def f_local(target, source, env, for_signature):
+ def f_local(target, source, env, for_signature, LocalFunc=LocalFunc):
+ return SCons.Action.Action(LocalFunc)
+
+ env = Environment(XYZ = 'foo')
+
+ a = self.factory(f_global)
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in func_matches, repr(c)
+
+ a = self.factory(f_local)
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in func_matches, repr(c)
+
+ def f_global(target, source, env, for_signature):
+ return SCons.Action.Action(GlobalFunc, varlist=['XYZ'])
+
+ # TODO(1.5):
+ #def f_local(target, source, env, for_signature):
+ def f_local(target, source, env, for_signature, LocalFunc=LocalFunc):
+ return SCons.Action.Action(LocalFunc, varlist=['XYZ'])
+
+ matches_foo = map(lambda x: x + "foo", func_matches)
+
+ a = self.factory(f_global)
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in matches_foo, repr(c)
+
+ a = self.factory(f_local)
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in matches_foo, repr(c)
+
class FunctionActionTestCase(unittest.TestCase):
@@ -1808,6 +1861,47 @@ class LazyActionTestCase(unittest.TestCase):
c = a.get_contents(target=[], source=[], env=env)
assert c == "This is a test", c
+ def test_get_contents_of_function_action(self):
+ """Test fetching the contents of a lazy-evaluation FunctionAction
+ """
+
+ def LocalFunc():
+ pass
+
+ func_matches = [
+ "0,0,0,0,(),(),(d\000\000S),(),()",
+ "0,0,0,0,(),(),(d\x00\x00S),(),()",
+ ]
+
+ meth_matches = [
+ "1,1,0,0,(),(),(d\000\000S),(),()",
+ "1,1,0,0,(),(),(d\x00\x00S),(),()",
+ ]
+
+ def factory(act, **kw):
+ return SCons.Action.FunctionAction(act, kw)
+
+
+ a = SCons.Action.Action("${FOO}")
+
+ env = Environment(FOO = factory(GlobalFunc))
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in func_matches, repr(c)
+
+ env = Environment(FOO = factory(LocalFunc))
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in func_matches, repr(c)
+
+ matches_foo = map(lambda x: x + "foo", func_matches)
+
+ env = Environment(FOO = factory(GlobalFunc, varlist=['XYZ']))
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in func_matches, repr(c)
+
+ env['XYZ'] = 'foo'
+ c = a.get_contents(target=[], source=[], env=env)
+ assert c in matches_foo, repr(c)
+
class ActionCallerTestCase(unittest.TestCase):
def test___init__(self):
"""Test creation of an ActionCaller"""