Complete original edition rules, season safety and verified 1.0 releases (by Codex)
This commit is contained in:
1 parent
e432f20ae7
commit
f0ef79a119
21 files changed
+563
-30
No files matched your search
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
"""Build products and every configured test program, without unused data fixtures."""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
TEST = re.compile(r'^add_test\((?:\[=*\[.*?\]=*\]|"[^"]*"|[^ )]+)\s+"((?:\\.|[^"\\])*)"')
|
||||
HOST = re.compile(r'(?:python(?:[0-9.]+)?|cmake|ctest)(?:\.exe)?$', re.I)
|
||||
|
||||
|
||||
def targets_for_tests(build):
|
||||
build = build.resolve(strict=True)
|
||||
targets = {'openbmh_play', 'openbmh_cli'}
|
||||
tests = 0
|
||||
for file in sorted(build.rglob('CTestTestfile.cmake')):
|
||||
for line in file.read_text(encoding='utf-8').splitlines():
|
||||
if not line.startswith('add_test('):
|
||||
continue
|
||||
match = TEST.match(line)
|
||||
if not match:
|
||||
raise RuntimeError('Unrecognized generated test command; refusing to omit a test')
|
||||
tests += 1
|
||||
command = match.group(1).replace('\\"', '"').replace('\\\\', '\\')
|
||||
executable = Path(command).resolve()
|
||||
if executable.is_relative_to(build):
|
||||
name = executable.name
|
||||
if name.lower().endswith('.exe'):
|
||||
name = name[:-4]
|
||||
targets.add('openbmh_play' if name == 'OpenBMH' else name)
|
||||
elif not HOST.fullmatch(executable.name):
|
||||
raise RuntimeError('Unrecognized external test executable; refusing to omit a test')
|
||||
if not tests:
|
||||
raise RuntimeError('No configured tests found')
|
||||
return sorted(targets), tests
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--build', type=Path, required=True)
|
||||
parser.add_argument('--config', default='Release')
|
||||
parser.add_argument('--parallel', type=int, default=2)
|
||||
parser.add_argument('--list', action='store_true')
|
||||
args = parser.parse_args()
|
||||
targets, count = targets_for_tests(args.build)
|
||||
print(f'{count} configured tests; {len(targets)} product/test build targets', flush=True)
|
||||
if args.list:
|
||||
print('\n'.join(targets))
|
||||
else:
|
||||
subprocess.run(['cmake', '--build', str(args.build), '--config', args.config,
|
||||
'--parallel', str(args.parallel), '--target', *targets], check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
from build_runnable_tests import targets_for_tests
|
||||
|
||||
|
||||
class BuildDiscoveryTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temporary = tempfile.TemporaryDirectory(prefix='ci build ')
|
||||
self.addCleanup(self.temporary.cleanup)
|
||||
self.build = Path(self.temporary.name) / 'build'
|
||||
self.build.mkdir()
|
||||
|
||||
def write(self, text):
|
||||
(self.build / 'CTestTestfile.cmake').write_text(text, encoding='utf-8')
|
||||
|
||||
def test_required_programs_and_optional_data_skip(self):
|
||||
self.write(f'add_test([=[unit]=] "{self.build.as_posix()}/unit_suite.exe")\n'
|
||||
f'add_test([=[private]=] "{self.build.as_posix()}/openbmh_test_skip.exe" "missing input")\n'
|
||||
f'add_test([=[python]=] "{Path(sys.executable).as_posix()}" "check.py")\n')
|
||||
targets, count = targets_for_tests(self.build)
|
||||
self.assertEqual(count, 3)
|
||||
self.assertEqual(targets, ['openbmh_cli', 'openbmh_play', 'openbmh_test_skip', 'unit_suite'])
|
||||
|
||||
def test_nested_test_and_product_output_name(self):
|
||||
self.write(f'add_test([=[version]=] "{self.build.as_posix()}/OpenBMH.exe" "--version")\n')
|
||||
nested = self.build / 'src' / 'ui'
|
||||
nested.mkdir(parents=True)
|
||||
(nested / 'CTestTestfile.cmake').write_text(
|
||||
f'add_test([=[ui]=] "{nested.as_posix()}/ui_suite")\n', encoding='utf-8')
|
||||
targets, count = targets_for_tests(self.build)
|
||||
self.assertEqual(count, 2)
|
||||
self.assertEqual(targets, ['openbmh_cli', 'openbmh_play', 'ui_suite'])
|
||||
|
||||
def test_unknown_external_binary_is_not_silently_dropped(self):
|
||||
outside = self.build.parent / 'unknown-suite'
|
||||
self.write(f'add_test([=[outside]=] "{outside.as_posix()}")\n')
|
||||
with self.assertRaisesRegex(RuntimeError, 'external'):
|
||||
targets_for_tests(self.build)
|
||||
|
||||
def test_unrecognized_command_and_empty_configuration_fail(self):
|
||||
self.write('add_test(unsupported-syntax)\n')
|
||||
with self.assertRaises(RuntimeError):
|
||||
targets_for_tests(self.build)
|
||||
self.write('# no tests\n')
|
||||
with self.assertRaises(RuntimeError):
|
||||
targets_for_tests(self.build)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user