blob: ccdf4bf0962e16803b221d40aa4dc352cb5866a4 [file]
# Copyright 2026 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Tests for static_checks regexp matching."""
from __future__ import annotations
from collections.abc import Iterator
from typing import Any
from recipe_engine import post_process, recipe_api, recipe_test_api
from PB.recipe_engine import result as result_pb
from PB.recipes.pigweed.static_checks import InputProperties
from RECIPE_MODULES.pigweed.raw_result import api as raw_result_api
DEPS = [
'pigweed/checkout',
'pigweed/raw_result',
'pigweed/static_checks',
'recipe_engine/properties',
]
PROPERTIES = InputProperties
@raw_result_api.wrap_run_steps
def RunSteps(
api: recipe_api.RecipeScriptApi, props: InputProperties
) -> result_pb.RawResult | None:
api.static_checks(props)
return None
def must_run(
api: recipe_test_api.RecipeTestApi, step: str
) -> recipe_test_api.TestData:
return api.post_check(post_process.MustRun, step)
def GenTests(
api: recipe_test_api.RecipeTestApi,
) -> Iterator[recipe_test_api.TestData]:
def test(
name: str,
msg: str,
*args: Any,
regexp: str,
failure_msg: str = '',
status: str = 'SUCCESS',
**kwargs: Any,
) -> recipe_test_api.TestData:
return api.test(
f'regexp.{name}',
api.properties(
commit_message_regexp=regexp,
commit_message_regexp_failure_message=failure_msg,
),
api.checkout.try_test_data(),
api.static_checks.change_details(msg),
*args,
api.post_process(post_process.DropExpectation),
status=status,
**kwargs,
)
yield test(
'pass',
'Bug: b/99999999999999999999999999999999999999999999999999999',
must_run(api, 'check regexp.matches'),
regexp=r'.*Bug: b/\d+.*',
)
yield test(
'fail',
'message',
must_run(api, 'check regexp.does not match'),
regexp=r'.*Bug: b/\d+.*',
status='FAILURE',
)
yield test(
'fail-msg',
'message',
must_run(api, 'check regexp.does not match'),
must_run(api, 'check regexp.more details'),
regexp=r'.*Bug: b/\d+.*',
failure_msg='Did not reference a bug.',
status='FAILURE',
)