From 580eb10d10e0163cc6e0723129882896f2dd3430 Mon Sep 17 00:00:00 2001 From: Patrick Balestra Date: Wed, 6 Mar 2024 22:57:35 +0100 Subject: [PATCH] Add const_vaues tests --- test/BUILD | 3 + test/const_values_tests.bzl | 115 +++++++++++++++++++++++++++++++++ test/output_file_map_tests.bzl | 1 + 3 files changed, 119 insertions(+) create mode 100644 test/const_values_tests.bzl diff --git a/test/BUILD b/test/BUILD index 11b768b0d..305005997 100644 --- a/test/BUILD +++ b/test/BUILD @@ -2,6 +2,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load(":ast_file_tests.bzl", "ast_file_test_suite") load(":bzl_test.bzl", "bzl_test") load(":compiler_arguments_tests.bzl", "compiler_arguments_test_suite") +load(":const_values_tests.bzl", "const_values_test_suite") load(":coverage_settings_tests.bzl", "coverage_settings_test_suite") load(":debug_settings_tests.bzl", "debug_settings_test_suite") load(":explicit_modules_test.bzl", "explicit_modules_test_suite") @@ -25,6 +26,8 @@ ast_file_test_suite(name = "ast_file") compiler_arguments_test_suite(name = "compiler_arguments") +const_values_test_suite(name = "const_values") + coverage_settings_test_suite(name = "coverage_settings") debug_settings_test_suite(name = "debug_settings") diff --git a/test/const_values_tests.bzl b/test/const_values_tests.bzl new file mode 100644 index 000000000..a3f655bfb --- /dev/null +++ b/test/const_values_tests.bzl @@ -0,0 +1,115 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for `const_values`.""" + +load( + "@build_bazel_rules_swift//test/rules:action_command_line_test.bzl", + "make_action_command_line_test_rule", +) +load( + "@build_bazel_rules_swift//test/rules:provider_test.bzl", + "make_provider_test_rule", + "provider_test", +) + +const_values_test = make_action_command_line_test_rule() + +no_const_values_test = make_action_command_line_test_rule( + config_settings = { + "//command_line_option:features": [ + "-swift._supports_const_value_extraction", + ], + }, +) + +const_values_wmo_test = make_provider_test_rule( + config_settings = { + str(Label("@build_bazel_rules_swift//swift:copt")): [ + "-whole-module-optimization", + ], + }, +) + +def const_values_test_suite(name): + """Test suite for `swift_library` producing .swiftconstvalues files. + + Args: + name: the base name to be used in things created by this macro + """ + + provider_test( + name = "{}_empty_const_values_single_file".format(name), + expected_files = [ + "test/fixtures/debug_settings/simple_objs/Empty.swift.swiftconstvalues", + ], + field = "const_values", + provider = "OutputGroupInfo", + tags = [name], + target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple", + ) + + provider_test( + name = "{}_empty_const_values_multiple_files".format(name), + expected_files = [ + "test/fixtures/multiple_files/multiple_files_objs/Empty.swift.swiftconstvalues", + "test/fixtures/multiple_files/multiple_files_objs/Empty2.swift.swiftconstvalues", + ], + field = "const_values", + provider = "OutputGroupInfo", + tags = [name], + target_under_test = "@build_bazel_rules_swift//test/fixtures/multiple_files", + ) + + const_values_wmo_test( + name = "{}_wmo_single_values_file".format(name), + expected_files = [ + "test/fixtures/multiple_files/multiple_files.swiftconstvalues", + ], + field = "const_values", + provider = "OutputGroupInfo", + tags = [name], + target_under_test = "@build_bazel_rules_swift//test/fixtures/multiple_files", + ) + + const_values_test( + name = "{}_expected_argv".format(name), + expected_argv = [ + "-Xfrontend -const-gather-protocols-file", + "-Xfrontend swift/toolchains/config/const_extract_protocols.json", + "-emit-const-values-path", + "first.swift.swiftconstvalues", + ], + mnemonic = "SwiftCompile", + tags = [name], + target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:first", + ) + + no_const_values_test( + name = "{}_not_expected_argv".format(name), + not_expected_argv = [ + "-Xfrontend -const-gather-protocols-file", + "-Xfrontend swift/toolchains/config/const_extract_protocols.json", + "-emit-const-values-path", + "first.swift.swiftconstvalues", + ], + mnemonic = "SwiftCompile", + tags = [name], + target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:first", + ) + + native.test_suite( + name = name, + tags = [name], + ) diff --git a/test/output_file_map_tests.bzl b/test/output_file_map_tests.bzl index 2f5a0bcc5..4277c761d 100644 --- a/test/output_file_map_tests.bzl +++ b/test/output_file_map_tests.bzl @@ -50,6 +50,7 @@ def output_file_map_test_suite(name): name = "{}_default".format(name), expected_mapping = { "object": "test/fixtures/debug_settings/simple_objs/Empty.swift.o", + "const-values": "test/fixtures/debug_settings/simple_objs/Empty.swift.swiftconstvalues", }, file_entry = "test/fixtures/debug_settings/Empty.swift", output_file_map = "test/fixtures/debug_settings/simple.output_file_map.json",