Skip to content

Commit

Permalink
Merge pull request #22 from keith/ks/add-xcresult-bundle-collection
Browse files Browse the repository at this point in the history
Add xcresult bundle collection
  • Loading branch information
albertdai committed Aug 4, 2020
2 parents 75cb0e3 + cefec9d commit 0809aad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions xctestrunner/shared/ios_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def enum(**enums):
In xctest, the functionality is the same as "args".
In xcuitest, the process of app under test is different with the
process of test.
keep_xcresult_data: bool
Whether or not to keep the xcresult bundle produced by the test run
in the output_dir.
tests_to_run : array
The specific test classes or test methods to run. Each item should be
string and its format is Test-Class-Name[/Test-Method-Name]. It is supported
Expand Down
15 changes: 8 additions & 7 deletions xctestrunner/test_runner/xctest_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"""The module to run XCTEST based tests."""

import glob
import logging
import os
import shutil
Expand Down Expand Up @@ -60,6 +59,7 @@ def __init__(self, sdk, device_arch, work_dir=None, output_dir=None):
self._destination_timeout_sec = None
self._xctestrun_obj = None
self._prepared = False
self._keep_xcresult_data = True
# The following fields are only for Logic Test.
self._logic_test_bundle = None
self._logic_test_env_vars = None
Expand Down Expand Up @@ -160,6 +160,7 @@ def SetLaunchOptions(self, launch_options):
'XctestSession.Prepare first.')
if not launch_options:
return
self._keep_xcresult_data = launch_options.get('keep_xcresult_data', True)
self._startup_timeout_sec = launch_options.get('startup_timeout_sec')
self._destination_timeout_sec = launch_options.get(
'destination_timeout_sec')
Expand Down Expand Up @@ -205,18 +206,18 @@ def RunTest(self, device_id, os_version=None):
'XctestSession.Prepare first.')

if self._xctestrun_obj:
result_bundle_path = os.path.join(self._output_dir, 'test.xcresult')
exit_code = self._xctestrun_obj.Run(device_id, self._sdk,
self._output_dir,
self._startup_timeout_sec,
self._destination_timeout_sec,
os_version=os_version)
os_version=os_version,
result_bundle_path=result_bundle_path)
# The xcresult only contains raw data in Xcode 11 or later.
if xcode_info_util.GetXcodeVersionNumber() >= 1100:
test_log_dir = '%s/Logs/Test' % self._output_dir
xcresults = glob.glob('%s/*.xcresult' % test_log_dir)
for xcresult in xcresults:
xcresult_util.ExposeDiagnosticsRef(xcresult, test_log_dir)
shutil.rmtree(xcresult)
xcresult_util.ExposeDiagnosticsRef(result_bundle_path, test_log_dir)
if not self._keep_xcresult_data:
shutil.rmtree(result_bundle_path)
return exit_code
elif self._logic_test_bundle:
return logic_test_util.RunLogicTestOnSim(
Expand Down
12 changes: 10 additions & 2 deletions xctestrunner/test_runner/xctestrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def SetSkipTests(self, skip_tests):
self.SetXctestrunField('SkipTestIdentifiers', skip_tests)

def Run(self, device_id, sdk, derived_data_dir, startup_timeout_sec,
destination_timeout_sec=None, os_version=None):
destination_timeout_sec=None, os_version=None,
result_bundle_path=None):
"""Runs the test with generated xctestrun file in the specific device.
Args:
Expand All @@ -153,6 +154,7 @@ def Run(self, device_id, sdk, derived_data_dir, startup_timeout_sec,
destination_timeout_sec: Wait for the given seconds while searching for
the destination device.
os_version: os version of the device.
result_bundle_path: path to output a xcresult bundle to
Returns:
A value of type runner_exit_codes.EXITCODE.
Expand All @@ -161,7 +163,8 @@ def Run(self, device_id, sdk, derived_data_dir, startup_timeout_sec,
# later, it is required to add swift5 fallback libraries to environment
# variable.
# See https://github.com/bazelbuild/rules_apple/issues/684 for context.
if (xcode_info_util.GetXcodeVersionNumber() >= 1100 and
xcode_version = xcode_info_util.GetXcodeVersionNumber()
if (xcode_version >= 1100 and
sdk == ios_constants.SDK.IPHONESIMULATOR and os_version and
version_util.GetVersionNumber(os_version) < 1220):
new_env_var = {
Expand All @@ -174,6 +177,11 @@ def Run(self, device_id, sdk, derived_data_dir, startup_timeout_sec,
'-xctestrun', self._xctestrun_file_path,
'-destination', 'id=%s' % device_id,
'-derivedDataPath', derived_data_dir]

if xcode_version >= 1100 and result_bundle_path:
shutil.rmtree(result_bundle_path, ignore_errors=True)
command.extend(['-resultBundlePath', result_bundle_path])

if destination_timeout_sec:
command.extend(['-destination-timeout', str(destination_timeout_sec)])
exit_code, _ = xcodebuild_test_executor.XcodebuildTestExecutor(
Expand Down

0 comments on commit 0809aad

Please sign in to comment.