1# Copyright 2022 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 15"""Unit tests for starlark helpers 16See https://docs.bazel.build/versions/main/skylark/testing.html#for-testing-starlark-utilities 17""" 18 19load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") 20load("//python:versions.bzl", "MINOR_MAPPING", "TOOL_VERSIONS") 21 22required_platforms = [ 23 "x86_64-apple-darwin", 24 "x86_64-unknown-linux-gnu", 25] 26 27def _smoke_test_impl(ctx): 28 env = unittest.begin(ctx) 29 for version in TOOL_VERSIONS.keys(): 30 platforms = TOOL_VERSIONS[version]["sha256"] 31 for required_platform in required_platforms: 32 asserts.true( 33 env, 34 required_platform in platforms.keys(), 35 "Missing platform {} for version {}".format(required_platform, version), 36 ) 37 for minor in MINOR_MAPPING: 38 version = MINOR_MAPPING[minor] 39 asserts.true( 40 env, 41 version in TOOL_VERSIONS.keys(), 42 "Missing version {} in TOOL_VERSIONS".format(version), 43 ) 44 return unittest.end(env) 45 46# The unittest library requires that we export the test cases as named test rules, 47# but their names are arbitrary and don't appear anywhere. 48_t0_test = unittest.make(_smoke_test_impl) 49 50def versions_test_suite(name): 51 unittest.suite(name, _t0_test) 52