xref: /aosp_15_r20/build/bazel/rules/java/bootclasspath_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.
14load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
15load(":bootclasspath.bzl", "bootclasspath")
16load(":import.bzl", "java_import")
17load(":java_system_modules.bzl", "java_system_modules")
18
19def _bootclasspath_test_impl(ctx):
20    env = analysistest.begin(ctx)
21    bootclasspath_target = analysistest.target_under_test(env)
22
23    asserts.true(
24        env,
25        java_common.BootClassPathInfo in bootclasspath_target,
26        "Expected BootClassPathInfo in bootclasspath providers.",
27    )
28    asserts.true(
29        env,
30        len(bootclasspath_target[java_common.BootClassPathInfo].bootclasspath.to_list()) == 1,
31        "Expected bootclasspath to have 1 jars, got %s" % bootclasspath_target[java_common.BootClassPathInfo].bootclasspath,
32    )
33    return analysistest.end(env)
34
35bootclasspath_test = analysistest.make(
36    _bootclasspath_test_impl,
37)
38
39def test_bootclasspath_provider():
40    name = "test_bootclasspath_provider"
41    import_name = name + "_import"
42    other_import_name = name + "_other_import"
43    system_name = name + "_jsm"
44    bootclasspath(
45        name = name + "_target",
46        bootclasspath = [import_name],
47        system = system_name,
48        auxiliary = [import_name],
49        tags = ["manual"],
50    )
51    bootclasspath_test(
52        name = name,
53        target_under_test = name + "_target",
54    )
55    java_system_modules(
56        name = system_name,
57        deps = [other_import_name],
58        tags = ["manual"],
59    )
60    java_import(
61        name = other_import_name,
62        jars = ["a_jar.jar"],
63        tags = ["manual"],
64    )
65    java_import(
66        name = import_name,
67        jars = ["some_jar.jar"],
68        tags = ["manual"],
69    )
70    return name
71
72def bootclasspath_test_suite(name):
73    native.test_suite(
74        name = name,
75        tests = [
76            test_bootclasspath_provider(),
77        ],
78    )
79