mirror of
https://github.com/mesonbuild/meson.git
synced 2026-06-24 08:48:03 +00:00
internaltests: Fix test_program_version type (and use subtests)
This was passing a `list[list[str] | str]` to `ExternalProgram(command)`, which is invalid.
This commit is contained in:
committed by
Paolo Bonzini
parent
142f44a3c4
commit
b6f1863c09
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user