xref: /aosp_15_r20/external/pigweed/pw_build/pw_copy_and_patch_file_test.bzl (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2024 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14"""Test helpers for pw_copy_and_patch_file"""
15
16load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
17load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
18load("//pw_build:pw_copy_and_patch_file.bzl", "pw_copy_and_patch_file")
19
20def pw_copy_and_patch_file_test(*, name, src, patch_file, expected, out, **kwargs):
21    """Validates that a patched files has the expected result.
22
23    Args:
24      name: The name of the target.
25      src: The source file to be patched.
26      out: The output file containing the patched contents.
27      patch_file: The patch file.
28      expected: The expected result of appling the patch.
29      **kwargs: Passed to pw_copy_and_patch_file.
30    """
31    pw_copy_and_patch_file(
32        name = name + ".test",
33        src = src,
34        out = out,
35        patch_file = patch_file,
36        target_compatible_with = incompatible_with_mcu(),
37        testonly = True,
38        **kwargs
39    )
40    diff_test(
41        name = name,
42        file1 = expected,
43        file2 = ":" + name + ".test",
44        **kwargs
45    )
46