Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: config_settings matching latest minor versions #1738

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/config_settings/construct_config_settings_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
"""Tests for construction of Python version matching config settings."""

load("@//python:versions.bzl", "MINOR_MAPPING")
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
load("@rules_testing//lib:test_suite.bzl", "test_suite")
load("@rules_testing//lib:truth.bzl", "subjects")
Expand All @@ -30,6 +31,7 @@ _subject = rule(
"match_micro": attr.string(),
"match_minor": attr.string(),
"no_match": attr.string(),
"no_match_micro": attr.string(),
},
)

Expand Down Expand Up @@ -74,6 +76,54 @@ def _test_minor_version_matching_impl(env, target):

_tests.append(_test_minor_version_matching)

def _test_latest_micro_version_matching(name):
rt_util.helper_target(
_subject,
name = name + "_subject",
match_minor = select({
"//python/config_settings:is_python_3.12": "matched-3.12",
"//conditions:default": "matched-default",
}),
match_micro = select({
"//python/config_settings:is_python_" + MINOR_MAPPING["3.12"]: "matched-3.12",
"//conditions:default": "matched-default",
}),
no_match_micro = select({
"//python/config_settings:is_python_3.12.0": "matched-3.12",
"//conditions:default": "matched-default",
}),
no_match = select({
"//python/config_settings:is_python_" + MINOR_MAPPING["3.11"]: "matched-3.11",
"//conditions:default": "matched-default",
}),
)

analysis_test(
name = name,
target = name + "_subject",
impl = _test_latest_micro_version_matching_impl,
config_settings = {
str(Label("//python/config_settings:python_version")): "3.12",
},
)

def _test_latest_micro_version_matching_impl(env, target):
target = env.expect.that_target(target)
target.attr("match_minor", factory = subjects.str).equals(
"matched-3.12",
)
target.attr("match_micro", factory = subjects.str).equals(
"matched-3.12",
)
target.attr("no_match_micro", factory = subjects.str).equals(
"matched-default",
)
target.attr("no_match", factory = subjects.str).equals(
"matched-default",
)

_tests.append(_test_latest_micro_version_matching)

def construct_config_settings_test_suite(name):
test_suite(
name = name,
Expand Down
54 changes: 0 additions & 54 deletions tests/toolchains/config_settings/BUILD.bazel

This file was deleted.

27 changes: 0 additions & 27 deletions tests/toolchains/config_settings/want

This file was deleted.

Loading