8000 test: config_settings matching latest minor versions (#1738) · philsc/rules_python@e7f8f0f · GitHub
[go: up one dir, main page]

Skip to content

Commit e7f8f0f

Browse files
authored
test: config_settings matching latest minor versions (bazel-contrib#1738)
This is a followup to bazel-contrib#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.
1 parent e53b0b7 commit e7f8f0f

File tree

3 files changed

+50
-81
lines changed

3 files changed

+50
-81
lines changed

tests/config_settings/construct_config_settings_tests.bzl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Tests for construction of Python version matching config settings."""
1515

16+
load("@//python:versions.bzl", "MINOR_MAPPING")
1617
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
1718
load("@rules_testing//lib:test_suite.bzl", "test_suite")
1819
load("@rules_testing//lib:truth.bzl", "subjects")
@@ -30,6 +31,7 @@ _subject = rule(
3031
< 8000 span class=pl-s>"match_micro": attr.string(),
3132
"match_minor": attr.string(),
3233
"no_match": attr.string(),
34+
"no_match_micro": attr.string(),
3335
},
3436
)
3537

@@ -74,6 +76,54 @@ def _test_minor_version_matching_impl(env, target):
7476

7577
_tests.append(_test_minor_version_matching)
7678

79+
def _test_latest_micro_version_matching(name):
80+
rt_util.helper_target(
81+
_subject,
82+
name = name + "_subject",
83+
match_minor = select({
84+
"//python/config_settings:is_python_3.12": "matched-3.12",
85+
"//conditions:default": "matched-default",
86+
}),
87+
match_micro = select({
88+
"//python/config_settings:is_python_" + MINOR_MAPPING["3.12"]: "matched-3.12",
89+
"//conditions:default": "matched-default",
90+
}),
91+
no_match_micro = select({
92+
"//python/config_settings:is_python_3.12.0": "matched-3.12",
93+
"//conditions:default": "matched-default",
94+
}),
95+
no_match = select({
96+
"//python/config_settings:is_python_" + MINOR_MAPPING["3.11"]: "matched-3.11",
97+
"//conditions:default": "matched-default",
98+
}),
99+
)
100+
101+
analysis_test(
102+
name = name,
103+
target = name + "_subject",
104+
impl = _test_latest_micro_version_matching_impl,
105+
config_settings = {
106+
str(Label("//python/config_settings:python_version")): "3.12",
107+
},
108+
)
109+
110+
def _test_latest_micro_version_matching_impl(env, target):
111+
target = env.expect.that_target(target)
112+
target.attr("match_minor", factory = subjects.str).equals(
113+
"matched-3.12",
114+
)
115+
target.attr("match_micro", factory = subjects.str).equals(
116+
"matched-3.12",
117+
)
118+
target.attr("no_match_micro", factory = subjects.str).equals(
119+
"matched-default",
120+
)
121+
target.attr("no_match", factory = subjects.str).equals(
122+
"matched-default",
123+
)
124+
125+
_tests.append(_test_latest_micro_version_matching)
126+
77127
def construct_config_settings_test_suite(name):
78128
test_suite(
79129
name = name,

tests/toolchains/config_settings/BUILD.bazel

Lines changed: 0 additions & 54 deletions
This file was deleted.

tests/toolchains/config_settings/want

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0