blob: 4e868583c0f158350aa0dfe62966cca520825b7a [file] [log] [blame]
# Copyright 2023 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.
"""Full test of bazel module."""
from __future__ import annotations
import dataclasses
from typing import Generator, TYPE_CHECKING
from PB.recipe_modules.pigweed.bazel.tests.full import InputProperties
from recipe_engine import post_process
if TYPE_CHECKING: # pragma: no cover
from recipe_engine import config_types, recipe_test_api
DEPS = [
'pigweed/bazel',
'recipe_engine/buildbucket',
'recipe_engine/path',
]
PROPERTIES = InputProperties
@dataclasses.dataclass
class _FakeCheckoutContext:
root: config_types.Path
def RunSteps(api, props): # pylint: disable=invalid-name
# pylint: disable=missing-function-docstring
runner = api.bazel.new_runner(
checkout=_FakeCheckoutContext(api.path.start_dir),
options=props.bazel_options,
)
runner.run()
# Coverage only.
runner.ensure()
def GenTests(api) -> Generator[recipe_test_api.TestData, None, None]:
yield api.test(
'fixed',
api.bazel.properties(bazelisk_version='1.19.0'),
api.post_process(post_process.MustRun, 'ensure bazelisk'),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'latest',
api.bazel.properties(program=['default']),
api.post_process(post_process.MustRun, 'ensure bazelisk'),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'upload-but-tryjob',
api.buildbucket.try_build(),
api.bazel.properties(),
api.bazel.config(remote_cache=True, upload_local_results=True),
api.post_process(post_process.MustRun, 'ensure bazelisk'),
api.post_process(
post_process.MustRun,
'ignoring upload_local_results because this is a tryjob',
),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'upload-but-no-cache',
api.buildbucket.ci_build(),
api.bazel.properties(),
api.bazel.config(remote_cache=False, upload_local_results=True),
api.post_process(post_process.MustRun, 'ensure bazelisk'),
api.post_process(
post_process.MustRun,
'ignoring upload_local_results since remote_cache is False',
),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'upload',
api.buildbucket.ci_build(),
api.bazel.properties(),
api.bazel.config(remote_cache=True, upload_local_results=True),
api.post_process(post_process.MustRun, 'ensure bazelisk'),
api.post_process(
post_process.DoesNotRun,
'ignoring upload_local_results because this is a tryjob',
),
api.post_process(
post_process.DoesNotRun,
'ignoring upload_local_results since remote_cache is False',
),
api.post_process(post_process.DropExpectation),
)