summaryrefslogtreecommitdiff
path: root/src/engine/SCons/Platform/PlatformTests.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/Platform/PlatformTests.py')
-rw-r--r--src/engine/SCons/Platform/PlatformTests.py55
1 files changed, 49 insertions, 6 deletions
diff --git a/src/engine/SCons/Platform/PlatformTests.py b/src/engine/SCons/Platform/PlatformTests.py
index 21dbf18..7941625 100644
--- a/src/engine/SCons/Platform/PlatformTests.py
+++ b/src/engine/SCons/Platform/PlatformTests.py
@@ -21,18 +21,20 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Platform/PlatformTests.py 103260fce95bf5db1c35fb2371983087d85dd611 2019-07-13 18:25:30 bdbaddog"
+__revision__ = "src/engine/SCons/Platform/PlatformTests.py e724ae812eb96f4858a132f5b8c769724744faf6 2019-07-21 00:04:47 bdeegan"
import SCons.compat
import collections
import unittest
+import os
import SCons.Errors
import SCons.Platform
import SCons.Environment
import SCons.Action
+
class Environment(collections.UserDict):
def Detect(self, cmd):
return cmd
@@ -40,6 +42,7 @@ class Environment(collections.UserDict):
def AppendENVPath(self, key, value):
pass
+
class PlatformTestCase(unittest.TestCase):
def test_Platform(self):
"""Test the Platform() function"""
@@ -110,13 +113,14 @@ class PlatformTestCase(unittest.TestCase):
p = SCons.Platform.Platform('_does_not_exist_')
except SCons.Errors.UserError:
pass
- else:
+ else: # TODO pylint E0704: bare raise not inside except
raise
env = Environment()
SCons.Platform.Platform()(env)
assert env != {}, env
+
class TempFileMungeTestCase(unittest.TestCase):
def test_MAXLINELENGTH(self):
""" Test different values for MAXLINELENGTH with the same
@@ -138,22 +142,58 @@ class TempFileMungeTestCase(unittest.TestCase):
env['OVERSIMPLIFIED'] = 'command'
expanded_cmd = env.subst(defined_cmd)
# Call the tempfile munger
- cmd = t(None,None,env,0)
+ cmd = t(None, None, env, 0)
assert cmd == defined_cmd, cmd
# Let MAXLINELENGTH equal the string's length
env['MAXLINELENGTH'] = len(expanded_cmd)
- cmd = t(None,None,env,0)
+ cmd = t(None, None, env, 0)
assert cmd == defined_cmd, cmd
# Finally, let the actual tempfile mechanism kick in
# Disable printing of actions...
old_actions = SCons.Action.print_actions
SCons.Action.print_actions = 0
env['MAXLINELENGTH'] = len(expanded_cmd)-1
- cmd = t(None,None,env,0)
+ cmd = t(None, None, env, 0)
# ...and restoring its setting.
SCons.Action.print_actions = old_actions
assert cmd != defined_cmd, cmd
+ def test_TEMPFILEARGJOINBYTE(self):
+ """
+ Test argument join byte TEMPFILEARGJOINBYTE
+ """
+
+ # Init class with cmd, such that the fully expanded
+ # string reads "a test command line".
+ # Note, how we're using a command string here that is
+ # actually longer than the substituted one. This is to ensure
+ # that the TempFileMunge class internally really takes the
+ # length of the expanded string into account.
+ defined_cmd = "a $VERY $OVERSIMPLIFIED line"
+ t = SCons.Platform.TempFileMunge(defined_cmd)
+ env = SCons.Environment.SubstitutionEnvironment(tools=[])
+ # Setting the line length high enough...
+ env['MAXLINELENGTH'] = 1024
+ env['VERY'] = 'test'
+ env['OVERSIMPLIFIED'] = 'command'
+ env['TEMPFILEARGJOINBYTE'] = os.linesep
+ expanded_cmd = env.subst(defined_cmd)
+
+ # For tempfilemunge to operate.
+ old_actions = SCons.Action.print_actions
+ SCons.Action.print_actions = 0
+ env['MAXLINELENGTH'] = len(expanded_cmd)-1
+ cmd = t(None, None, env, 0)
+ # print("CMD is:%s"%cmd)
+
+ with open(cmd[-1],'rb') as f:
+ file_content = f.read()
+ # print("Content is:[%s]"%file_content)
+ # ...and restoring its setting.
+ SCons.Action.print_actions = old_actions
+ assert file_content != env['TEMPFILEARGJOINBYTE'].join(['test','command','line'])
+
+
def test_tempfilecreation_once(self):
# Init class with cmd, such that the fully expanded
# string reads "a test command line".
@@ -173,9 +213,11 @@ class TempFileMungeTestCase(unittest.TestCase):
old_actions = SCons.Action.print_actions
SCons.Action.print_actions = 0
# Create an instance of object derived class to allow setattrb
- class Node(object) :
+
+ class Node(object):
class Attrs(object):
pass
+
def __init__(self):
self.attributes = self.Attrs()
target = [Node()]
@@ -185,6 +227,7 @@ class TempFileMungeTestCase(unittest.TestCase):
assert cmd != defined_cmd, cmd
assert cmd == getattr(target[0].attributes, 'tempfile_cmdlist', None)
+
class PlatformEscapeTestCase(unittest.TestCase):
def test_posix_escape(self):
""" Check that paths with parens are escaped properly