Skip to content

Commit e106ef9

Browse files
committed
add test
1 parent 8aa6918 commit e106ef9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

tests/pypi/env_marker_setting/env_marker_setting_tests.bzl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,45 @@
33
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
44
load("@rules_testing//lib:test_suite.bzl", "test_suite")
55
load("@rules_testing//lib:util.bzl", "TestingAspectInfo")
6+
load("//python/private/pypi:env_marker_info.bzl", "EnvMarkerInfo") # buildifier: disable=bzl-visibility
67
load("//python/private/pypi:env_marker_setting.bzl", "env_marker_setting") # buildifier: disable=bzl-visibility
7-
load("//tests/support:support.bzl", "PYTHON_VERSION")
8+
load("//tests/support:support.bzl", "PIP_ENV_MARKER_CONFIG", "PYTHON_VERSION")
9+
10+
def _custom_env_markers_impl(ctx):
11+
return [EnvMarkerInfo(env = {
12+
"os_name": "testos",
13+
})]
14+
15+
_custom_env_markers = rule(
16+
implementation = _custom_env_markers_impl,
17+
)
818

919
_tests = []
1020

21+
def _test_custom_env_markers(name):
22+
def _impl(env, target):
23+
env.expect.where(
24+
expression = target[TestingAspectInfo].attrs.expression,
25+
).that_str(
26+
target[config_common.FeatureFlagInfo].value,
27+
).equals("TRUE")
28+
29+
env_marker_setting(
30+
name = name + "_subject",
31+
expression = "os_name == 'testos'",
32+
)
33+
_custom_env_markers(name = name + "_env")
34+
analysis_test(
35+
name = name,
36+
impl = _impl,
37+
target = name + "_subject",
38+
config_settings = {
39+
PIP_ENV_MARKER_CONFIG: str(Label(name + "_env")),
40+
},
41+
)
42+
43+
_tests.append(_test_custom_env_markers)
44+
1145
def _test_expr(name):
1246
def impl(env, target):
1347
env.expect.where(

tests/support/support.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CROSSTOOL_TOP = Label("//tests/support/cc_toolchains:cc_toolchain_suite")
3737
ADD_SRCS_TO_RUNFILES = str(Label("//python/config_settings:add_srcs_to_runfiles"))
3838
BOOTSTRAP_IMPL = str(Label("//python/config_settings:bootstrap_impl"))
3939
EXEC_TOOLS_TOOLCHAIN = str(Label("//python/config_settings:exec_tools_toolchain"))
40+
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config"))
4041
PRECOMPILE = str(Label("//python/config_settings:precompile"))
4142
PRECOMPILE_SOURCE_RETENTION = str(Label("//python/config_settings:precompile_source_retention"))
4243
PYC_COLLECTION = str(Label("//python/config_settings:pyc_collection"))

0 commit comments

Comments
 (0)