Skip to content

Commit

Permalink
test: config_settings matching latest minor versions (#1738)
Browse files Browse the repository at this point in the history
This is a followup to #1720 to add better tests as commented in the PR
and we ensure that we match correctly when the config setting is
configured to a minor version.
  • Loading branch information
aignas committed Jan 31, 2024
1 parent e53b0b7 commit e7f8f0f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 81 deletions.
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.

0 comments on commit e7f8f0f

Please sign in to comment.