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

Fix unit test attr forwarding #927

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

luispadron
Copy link
Collaborator

The test.bzl macros were incorrectly forwarding some of the attrs like features. This was leading to silent errors where things passed via features were dropped (such as main thread checking). This PR fixes the macro by properly forwarding ALL supported unit test attrs to the unit test rule.

rules/test.bzl Outdated
test_attrs = {k: v for (k, v) in kwargs.items() if k not in _APPLE_BUNDLE_ATTRS}
test_attrs = {k: v for (k, v) in kwargs.items() if k in _IOS_TEST_KWARGS}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been broken for a while it seems but afaik the right logic here is to grab the attrs for the unit test rule.. not what it was originally doing. Without this change features is dropped because it appars in _APPLE_BUNDLE_ATTRS (because every rule supports the features attr).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is this might have been to support custom rules with attributes unknown to this macro?

Copy link
Collaborator Author

@luispadron luispadron Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to maintain the original logic with the addition of including implicit rule attrs as well (like features)

The `test.bzl` macros were incorrectly forwarding some of the attrs like `features`. This was leading to silent errors where things passed via `features` were dropped (such as main thread checking).
This PR fixes the macro by properly forwarding ALL supported unit test attrs to the unit test rule.
@luispadron luispadron force-pushed the luis/fix-attr-forwarding-for-test-rules branch from 5c042d8 to 37659c1 Compare November 18, 2024 18:13
@@ -45,6 +43,22 @@ _APPLE_BUNDLE_ATTRS = {
]
}

# See: https://bazel.build/reference/be/common-definitions#common-attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if bazel's newer version contains new common attribute, we need to update this list right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yeah, however most of these attrs are unused

@@ -104,7 +118,7 @@ def _make_test(name, test_rule, **kwargs):
Helper to create an individual test
"""
runner = kwargs.pop("runner", None) or _DEFAULT_APPLE_TEST_RUNNER
test_attrs = {k: v for (k, v) in kwargs.items() if k not in _APPLE_BUNDLE_ATTRS}
test_attrs = {k: v for (k, v) in kwargs.items() if (k not in _APPLE_BUNDLE_ATTRS) or (k in _ALWAYS_AVAILABLE_ATTRS)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when downstream project point to this commit, probably worth printing out what is dropped before VS after, to see if anything other than features are dropped also

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean adding a print here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but do it temp. during the testing

@luispadron luispadron enabled auto-merge (squash) November 18, 2024 20:41
@luispadron luispadron merged commit 57d46ed into master Nov 18, 2024
23 checks passed
@luispadron luispadron deleted the luis/fix-attr-forwarding-for-test-rules branch November 18, 2024 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants