1# Copyright 2023 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"""Tests for current_py_cc_headers.""" 16 17load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") 18load("@rules_testing//lib:truth.bzl", "matching") 19load("//tests:cc_info_subject.bzl", "cc_info_subject") 20 21_tests = [] 22 23def _test_current_toolchain_headers(name): 24 analysis_test( 25 name = name, 26 impl = _test_current_toolchain_headers_impl, 27 target = "//python/cc:current_py_cc_headers", 28 config_settings = { 29 "//command_line_option:extra_toolchains": [str(Label("//tests/cc:all"))], 30 }, 31 attrs = { 32 "header": attr.label( 33 default = "//tests/cc:fake_header.h", 34 allow_single_file = True, 35 ), 36 }, 37 ) 38 39def _test_current_toolchain_headers_impl(env, target): 40 # Check that the forwarded CcInfo looks vaguely correct. 41 compilation_context = env.expect.that_target(target).provider( 42 CcInfo, 43 factory = cc_info_subject, 44 ).compilation_context() 45 compilation_context.direct_headers().contains_exactly([ 46 env.ctx.file.header, 47 ]) 48 compilation_context.direct_public_headers().contains_exactly([ 49 env.ctx.file.header, 50 ]) 51 52 # NOTE: The include dir gets added twice, once for the source path, 53 # and once for the config-specific path. 54 compilation_context.system_includes().contains_at_least_predicates([ 55 matching.str_matches("*/fake_include"), 56 ]) 57 58 # Check that the forward DefaultInfo looks correct 59 env.expect.that_target(target).runfiles().contains_predicate( 60 matching.str_matches("*/cc/data.txt"), 61 ) 62 63_tests.append(_test_current_toolchain_headers) 64 65def current_py_cc_headers_test_suite(name): 66 test_suite( 67 name = name, 68 tests = _tests, 69 ) 70