Meta: Add test command to ladybird.py

This commit is contained in:
Ashton 2025-05-20 02:39:32 -07:00 committed by Andrew Kaster
commit c51abfb2ca
Notes: github-actions[bot] 2025-05-21 17:37:06 +00:00

View file

@ -86,6 +86,11 @@ def main(platform):
build_parser.add_argument('args', nargs=argparse.REMAINDER,
help='Additional arguments passed through to the build system')
test_parser = subparsers.add_parser(
'test', help='Runs the unit tests on the build host', parents=[preset_parser, compiler_parser])
test_parser.add_argument('--pattern', required=False,
help='Limits the tests that are ran to those that match the regex pattern')
args = parser.parse_args()
kwargs = vars(args)
command = kwargs.pop('command', None)
@ -104,6 +109,10 @@ def main(platform):
if command == 'build':
build_dir = _configure_main(platform, **kwargs)
_build_main(build_dir, **kwargs)
elif command == 'test':
build_dir = _configure_main(platform, **kwargs)
_build_main(build_dir)
_test_main(build_dir, **kwargs)
def _configure_main(platform, **kwargs):
@ -292,6 +301,34 @@ def _build_main(build_dir, **kwargs):
sys.exit(1)
def _test_main(build_dir, **kwargs):
build_preset = kwargs.get('preset')
test_args = [
'ctest',
'--preset',
build_preset,
'--output-on-failure',
'--test-dir',
str(build_dir),
]
test_name_pattern = kwargs.get('pattern', None)
if test_name_pattern:
test_args.extend([
'-R',
test_name_pattern,
])
try:
subprocess.check_call(test_args)
except subprocess.CalledProcessError as e:
msg = 'Unable to test ladybird '
if test_name_pattern:
msg += f'name pattern "{test_name_pattern}"'
else:
msg += 'project'
_print_process_stderr(e, msg)
sys.exit(1)
def _print_process_stderr(e, msg):
err_details = f': {e.stderr}' if e.stderr else ''
print(f'{msg}{err_details}', file=sys.stderr)