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

Add module name to the testrunner #1785

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dostrander
Copy link
Contributor

@dostrander dostrander commented Dec 9, 2022

If there are modules under the tests that are named differently then the target itself it will cause issues with the xctestrun file. Specifically using Swift the test_filters do not work unless the module names line up with the test target name. Guessing because Swift's full class names are MODULE.CLASS so they do the magic under the hood.

We'll likely need to wait until google/xctestrunner#50 is merged

@keith
Copy link
Member

keith commented Dec 9, 2022

can you throw a value for this attr into one of the test targets so that it actually gets caught by CI? also note that this has to hit master before this branch, we won't ever merge this branch back into master

@dostrander
Copy link
Contributor Author

can you throw a value for this attr into one of the test targets so that it actually gets caught by CI? also note that this has to hit master before this branch, we won't ever merge this branch back into master

Will do.

Also open to possibly changing this name to module_name or something. I keep going back and forth in my head

@dostrander dostrander force-pushed the dostrander/add-product-module-name branch 2 times, most recently from 38b3efa to abc1a78 Compare December 12, 2022 15:14
@dostrander dostrander changed the base branch from bazel/5.x to master December 12, 2022 15:15
@@ -115,6 +115,7 @@ def _get_template_substitutions(test_type, test_bundle, test_environment, test_h
subs["test_type"] = test_type.upper()
subs["test_env"] = ",".join([k + "=" + v for (k, v) in test_environment.items()])
subs["test_filter"] = test_filter or ""
subs["product_module_name"] = product_module_name or ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't the test_filter address each test by the PRODUCT_MODULE_NAME? Perhaps can you parse this from test_filter if it it exists. The thing I liked about this is being able to filter different module names. Say you've got a number of modules in the test:

bazel test :MyTest --test_filters MyFirst.swiftmodule:foo
bazel test :MyTest --test_filters MySecond.swiftmodule:bar

Then - inside of xctestrunner - you'd simply set PRODUCT_MODULE in the xctestrun based on the filter - and be sure to get the right one. Probably validate they set that..

The downside of adding this at the rule level is you can't filter dynamically like that.

PS : I wonder if this is a regression - or perhaps test_filter only ever workd for objc!

Copy link
Contributor

Choose a reason for hiding this comment

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

Also do you imagine that we'd ever want to feed .xctestrun ( or partials ) into this rule? That might be another thing to contend with - similar our plist composition stuff in rules_ios you might be able to pass overrides.

I would still question if you can leverage the build graph too: assuming that you pack ( filterable ) tests into the first .swiftmodule file - you can set the PRODUCT_MODULE_NAME based on the first direct SwiftInfo

Obviously these are 2 different solutions. I liked the dep graph way - and might be a nice default - it has some inflexibility but it's probably easier for 99% of tests out there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey PTAL again i've pivoted to using the swiftmodule's you were talking about here

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah cool glad it works - this makes Bazel easier to use in general IMO

@dostrander dostrander force-pushed the dostrander/add-product-module-name branch from abc1a78 to a00c1af Compare December 15, 2022 20:02
@@ -209,6 +209,7 @@ objc_library(

ios_unit_test(
name = "PassingUnitTest",
module_name = "pass_unit_test_lib",
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine we should remove this attribute now

@@ -135,6 +141,11 @@ def _apple_test_rule_impl(ctx, test_type):
test_bundle_target = ctx.attr.deps[0]

test_bundle = test_bundle_target[AppleTestInfo].test_bundle
swift_module_list = test_bundle_target[AppleTestInfo].swift_modules.to_list()

test_swift_module_file = swift_module_list[len(swift_module_list) - 1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this do a lenght check - if there is less than 1 swiftmodule it's out of bounds?

@@ -115,6 +115,7 @@ def _get_template_substitutions(test_type, test_bundle, test_environment, test_h
subs["test_type"] = test_type.upper()
subs["test_env"] = ",".join([k + "=" + v for (k, v) in test_environment.items()])
subs["test_filter"] = test_filter or ""
subs["product_module_name"] = product_module_name or ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah cool glad it works - this makes Bazel easier to use in general IMO

Unless the xctestrun specifies a product module name some feature such as filtering tests will not work in Swift files.
@dostrander dostrander force-pushed the dostrander/add-product-module-name branch from a00c1af to c1e7efa Compare December 15, 2022 20:43
@dostrander dostrander changed the title Add product module name as an optional arg for the test rule Add module name to the testrunner Dec 16, 2022
jerrymarino pushed a commit to bazel-ios/rules_apple that referenced this pull request Jan 26, 2023
* Grab module name from swiftmodule files (#1)
bazelbuild#1785

* Use bazel-ios/xctestrunner (#2)
jerrymarino pushed a commit to bazel-ios/rules_apple that referenced this pull request Feb 7, 2023
* Grab module name from swiftmodule files (#1)
bazelbuild#1785

* Use bazel-ios/xctestrunner (#2)
@jerrymarino
Copy link
Contributor

@dostrander bump - I think there's a few test failures that would prevent us from landing this re: bazel-ios/rules_ios#663

@dostrander
Copy link
Contributor Author

@dostrander bump - I think there's a few test failures that would prevent us from landing this re: bazel-ios/rules_ios#663

This can't realyl be merged until google/xctestrunner#50 is merged unless we do a patch

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.

3 participants