xref: /aosp_15_r20/build/bazel/rules/sysprop/sysprop_library_test.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1# Copyright (C) 2022 The Android Open Source Project
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
15load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
16load(":sysprop_library.bzl", "SyspropGenInfo", "sysprop_library")
17
18def _provides_src_files_test_impl(ctx):
19    env = analysistest.begin(ctx)
20
21    target_under_test = analysistest.target_under_test(env)
22    asserts.equals(
23        env,
24        ["foo.sysprop", "bar.sysprop"],
25        [src.label.name for src in target_under_test[SyspropGenInfo].srcs],
26    )
27
28    return analysistest.end(env)
29
30provides_src_files_test = analysistest.make(
31    _provides_src_files_test_impl,
32)
33
34def _test_provides_src_files():
35    name = "provides_src_files"
36    test_name = name + "_test"
37    sysprop_library(
38        name = name,
39        srcs = ["foo.sysprop", "bar.sysprop"],
40        tags = ["manual"],
41    )
42    provides_src_files_test(
43        name = test_name,
44        target_under_test = name,
45    )
46    return test_name
47
48def sysprop_library_test_suite(name):
49    native.test_suite(
50        name = name,
51        tests = [
52            _test_provides_src_files(),
53        ],
54    )
55