diff options
author | Mats Wichmann <mats@linux.com> | 2024-08-27 16:21:54 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2024-08-27 16:43:03 (GMT) |
commit | aca5728fd680cca0182b5873b6d34fcd9f6f2821 (patch) | |
tree | 0641c39134abf5ba07e0623efe7d5305f3d04c5b /testing | |
parent | 6cf21b8298d81fa34f583b60d3fd19a4201d8a04 (diff) | |
download | SCons-aca5728fd680cca0182b5873b6d34fcd9f6f2821.zip SCons-aca5728fd680cca0182b5873b6d34fcd9f6f2821.tar.gz SCons-aca5728fd680cca0182b5873b6d34fcd9f6f2821.tar.bz2 |
Variables testing: confirm space-containing values
The previous commit introduced a change to how the framework handled
arguments, which necessitated some changes in the variables code.
It got too complicated, too many places would need too much logic.
Just accept that the test.run(arguments="...") will never be quite
like the same arguments on the CLI, and just use lists to avoid
things being broken on embedded spaces - those won't be split.
Many tests arleady do this, so it's nothing new. Added a comment
in TestCmd to make it more clear.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'testing')
-rw-r--r-- | testing/framework/TestCmd.py | 12 | ||||
-rw-r--r-- | testing/framework/TestCmdTests.py | 8 | ||||
-rw-r--r-- | testing/framework/test-framework.rst | 12 |
3 files changed, 22 insertions, 10 deletions
diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 5d9aed9..616297a 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -1023,7 +1023,7 @@ class TestCmd: interpreter=None, workdir=None, subdir=None, - verbose=None, + verbose: int = -1, match=None, match_stdout=None, match_stderr=None, @@ -1039,7 +1039,7 @@ class TestCmd: self.description_set(description) self.program_set(program) self.interpreter_set(interpreter) - if verbose is None: + if verbose == -1: try: verbose = max(0, int(os.environ.get('TESTCMD_VERBOSE', 0))) except ValueError: @@ -1178,10 +1178,10 @@ class TestCmd: cmd.extend([f"{k}={v}" for k, v in arguments.items()]) return cmd if isinstance(arguments, str): - # Split into a list for passing to SCons - don't lose - # quotes, and don't break apart quoted substring with space. - # str split() fails on the spaces, shlex.split() on the quotes. - arguments = re.findall(r"(?:\".*?\"|\S)+", arguments) + # Split into a list for passing to SCons. This *will* + # break if the string has embedded spaces as part of a substing - + # use a # list to pass those to avoid the problem. + arguments = arguments.split() cmd.extend(arguments) return cmd diff --git a/testing/framework/TestCmdTests.py b/testing/framework/TestCmdTests.py index 2a6cceb..a2d941d 100644 --- a/testing/framework/TestCmdTests.py +++ b/testing/framework/TestCmdTests.py @@ -2239,13 +2239,13 @@ class command_args_TestCase(TestCmdTestCase): expect = ['python', run_env.workpath('prog'), 'arg1', 'arg2'] self.assertEqual(expect, r) - r = test.command_args('prog', 'python', 'arg1 arg2="quoted"') - expect = ['python', run_env.workpath('prog'), 'arg1', 'arg2="quoted"'] + r = test.command_args('prog', 'python', 'arg1 arg2=value') + expect = ['python', run_env.workpath('prog'), 'arg1', 'arg2=value'] with self.subTest(): self.assertEqual(expect, r) - r = test.command_args('prog', 'python', 'arg1 arg2="quoted with space"') - expect = ['python', run_env.workpath('prog'), 'arg1', 'arg2="quoted with space"'] + r = test.command_args('prog', 'python', ['arg1', 'arg2=with space']) + expect = ['python', run_env.workpath('prog'), 'arg1', 'arg2=with space'] with self.subTest(): self.assertEqual(expect, r) diff --git a/testing/framework/test-framework.rst b/testing/framework/test-framework.rst index 39ec6e3..1a07923 100644 --- a/testing/framework/test-framework.rst +++ b/testing/framework/test-framework.rst @@ -621,6 +621,18 @@ or:: test.must_match(..., match=TestSCons.match_re, ...) +Often you want to supply arguments to SCons when it is invoked +to run a test, which you can do using an *arguments* parameter:: + + test.run(arguments="-O -v FOO=BAR") + +One caveat here: the way the parameter is processed is unavoidably +different from typing on the command line - if you need it not to +be split on spaces, pre-split it yourself, and pass the list, like:: + + test.run(arguments=["-f", "SConstruct2", "FOO=Two Words"]) + + Avoiding tests based on tool existence ====================================== |