xref: /aosp_15_r20/external/bazelbuild-rules_testing/lib/private/instrumented_files_info_subject.bzl (revision d605057434dcabba796c020773aab68d9790ff9f)
1# Copyright 2023 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""# InstrumentedFilesInfoSubject"""
15
16load(":depset_file_subject.bzl", "DepsetFileSubject")
17
18def _instrumented_files_info_subject_new(info, *, meta):
19    """Creates a subject to assert on `InstrumentedFilesInfo` providers.
20
21    Method: InstrumentedFilesInfoSubject.new
22
23    Args:
24        info: ([`InstrumentedFilesInfo`]) provider instance.
25        meta: ([`ExpectMeta`]) the meta data about the call chain.
26
27    Returns:
28        An `InstrumentedFilesInfoSubject` struct.
29    """
30    self = struct(
31        actual = info,
32        meta = meta,
33    )
34    public = struct(
35        actual = info,
36        instrumented_files = lambda *a, **k: _instrumented_files_info_subject_instrumented_files(self, *a, **k),
37        metadata_files = lambda *a, **k: _instrumented_files_info_subject_metadata_files(self, *a, **k),
38    )
39    return public
40
41def _instrumented_files_info_subject_instrumented_files(self):
42    """Returns a `DesetFileSubject` of the instrumented files.
43
44    Method: InstrumentedFilesInfoSubject.instrumented_files
45
46    Args:
47        self: implicitly added
48    """
49    return DepsetFileSubject.new(
50        self.actual.instrumented_files,
51        meta = self.meta.derive("instrumented_files()"),
52    )
53
54def _instrumented_files_info_subject_metadata_files(self):
55    """Returns a `DesetFileSubject` of the metadata files.
56
57    Method: InstrumentedFilesInfoSubject.metadata_files
58
59    Args:
60        self: implicitly added
61    """
62    return DepsetFileSubject.new(
63        self.actual.metadata_files,
64        meta = self.meta.derive("metadata_files()"),
65    )
66
67# We use this name so it shows up nice in docs.
68# buildifier: disable=name-conventions
69InstrumentedFilesInfoSubject = struct(
70    new = _instrumented_files_info_subject_new,
71    instrumented_files = _instrumented_files_info_subject_instrumented_files,
72    metadata_files = _instrumented_files_info_subject_metadata_files,
73)
74