1"""
2Copyright (C) 2023 The Android Open Source Project
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15"""
16
17load("@bazel_skylib//lib:paths.bzl", "paths")
18load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
19load("@rules_testing//lib:util.bzl", "TestingAspectInfo", testing_util = "util")
20load(":cc_info_subject.bzl", "cc_info_subject")
21load(":cc_library_headers.bzl", "cc_library_headers")
22
23def _cc_library_headers_test_impl(env, target):
24    target_subject = env.expect.that_target(target)
25    target_subject.has_provider(CcInfo)
26    info_subject = target_subject.provider(CcInfo, factory = cc_info_subject)
27    info_subject.includes().contains_exactly([
28        "build/bazel/rules/cc",
29        paths.join(target[TestingAspectInfo].bin_path, "build/bazel/rules/cc"),
30        "build/bazel/rules/cc/incl",
31        paths.join(target[TestingAspectInfo].bin_path, "build/bazel/rules/cc/incl"),
32        "abs/includes",
33        paths.join(target[TestingAspectInfo].bin_path, "abs/includes"),
34    ])
35    info_subject.system_includes().contains_exactly([
36        "build/bazel/rules/cc/sys",
37        paths.join(target[TestingAspectInfo].bin_path, "build/bazel/rules/cc/sys"),
38    ])
39    info_subject.headers().contains_exactly([
40        "build/bazel/rules/cc/foo.h",
41    ])
42
43def test_cc_library_headers(name):
44    lib_name = name + "_target"
45    testing_util.helper_target(
46        cc_library_headers,
47        name = lib_name,
48        hdrs = ["foo.h"],
49        export_includes = [".", "incl"],
50        export_system_includes = ["sys"],
51        export_absolute_includes = ["abs/includes"],
52    )
53    analysis_test(name, impl = _cc_library_headers_test_impl, target = lib_name)
54
55def cc_library_headers_test_suite(name):
56    test_suite(
57        name = name,
58        tests = [
59            test_cc_library_headers,
60        ],
61    )
62