Skip to content
Closed
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
6 changes: 3 additions & 3 deletions rust/private/lint_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ LINT_TEST_COMMON_ATTRS = {
),
"_runner": attr.label(
doc = "The shared runner (prints/inspects collected marker paths).",
cfg = "exec",
cfg = config.exec("test"),
executable = True,
default = Label("//rust/private/lint_test_runner"),
),
Expand Down Expand Up @@ -116,7 +116,7 @@ def lint_test_rule_impl(ctx, info_provider, output_group_names):
list: `[DefaultInfo, RunEnvironmentInfo, OutputGroupInfo]` for the
test target.
"""
is_windows = ctx.executable._runner.extension == ".exe"
is_windows = ctx.executable._runner.extension == "exe"
runner = ctx.actions.declare_file("{}{}".format(
ctx.label.name,
".exe" if is_windows else "",
Expand All @@ -140,7 +140,7 @@ def lint_test_rule_impl(ctx, info_provider, output_group_names):
)

workspace_name = ctx.workspace_name
markers_env = ctx.configuration.host_path_separator.join([
markers_env = (";" if is_windows else ":").join([
rlocationpath(f, workspace_name)
for f in checks.to_list()
])
Expand Down
18 changes: 18 additions & 0 deletions test/unit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@ package(default_visibility = ["//visibility:public"])
exports_files([
"common.bzl",
])

# Distinct executable platforms let analysis tests verify the test execution
# group without running an x86_64 test binary on an arm64 host.
platform(
name = "macos_aarch64",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
],
)

platform(
name = "macos_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
)
79 changes: 79 additions & 0 deletions test/unit/lint_tests/lint_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,55 @@ def _make_transitive_count_test(marker_suffix, output_group_name):
clippy_transitive_test = _make_transitive_count_test(".clippy.ok", "clippy_checks")
rustfmt_transitive_test = _make_transitive_count_test(".rustfmt.ok", "rustfmt_checks")

_RunnerInfo = provider(fields = {"file": "Underlying lint runner executable"})

def _runner_aspect_impl(_target, ctx):
return [_RunnerInfo(file = ctx.rule.attr._runner[DefaultInfo].files_to_run.executable)]

_runner_aspect = aspect(implementation = _runner_aspect_impl)

def _runner_format_test_impl(ctx):
env = analysistest.begin(ctx)
target = analysistest.target_under_test(env)
runner = target[_RunnerInfo].file
executable = target[DefaultInfo].files_to_run.executable

asserts.equals(env, runner.extension, executable.extension)

markers = target[RunEnvironmentInfo].environment["RUST_LINT_TEST_MARKERS"]
separator = ";" if runner.extension == "exe" else ":"
asserts.equals(env, 1, markers.count(separator))

return analysistest.end(env)

_runner_format_test = analysistest.make(
_runner_format_test_impl,
extra_target_under_test_aspects = [_runner_aspect],
)

def _runner_platform_test_impl(ctx):
env = analysistest.begin(ctx)
target = analysistest.target_under_test(env)
runner = target[_RunnerInfo].file
asserts.true(
env,
runner.path.startswith("bazel-out/macos_x86_64-"),
"Expected the test-platform runner, got {}".format(runner.path),
)
return analysistest.end(env)

_runner_platform_test = analysistest.make(
_runner_platform_test_impl,
config_settings = {
"//command_line_option:extra_execution_platforms": [
str(Label("//test/unit:macos_aarch64")),
str(Label("//test/unit:macos_x86_64")),
],
"//command_line_option:platforms": str(Label("//test/unit:macos_x86_64")),
},
extra_target_under_test_aspects = [_runner_aspect],
)

def lint_tests_suite(name):
"""Wire up the fixture graph and the two analysistests.

Expand Down Expand Up @@ -131,10 +180,40 @@ def lint_tests_suite(name):
target_under_test = ":rustfmt_fixture",
)

_runner_format_test(
name = "clippy_runner_format_test",
target_under_test = ":clippy_fixture",
)
_runner_format_test(
name = "rustfmt_runner_format_test",
target_under_test = ":rustfmt_fixture",
)

_runner_platform_test(
name = "clippy_runner_platform_test",
target_under_test = ":clippy_fixture",
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
],
)
_runner_platform_test(
name = "rustfmt_runner_platform_test",
target_under_test = ":rustfmt_fixture",
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
],
)

native.test_suite(
name = name,
tests = [
":clippy_transitive_test",
":rustfmt_transitive_test",
":clippy_runner_format_test",
":rustfmt_runner_format_test",
":clippy_runner_platform_test",
":rustfmt_runner_platform_test",
],
)