1# Copyright (C) 2023 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", "asserts", "unittest") 16load("//build/bazel/rules/java:versions.bzl", "java_versions") 17load("//build/bazel/rules/common:api.bzl", "api") 18 19def _get_java_version_test_impl(ctx): 20 env = unittest.begin(ctx) 21 22 _VERSIONS_UNDER_TEST = { 23 (None, api.FUTURE_API_LEVEL): 17, 24 (None, 23): 7, 25 (None, 33): 11, 26 ("1.7", api.FUTURE_API_LEVEL): 7, 27 ("1.7", 23): 7, 28 ("1.8", 33): 8, 29 (None, None): 17, 30 } 31 for java_sdk_version, expected_java_version in _VERSIONS_UNDER_TEST.items(): 32 java_version = java_sdk_version[0] 33 sdk_version = java_sdk_version[1] 34 asserts.equals(env, expected_java_version, java_versions.get_version(java_version, sdk_version), "unexpected java version for java_version %s and sdk_version %s" % (java_version, sdk_version)) 35 36 return unittest.end(env) 37 38get_java_version_test = unittest.make(_get_java_version_test_impl) 39 40def versions_test_suite(name): 41 unittest.suite( 42 name, 43 get_java_version_test, 44 ) 45