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

Record warnings from the Xcode rules as structured information in dummy actions so that we can test them #333

Draft
wants to merge 3 commits into
base: bj/fork-the-xcode-rules-from-bazel-built-in-starlark-into-apple_support
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bzl_library(
"//lib:xcode_support",
"//xcode:available_xcodes",
"//xcode:xcode_config",
"//xcode:xcode_config_alias",
"//xcode:xcode_version",
"@bazel_skylib//lib:unittest",
],
Expand Down
63 changes: 63 additions & 0 deletions test/test_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

"""Common Starlark helpers used by apple_support tests."""

load("@bazel_skylib//lib:unittest.bzl", "analysistest")

visibility(["//test/..."])

# Common tags used for all test fixtures to ensure that they don't build unless
Expand All @@ -22,6 +24,67 @@ FIXTURE_TAGS = [
"manual",
]

def assert_warning(env, msg_id, data = None):
"""Asserts that a warning was printed.

The logic in this helper is specifically meant to handle warnings printed by
`xcode_config.bzl`, because we want to preserve the behavior of the original
rules and their tests.

Args:
env: The analysis test environment.
msg_id: The fixed identifier of the warning message.
data: The semicolon-delimited, sorted by key, `key=value` string
representation of the format arguments for the message, if any.
"""
expected = "Warning:{}".format(msg_id)
if data:
expected += ":{}".format(data)

found_warnings = []

actions = analysistest.target_actions(env)
for action in actions:
mnemonic = action.mnemonic
if mnemonic == expected:
return
if mnemonic.startswith("Warning:"):
found_warnings.append(mnemonic)

found_warnings_msg = ""
if found_warnings:
found_warnings_msg = "; the following warnings were emitted:\n{}".format(
"\n".join(found_warnings),
)

analysistest.fail(
env,
"Expected warning '{}' was not emitted{}".format(
expected,
found_warnings_msg,
),
)

def find_action(env, mnemonic):
"""Finds the first action with the given mnemonic in the target under test.

This generates an analysis test failure if no action was found.

Args:
env: The analysis test environment.
mnemonic: The mnemonic to find.

Returns:
The first action matching the mnemonic, or `None` if none was found.
"""
actions = analysistest.target_actions(env)
for action in actions:
if action.mnemonic == mnemonic:
return action

analysistest.fail(env, "No '{}' action found".format(mnemonic))
return None

def make_unique_namer(*, prefix, index):
"""Returns a function used to generate unique names in a package.

Expand Down
Loading