-
Notifications
You must be signed in to change notification settings - Fork 95
Pass product module name into test_rule #627
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Derek Ostrander <derko@squareup.com> | ||
| Date: Fri, 9 Dec 2022 13:55:16 -0500 | ||
| Subject: Add product module name as an optional arg for the test rule | ||
|
|
||
| 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. | ||
|
|
||
| diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl | ||
| index 33d4312f..b196a577 100644 | ||
| --- a/apple/internal/rule_factory.bzl | ||
| +++ b/apple/internal/rule_factory.bzl | ||
| @@ -205,6 +205,12 @@ AppleTestRunnerInfo provider. | ||
| "test_filter": attr.string( | ||
| doc = """ | ||
| Test filter string that will be passed into the test runner to select which tests will run. | ||
| +""", | ||
| + default = "", | ||
| + ), | ||
| + "module_name": attr.string( | ||
| + doc = """ | ||
| +Module name of the underlying test to be run. | ||
| """, | ||
| default = "", | ||
| ), | ||
| diff --git a/apple/internal/testing/apple_test_rule_support.bzl b/apple/internal/testing/apple_test_rule_support.bzl | ||
| index 8392862a..49ff1f65 100644 | ||
| --- a/apple/internal/testing/apple_test_rule_support.bzl | ||
| +++ b/apple/internal/testing/apple_test_rule_support.bzl | ||
| @@ -102,7 +102,7 @@ This aspect propagates a `CoverageFilesInfo` provider. | ||
| implementation = _coverage_files_aspect_impl, | ||
| ) | ||
|
|
||
| -def _get_template_substitutions(test_type, test_bundle, test_environment, test_host = None, test_filter = None): | ||
| +def _get_template_substitutions(test_type, test_bundle, test_environment, test_host = None, test_filter = None, product_module_name = None): | ||
| """Dictionary with the substitutions to be applied to the template script.""" | ||
| subs = {} | ||
|
|
||
| @@ -114,6 +114,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 "" | ||
|
|
||
| return {"%(" + k + ")s": subs[k] for k in subs} | ||
|
|
||
| @@ -176,6 +177,7 @@ def _apple_test_rule_impl(ctx, test_type): | ||
| test_environment, | ||
| test_host = test_host_archive, | ||
| test_filter = ctx.attr.test_filter, | ||
| + product_module_name = ctx.attr.module_name, | ||
| ), | ||
| is_executable = True, | ||
| ) | ||
| diff --git a/apple/testing/default_runner/ios_test_runner.template.sh b/apple/testing/default_runner/ios_test_runner.template.sh | ||
| index 0804007c..0fbf190f 100644 | ||
| --- a/apple/testing/default_runner/ios_test_runner.template.sh | ||
| +++ b/apple/testing/default_runner/ios_test_runner.template.sh | ||
| @@ -52,6 +52,11 @@ TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/test_runner_work_dir.XXXXXX")" | ||
| trap 'rm -rf "${TMP_DIR}"' ERR EXIT | ||
| runner_flags+=("--work_dir=${TMP_DIR}") | ||
|
|
||
| +PRODUCT_MODULE_NAME="%(product_module_name)s" | ||
| +if [[ -n "$PRODUCT_MODULE_NAME" ]]; then | ||
| + runner_flags+=("--product_module_name=${PRODUCT_MODULE_NAME}") | ||
| +fi | ||
| + | ||
| TEST_BUNDLE_PATH="%(test_bundle_path)s" | ||
|
|
||
| if [[ "$TEST_BUNDLE_PATH" == *.xctest ]]; then | ||
| diff --git a/test/ios_test_runner_unit_test.sh b/test/ios_test_runner_unit_test.sh | ||
| index 64002d38..55fb26ee 100755 | ||
| --- a/test/ios_test_runner_unit_test.sh | ||
| +++ b/test/ios_test_runner_unit_test.sh | ||
| @@ -201,6 +201,7 @@ objc_library( | ||
|
|
||
| ios_unit_test( | ||
| name = "PassingUnitTest", | ||
| + module_name = "pass_unit_test_lib", | ||
| infoplists = ["PassUnitTest-Info.plist"], | ||
| deps = [":pass_unit_test_lib"], | ||
| minimum_os_version = "9.0", | ||
| -- | ||
| 2.36.1 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Derek Ostrander <derko@squareup.com> | ||
| Date: Fri, 9 Dec 2022 13:34:25 -0500 | ||
| Subject: =?UTF-8?q?Add=20optional=20parameter=20of=20product=5Fmodule=5Fna?= | ||
| =?UTF-8?q?me=0AThis=20will=20be=20forwarded=20into=20the=20xctestrun=20fi?= | ||
| =?UTF-8?q?le=20in=20the=20test=20name=20doesn't=20accurately=20reflect=20?= | ||
| =?UTF-8?q?the=20module=20underneath?= | ||
|
|
||
|
|
||
| diff --git a/test_runner/ios_test_runner.py b/test_runner/ios_test_runner.py | ||
| index c85800d..b4b67a3 100644 | ||
| --- a/test_runner/ios_test_runner.py | ||
| +++ b/test_runner/ios_test_runner.py | ||
| @@ -117,7 +117,8 @@ def _AddPrepareSubParser(subparsers): | ||
| test_bundle=args.test_bundle_path, | ||
| xctestrun_file_path=args.xctestrun, | ||
| test_type=args.test_type, | ||
| - signing_options=_GetJson(args.signing_options_json_path)) | ||
| + signing_options=_GetJson(args.signing_options_json_path), | ||
| + product_module_name=args.product_module_name) | ||
| session.SetLaunchOptions(_GetJson(args.launch_options_json_path)) | ||
|
|
||
| test_parser = subparsers.add_parser( | ||
| @@ -153,7 +154,8 @@ def _AddTestSubParser(subparsers): | ||
| test_bundle=args.test_bundle_path, | ||
| xctestrun_file_path=args.xctestrun, | ||
| test_type=args.test_type, | ||
| - signing_options=_GetJson(args.signing_options_json_path)) | ||
| + signing_options=_GetJson(args.signing_options_json_path), | ||
| + product_module_name=args.product_module_name) | ||
| session.SetLaunchOptions(_GetJson(args.launch_options_json_path)) | ||
| return session.RunTest(args.id) | ||
|
|
||
| @@ -172,6 +174,11 @@ def _AddTestSubParser(subparsers): | ||
| help='The platform of the device. The value can be ios_device or ' | ||
| 'ios_simulator.' | ||
| ) | ||
| + optional_arguments.add_argument( | ||
| + '--product_module_name', | ||
| + help='The product module name that will be set in the xctestrun file.' | ||
| + ) | ||
| + | ||
| test_parser.set_defaults(func=_Test) | ||
|
|
||
|
|
||
| @@ -197,7 +204,8 @@ def _AddSimulatorTestSubParser(subparsers): | ||
| test_bundle=args.test_bundle_path, | ||
| xctestrun_file_path=args.xctestrun, | ||
| test_type=args.test_type, | ||
| - signing_options=_GetJson(args.signing_options_json_path)) | ||
| + signing_options=_GetJson(args.signing_options_json_path), | ||
| + product_module_name=args.product_module_name) | ||
| session.SetLaunchOptions(_GetJson(args.launch_options_json_path)) | ||
| if not hostless: | ||
| try: | ||
| diff --git a/test_runner/xctest_session.py b/test_runner/xctest_session.py | ||
| index 1e879db..1e08e70 100644 | ||
| --- a/test_runner/xctest_session.py | ||
| +++ b/test_runner/xctest_session.py | ||
| @@ -78,7 +78,8 @@ class XctestSession(object): | ||
| # TODO(albertdai): Support bundle id as the value of app_under_test and | ||
| # test_bundle. | ||
| def Prepare(self, app_under_test=None, test_bundle=None, | ||
| - xctestrun_file_path=None, test_type=None, signing_options=None): | ||
| + xctestrun_file_path=None, test_type=None, | ||
| + signing_options=None, product_module_name=None): | ||
| """Prepares the test session. | ||
|
|
||
| If xctestrun_file is not provided, will use app under test and test bundle | ||
| @@ -94,6 +95,8 @@ class XctestSession(object): | ||
| test_type: ios_constants.TestType. The type of test bundle. | ||
| signing_options: dict, the signing app options. See | ||
| ios_constants.SIGNING_OPTIONS_JSON_HELP for details. | ||
| + product_module_name: string, the name of the module that is being tested. | ||
| + This will be forwarded into the xctestrun file. | ||
|
|
||
| Raises: | ||
| ios_errors.IllegalArgumentError: | ||
| @@ -141,7 +144,7 @@ class XctestSession(object): | ||
| if test_type != ios_constants.TestType.LOGIC_TEST: | ||
| xctestrun_factory = xctestrun.XctestRunFactory( | ||
| app_under_test_dir, test_bundle_dir, self._sdk, self._device_arch, | ||
| - test_type, signing_options, self._work_dir) | ||
| + test_type, signing_options, self._work_dir, product_module_name) | ||
| self._xctestrun_obj = xctestrun_factory.GenerateXctestrun() | ||
| else: | ||
| self._logic_test_bundle = test_bundle_dir | ||
| diff --git a/test_runner/xctestrun.py b/test_runner/xctestrun.py | ||
| index 4390489..f1c2fe1 100644 | ||
| --- a/test_runner/xctestrun.py | ||
| +++ b/test_runner/xctestrun.py | ||
| @@ -275,7 +275,8 @@ class XctestRunFactory(object): | ||
| sdk=ios_constants.SDK.IPHONESIMULATOR, | ||
| device_arch=ios_constants.ARCH.X86_64, | ||
| test_type=ios_constants.TestType.XCUITEST, | ||
| - signing_options=None, work_dir=None): | ||
| + signing_options=None, work_dir=None, | ||
| + product_module_name=None): | ||
| """Initializes the XctestRun object. | ||
|
|
||
| If arg work_dir is provided, the original app under test file and test | ||
| @@ -292,6 +293,7 @@ class XctestRunFactory(object): | ||
| signing_options: dict, the signing app options. See | ||
| ios_constants.SIGNING_OPTIONS_JSON_HELP for details. | ||
| work_dir: string, work directory which contains run files. | ||
| + product_module_name: string, forwarded into the xctestrun. | ||
|
|
||
| Raises: | ||
| IllegalArgumentError: when the sdk or test type is not supported. | ||
| @@ -302,6 +304,7 @@ class XctestRunFactory(object): | ||
| self._sdk = sdk | ||
| self._device_arch = device_arch | ||
| self._test_type = test_type | ||
| + self._product_module_name = product_module_name | ||
| if self._sdk == ios_constants.SDK.IPHONEOS: | ||
| self._on_device = True | ||
| self._signing_options = signing_options | ||
| @@ -499,7 +502,7 @@ class XctestRunFactory(object): | ||
| 'DYLD_LIBRARY_PATH': '__TESTROOT__:%s/usr/lib' % developer_path | ||
| } | ||
| self._xctestrun_dict = { | ||
| - 'ProductModuleName': self._test_name.replace("-", "_"), | ||
| + 'ProductModuleName': self._product_module_name or self._test_name.replace("-", "_"), | ||
| 'IsUITestBundle': True, | ||
| 'SystemAttachmentLifetime': 'keepNever', | ||
| 'TestBundlePath': self._test_bundle_dir, | ||
| @@ -666,7 +669,7 @@ class XctestRunFactory(object): | ||
| 'DYLD_LIBRARY_PATH': '__TESTROOT__:%s/usr/lib:' % developer_path | ||
| } | ||
| self._xctestrun_dict = { | ||
| - 'ProductModuleName': self._test_name.replace("-", "_"), | ||
| + 'ProductModuleName': self._product_module_name or self._test_name.replace("-", "_"), | ||
| 'TestHostPath': self._app_under_test_dir, | ||
| 'TestBundlePath': self._test_bundle_dir, | ||
| 'IsAppHostedTestBundle': True, | ||
| @@ -687,7 +690,7 @@ class XctestRunFactory(object): | ||
| 'DYLD_LIBRARY_PATH': dyld_framework_path | ||
| } | ||
| self._xctestrun_dict = { | ||
| - 'ProductModuleName': self._test_name.replace("-", "_"), | ||
| + 'ProductModuleName': self._product_module_name or self._test_name.replace("-", "_"), | ||
| 'TestBundlePath': self._test_bundle_dir, | ||
| 'TestHostPath': xcode_info_util.GetXctestToolPath(self._sdk), | ||
| 'TestingEnvironmentVariables': test_envs, | ||
| -- | ||
| 2.36.1 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will break other people that have a different version of rules_apple ( similar of @mattrobmattrob's comment )