|
| 1 | +# Copyright 2021 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 | +"""Tests for //java/private:android_support.bzl""" |
| 15 | + |
| 16 | +load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") |
| 17 | +load("//java/common:java_info.bzl", "JavaInfo") |
| 18 | +load("//java/private:android_support.bzl", "android_support") |
| 19 | + |
| 20 | +def _impl(ctx): |
| 21 | + return [ |
| 22 | + android_support.enable_implicit_sourceless_deps_exports_compatibility(ctx.attr.dep[JavaInfo]), |
| 23 | + ] |
| 24 | + |
| 25 | +my_rule = rule( |
| 26 | + implementation = _impl, |
| 27 | + attrs = { |
| 28 | + "dep": attr.label(), |
| 29 | + }, |
| 30 | +) |
| 31 | + |
| 32 | +def _test_enable_implicit_sourceless_deps_exports_compatibility(name): |
| 33 | + analysis_test( |
| 34 | + name = name, |
| 35 | + impl = _test_enable_implicit_sourceless_deps_exports_compatibility_impl, |
| 36 | + targets = { |
| 37 | + "foo": Label(":foo"), |
| 38 | + "bar": Label(":bar"), |
| 39 | + }, |
| 40 | + ) |
| 41 | + |
| 42 | +def _test_enable_implicit_sourceless_deps_exports_compatibility_impl(env, targets): |
| 43 | + # TODO(hvd): write a ProviderSubject for JavaInfo |
| 44 | + foo_javainfo = targets.foo[JavaInfo] |
| 45 | + bar_javainfo = targets.bar[JavaInfo] |
| 46 | + for attr in ["transitive_runtime_jars", "compile_jars", "transitive_compile_time_jars", "full_compile_jars", "_transitive_full_compile_time_jars", "_compile_time_java_dependencies"]: |
| 47 | + env.expect.that_bool(getattr(foo_javainfo, attr) == getattr(bar_javainfo, attr)).equals(True) |
| 48 | + env.expect.that_depset_of_files(foo_javainfo.plugins.processor_jars).contains_exactly([ |
| 49 | + "java/test/private/libmy_plugin.jar", |
| 50 | + ]) |
| 51 | + env.expect.that_depset_of_files(bar_javainfo.plugins.processor_jars).contains_exactly([]) |
| 52 | + |
| 53 | +def android_support_tests(name): |
| 54 | + test_suite( |
| 55 | + name = name, |
| 56 | + tests = [ |
| 57 | + _test_enable_implicit_sourceless_deps_exports_compatibility, |
| 58 | + ], |
| 59 | + ) |
0 commit comments