コード例 #1
0
ファイル: xctestrun.py プロジェクト: srautiai/xctestrunner
    def _GenerateTestRootForLogicTest(self):
        """Generates the test root for Logic test.

    The approach constructs xctestrun.plist from Xcode. Then copies test bundle
    and xctestrun.plist to test root directory.
    """
        dyld_framework_path = os.path.join(
            xcode_info_util.GetSdkPlatformPath(self._sdk),
            'Developer/Library/Frameworks')
        test_envs = {
            'DYLD_FRAMEWORK_PATH': dyld_framework_path,
            'DYLD_LIBRARY_PATH': dyld_framework_path
        }

        # Fixes failures for unit test targets that depend on Swift libraries when running with Xcode 11
        # on pre-iOS 12.2 simulators.
        # Example failure message this resolves: "The bundle couldn’t be loaded because it is damaged
        # or missing necessary resources."
        swift5FallbackLibsDir = xcode_info_util.GetSwift5FallbackLibsDir()
        if swift5FallbackLibsDir:
            test_envs["DYLD_FALLBACK_LIBRARY_PATH"] = swift5FallbackLibsDir

        self._xctestrun_dict = {
            'TestBundlePath': self._test_bundle_dir,
            'TestHostPath': xcode_info_util.GetXctestToolPath(self._sdk),
            'TestingEnvironmentVariables': test_envs,
        }
コード例 #2
0
def RunLogicTestOnSim(sim_id,
                      test_bundle_path,
                      env_vars=None,
                      args=None,
                      tests_to_run=None,
                      os_version=None):
    """Runs logic tests on the simulator. The output prints on system stdout.

  Args:
    sim_id: string, the id of the simulator.
    test_bundle_path: string, the path of the logic test bundle.
    env_vars: dict, the additionl environment variables passing to test's
        process.
    args: array, the additional arguments passing to test's process.
    tests_to_run: array, the format of each item is TestClass[/TestMethod].
        If it is empty, then runs with All methods.
    os_version: string, the OS version of the simulator.

  Returns:
    exit_code: A value of type runner_exit_codes.EXITCODE.

  Raises:
    ios_errors.SimError: The command to launch logic test has error.
  """
    simctl_env_vars = {}
    if env_vars:
        for key in env_vars:
            simctl_env_vars[_SIMCTL_ENV_VAR_PREFIX + key] = env_vars[key]
    simctl_env_vars['NSUnbufferedIO'] = 'YES'
    # When running tests on iOS 12.1 or earlier simulator under Xcode 11 or 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 os_version
            and version_util.GetVersionNumber(os_version) < 1220):
        key = _SIMCTL_ENV_VAR_PREFIX + 'DYLD_FALLBACK_LIBRARY_PATH'
        simctl_env_vars[key] = xcode_info_util.GetSwift5FallbackLibsDir()
    # We need to set the DEVELOPER_DIR to ensure xcrun works correctly
    developer_dir = os.environ.get('DEVELOPER_DIR')
    if developer_dir:
        simctl_env_vars['DEVELOPER_DIR'] = developer_dir

    command = [
        'xcrun', 'simctl', 'spawn', '-s', sim_id,
        xcode_info_util.GetXctestToolPath(ios_constants.SDK.IPHONESIMULATOR)
    ]
    if args:
        command += args
    if not tests_to_run:
        tests_to_run_str = 'All'
    else:
        tests_to_run_str = ','.join(tests_to_run)

    return_code = subprocess.Popen(
        command + ['-XCTest', tests_to_run_str, test_bundle_path],
        env=simctl_env_vars,
        stdout=sys.stdout,
        stderr=subprocess.STDOUT).wait()
    if return_code != 0:
        return runner_exit_codes.EXITCODE.FAILED
    return runner_exit_codes.EXITCODE.SUCCEEDED
コード例 #3
0
def RunLogicTestOnSim(sim_id,
                      test_bundle_path,
                      env_vars=None,
                      args=None,
                      tests_to_run=None):
    """Runs logic tests on the simulator. The output prints on system stdout.

  Args:
    sim_id: string, the id of the simulator.
    test_bundle_path: string, the path of the logic test bundle.
    env_vars: dict, the additionl environment variables passing to test's
        process.
    args: array, the additional arguments passing to test's process.
    tests_to_run: array, the format of each item is TestClass[/TestMethod].
        If it is empty, then runs with All methods.

  Returns:
    exit_code: A value of type runner_exit_codes.EXITCODE.

  Raises:
    ios_errors.SimError: The command to launch logic test has error.
  """
    simctl_env_vars = {}
    if env_vars:
        for key in env_vars:
            simctl_env_vars[_SIMCTL_ENV_VAR_PREFIX + key] = env_vars[key]
    simctl_env_vars['NSUnbufferedIO'] = 'YES'

    # Fixes failures for unit test targets that depend on Swift libraries when running with Xcode 11
    # on pre-iOS 12.2 simulators.
    # Example failure message this resolves: "The bundle couldn’t be loaded because it is damaged
    # or missing necessary resources."
    swift5FallbackLibsDir = xcode_info_util.GetSwift5FallbackLibsDir()
    if swift5FallbackLibsDir:
        simctl_env_vars[_SIMCTL_ENV_VAR_PREFIX +
                        "DYLD_FALLBACK_LIBRARY_PATH"] = swift5FallbackLibsDir

    command = [
        'xcrun', 'simctl', 'spawn', '-s', sim_id,
        xcode_info_util.GetXctestToolPath(ios_constants.SDK.IPHONESIMULATOR)
    ]
    if args:
        command += args
    if not tests_to_run:
        tests_to_run_str = 'All'
    else:
        tests_to_run_str = ','.join(tests_to_run)

    return_code = subprocess.Popen(
        command + ['-XCTest', tests_to_run_str, test_bundle_path],
        env=simctl_env_vars,
        stdout=sys.stdout,
        stderr=subprocess.STDOUT).wait()
    if return_code != 0:
        return runner_exit_codes.EXITCODE.FAILED
    return runner_exit_codes.EXITCODE.SUCCEEDED
コード例 #4
0
def RunLogicTestOnSim(sim_id,
                      test_bundle_path,
                      env_vars=None,
                      args=None,
                      tests_to_run=None):
    """Runs logic tests on the simulator. The output prints on system stdout.

  Args:
    sim_id: string, the id of the simulator.
    test_bundle_path: string, the path of the logic test bundle.
    env_vars: dict, the additionl environment variables passing to test's
        process.
    args: array, the additional arguments passing to test's process.
    tests_to_run: array, the format of each item is TestClass[/TestMethod].
        If it is empty, then runs with All methods.

  Returns:
    exit_code: A value of type runner_exit_codes.EXITCODE.

  Raises:
    ios_errors.SimError: The command to launch logic test has error.
  """
    simctl_env_vars = {}
    if env_vars:
        for key in env_vars:
            simctl_env_vars[_SIMCTL_ENV_VAR_PREFIX + key] = env_vars[key]
    simctl_env_vars['NSUnbufferedIO'] = 'YES'
    command = [
        'xcrun', 'simctl', 'spawn', '-s', sim_id,
        xcode_info_util.GetXctestToolPath(ios_constants.SDK.IPHONESIMULATOR)
    ]
    if args:
        command += args
    if not tests_to_run:
        tests_to_run_str = 'All'
    else:
        tests_to_run_str = ','.join(tests_to_run)

    return_code = subprocess.Popen(
        command + ['-XCTest', tests_to_run_str, test_bundle_path],
        env=simctl_env_vars,
        stdout=sys.stdout,
        stderr=subprocess.STDOUT).wait()
    if return_code != 0:
        return runner_exit_codes.EXITCODE.FAILED
    return runner_exit_codes.EXITCODE.SUCCEEDED
コード例 #5
0
ファイル: xctestrun.py プロジェクト: aihua/xctestrunner
    def _GenerateTestRootForLogicTest(self):
        """Generates the test root for Logic test.

    The approach constructs xctestrun.plist from Xcode. Then copies test bundle
    and xctestrun.plist to test root directory.
    """
        dyld_framework_path = os.path.join(
            xcode_info_util.GetSdkPlatformPath(self._sdk),
            'Developer/Library/Frameworks')
        test_envs = {
            'DYLD_FRAMEWORK_PATH': dyld_framework_path,
            'DYLD_LIBRARY_PATH': dyld_framework_path
        }
        self._xctestrun_dict = {
            'TestBundlePath': self._test_bundle_dir,
            'TestHostPath': xcode_info_util.GetXctestToolPath(self._sdk),
            'TestingEnvironmentVariables': test_envs,
        }