From e37f8b71a89adebae1592edca7c5371d50322e42 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Feb 2023 17:41:38 -0800 Subject: Added DefaultEnvironment(tools=[]) to fixtures for CPPDEFINES. Added negative test for non-two-tuple. Minor wording change --- SCons/Defaults.py | 4 ++-- SCons/DefaultsTests.py | 10 ++++++++++ test/CPPDEFINES/fixture/SConstruct-Append | 2 ++ test/CPPDEFINES/fixture/SConstruct-Prepend | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/SCons/Defaults.py b/SCons/Defaults.py index ea7e930..72af1bd 100644 --- a/SCons/Defaults.py +++ b/SCons/Defaults.py @@ -530,7 +530,7 @@ def processDefines(defs) -> List[str]: if len(define) > 2: raise SCons.Errors.UserError( f"Invalid tuple in CPPDEFINES: {define!r}, " - "must be a two-tuple" + "must be a tuple with only two elements" ) name, *value = define if value and value[0] is not None: @@ -556,7 +556,7 @@ def processDefines(defs) -> List[str]: if len(defs) > 2: raise SCons.Errors.UserError( f"Invalid tuple in CPPDEFINES: {defs!r}, " - "must be a two-tuple" + "must be a tuple with only two elements" ) name, *value = defs if value and value[0] is not None: diff --git a/SCons/DefaultsTests.py b/SCons/DefaultsTests.py index c9a6663..66e219a 100644 --- a/SCons/DefaultsTests.py +++ b/SCons/DefaultsTests.py @@ -28,6 +28,7 @@ import collections import TestCmd from SCons.Defaults import mkdir_func, _defines, processDefines +from SCons.Errors import UserError class DummyEnvironment(collections.UserDict): @@ -144,6 +145,15 @@ class DefaultsTestCase(unittest.TestCase): rv = processDefines(['foo', ('name', 'val'), ['name2', 'val2']]) self.assertEqual(rv, ['foo', 'name=val', 'name2=val2']) + with self.subTest(): + # invalid tuple + try: + rv = processDefines([('name', 'val', 'bad')]) + except UserError as e: + pass + else: + self.fail("Invalid tuple should throw SCons.Errors.UserError") + if __name__ == "__main__": unittest.main() diff --git a/test/CPPDEFINES/fixture/SConstruct-Append b/test/CPPDEFINES/fixture/SConstruct-Append index 62d7352..1149fc3 100644 --- a/test/CPPDEFINES/fixture/SConstruct-Append +++ b/test/CPPDEFINES/fixture/SConstruct-Append @@ -1,3 +1,5 @@ +DefaultEnvironment(tools=[]) + # Special cases: # https://github.com/SCons/scons/issues/1738 env_1738_2 = Environment(CPPDEFPREFIX='-D') diff --git a/test/CPPDEFINES/fixture/SConstruct-Prepend b/test/CPPDEFINES/fixture/SConstruct-Prepend index 4234de2..67d637c 100644 --- a/test/CPPDEFINES/fixture/SConstruct-Prepend +++ b/test/CPPDEFINES/fixture/SConstruct-Prepend @@ -1,3 +1,4 @@ +DefaultEnvironment(tools=[]) # Special cases: # https://github.com/SCons/scons/issues/1738 env_1738_2 = Environment(CPPDEFPREFIX='-D') -- cgit v0.12