From b6f1863c09a689024f1195dfbbcd3e70b353af96 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 11 Jun 2026 09:23:01 -0700 Subject: [PATCH] internaltests: Fix test_program_version type (and use subtests) This was passing a `list[list[str] | str]` to `ExternalProgram(command)`, which is invalid. --- unittests/internaltests.py | 45 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/unittests/internaltests.py b/unittests/internaltests.py index d1ebb4af5..4229769b9 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -773,33 +773,36 @@ class InternalTests(unittest.TestCase): for lib in ('pthread', 'm', 'c', 'dl', 'rt'): self.assertNotIn(f'lib{lib}.a', link_arg, msg=link_args) - def test_program_version(self): + def test_program_version(self) -> None: with tempfile.TemporaryDirectory() as tmpdir: script_path = Path(tmpdir) / 'script.py' script_path.write_text('import sys\nprint(sys.argv[1])\n', encoding='utf-8') script_path.chmod(0o755) - for output, expected in { - '': None, - '1': None, - '1.2.4': '1.2.4', - '1 1.2.4': '1.2.4', - 'foo version 1.2.4': '1.2.4', - 'foo 1.2.4.': '1.2.4', - 'foo 1.2.4': '1.2.4', - 'foo 1.2.4 bar': '1.2.4', - 'foo 10.0.0': '10.0.0', - '50 5.4.0': '5.4.0', - 'This is perl 5, version 40, subversion 0 (v5.40.0)': '5.40.0', - 'git version 2.48.0.rc1': '2.48.0', - }.items(): - prog = ExternalProgram('script', command=[python_command, str(script_path), output], silent=True) + inputs: list[tuple[str, str | None]] = [ + ('', None), + ('1', None), + ('1.2.4', '1.2.4'), + ('1 1.2.4', '1.2.4'), + ('foo version 1.2.4', '1.2.4'), + ('foo 1.2.4.', '1.2.4'), + ('foo 1.2.4', '1.2.4'), + ('foo 1.2.4 bar', '1.2.4'), + ('foo 10.0.0', '10.0.0'), + ('50 5.4.0', '5.4.0'), + ('This is perl 5, version 40, subversion 0 (v5.40.0)', '5.40.0'), + ('git version 2.48.0.rc1', '2.48.0'), + ] - if expected is None: - with self.assertRaisesRegex(MesonException, 'Could not find a version number'): - prog.get_version() - else: - self.assertEqual(prog.get_version(), expected) + for output, expected in inputs: + prog = ExternalProgram('script', command=python_command + [str(script_path), output], silent=True) + + with self.subTest(output=output, expected=expected): + if expected is None: + with self.assertRaisesRegex(MesonException, 'Could not find a version number'): + prog.get_version() + else: + self.assertEqual(prog.get_version(), expected) def test_version_compare(self): comparefunc = mesonbuild.mesonlib.version_compare_many