<commit_before># swift/test/lit.cfg - Configuration for the 'lit' test runner -*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# -----------------------------------------------------------------------------
#
# This is a configuration file for the 'lit' test runner.
#
# Refer to docs/Testing.rst for documentation.
#
# Update docs/Testing.rst when changing this file.
#
# -----------------------------------------------------------------------------

import os
import platform
import re
import subprocess
import sys
import tempfile
import socket
import glob

import lit
import lit.formats
import lit.util

#
# Helper functions.
#

def darwin_get_sdk_version(sdk_path):
    system_version_plist_path = os.path.join(
        sdk_path, "System", "Library", "CoreServices", "SystemVersion.plist")
    name = subprocess.check_output(
        [ "defaults", "read", system_version_plist_path,
          "ProductName" ]).rstrip()
    vers = subprocess.check_output(
        [ "defaults", "read", system_version_plist_path,
          "ProductVersion" ]).rstrip()
    build = subprocess.check_output(
        [ "defaults", "read", system_version_plist_path,
          "ProductBuildVersion" ]).rstrip()
    return (name, vers, build)


def darwin_sdk_build_version_split(version):
    m = re.search("([0-9]+)([A-Z])([0-9]+)", version)
    return (int(m.group(1)), m.group(2), int(m.group(3)))


def darwin_sdk_build_version_cmp(lhs, rhs):
    # The `_cmp` function is provided to port the Python 2 global `cmp`
    # function forward to Python 3. The function implementation is taken
    # directly from the recommendation that announced its removal.
    # See: https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
    def _cmp(a, b):
      return (a > b) - (a < b)
    return _cmp(
        darwin_sdk_build_version_split(lhs),
        darwin_sdk_build_version_split(rhs))


# Run sw_vers on the target to be tested and return the results.
def darwin_get_sw_vers(commandPrefix=[]):
    name = lit.util.executeCommand(
        commandPrefix + ['/usr/bin/sw_vers', '-productName'])[0].rstrip()
    vers = lit.util.executeCommand(
        commandPrefix + ['/usr/bin/sw_vers', '-productVersion'])[0].rstrip()
    build = lit.util.executeCommand(
        commandPrefix + ['/usr/bin/sw_vers', '-buildVersion'])[0].rstrip()
    return (name, vers, build)


# Returns the "prefix" command that should be prepended to the command line to
# run an executable compiled for iOS or AppleTV simulator.
def get_simulator_command(run_os, sdk_path):
    (name, vers, build) = darwin_get_sdk_version(sdk_path)
    if run_os == 'ios':
        # There are two binaries for the iOS simulator: 'sim' and 'simctl'.
        # 'sim' is only supported for iOS <= 8.1 and early versions of 8.2.
        # 'simctl' is supported for iOS >= 8.2.
        # 'simctl' used to have a bug where it failed to propagate the exit
        # code of the child process.  This was fixed only in the middle of 8.2
        # development cycle.
        if ((darwin_sdk_build_version_cmp(build, "12E999") <= 0) or
            (darwin_sdk_build_version_cmp("12F1", build) <= 0 and
             darwin_sdk_build_version_cmp(build, "12F12") <= 0) or
            (darwin_sdk_build_version_cmp("12H1", build) <= 0 and
             darwin_sdk_build_version_cmp(build, "12H11") <= 0)):
            return "sim"
        else:
            return "simctl spawn 'iPhone 6'"
    elif run_os == 'tvos':
        return "simctl spawn 'Apple TV 1080p'"
    elif run_os == 'watchos':
        return "simctl spawn 'Apple Watch - 42mm'"
    else:
        lit_config.fatal("Unknown simulator OS %r" % run_os)

assert darwin_sdk_build_version_cmp("11A1", "12A1") < 0
assert darwin_sdk_build_version_cmp("12A1", "11A1") > 0

assert darwin_sdk_build_version_cmp("11A1", "11B1") < 0
assert darwin_sdk_build_version_cmp("11B1", "11A1") > 0

assert darwin_sdk_build_version_cmp("11A22", "11A100") < 0
assert darwin_sdk_build_version_cmp("11A100", "11A22") > 0

###

# Check that the object root is known.
if config.test_exec_root is None:
    # Otherwise, we haven't loaded the site specific configuration (the user is
    # probably trying to run on a test file directly, and either the site
    # configuration hasn't been created by the build system, or we are in an
    # out-of-tree build situation).

    # Check for 'swift_site_config' user parameter, and use that if available.
    site_cfg = lit_config.params.get('swift_site_config', None)
    if site_cfg and os.path.exists(site_cfg):
        lit_config.load_config(config, site_cfg)
        raise SystemExit

    lit_config.fatal("lit must be pointed at a build folder")

###

class SwiftTest(lit.formats.ShTest):
    def __init__(self, coverage_mode=None, execute_external=True):
        lit.formats.ShTest.__init__(self, execute_external=execute_external)
        if coverage_mode == "FALSE":
            self.coverage_mode = None
        else:
            self.coverage_mode = coverage_mode

    def profdir_for_test(self, test):
        _, tmp_base = lit.TestRunner.getTempPaths(test)
        return tmp_base + ".profdir"

    def before_test(self, test, litConfig):
        if self.coverage_mode:
            profdir = self.profdir_for_test(test)
            if not os.path.exists(profdir):
                os.makedirs(profdir)

            test.config.environment["LLVM_PROFILE_FILE"] = \
                os.path.join(profdir, "swift-%p.profraw")

    def after_test(self, test, litConfig, result):
        if self.coverage_mode == "MERGED":
            profdir = self.profdir_for_test(test)<commit_msg>[coverage] Converted to explicit super in lit.cfg<commit_after># swift/test/lit.cfg - Configuration for the 'lit' test runner -*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# -----------------------------------------------------------------------------
#
# This is a configuration file for the 'lit' test runner.
#
# Refer to docs/Testing.rst for documentation.
#
# Update docs/Testing.rst when changing this file.
#
# -----------------------------------------------------------------------------

import os
import platform
import re
import subprocess
import sys
import tempfile
import socket
import glob

import lit
import lit.formats
import lit.util

#
# Helper functions.
#

def darwin_get_sdk_version(sdk_path):
    system_version_plist_path = os.path.join(
        sdk_path, "System", "Library", "CoreServices", "SystemVersion.plist")
    name = subprocess.check_output(
        [ "defaults", "read", system_version_plist_path,
          "ProductName" ]).rstrip()
    vers = subprocess.check_output(
        [ "defaults", "read", system_version_plist_path,
          "ProductVersion" ]).rstrip()
    build = subprocess.check_output(
        [ "defaults", "read", system_version_plist_path,
          "ProductBuildVersion" ]).rstrip()
    return (name, vers, build)


def darwin_sdk_build_version_split(version):
    m = re.search("([0-9]+)([A-Z])([0-9]+)", version)
    return (int(m.group(1)), m.group(2), int(m.group(3)))


def darwin_sdk_build_version_cmp(lhs, rhs):
    # The `_cmp` function is provided to port the Python 2 global `cmp`
    # function forward to Python 3. The function implementation is taken
    # directly from the recommendation that announced its removal.
    # See: https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
    def _cmp(a, b):
      return (a > b) - (a < b)
    return _cmp(
        darwin_sdk_build_version_split(lhs),
        darwin_sdk_build_version_split(rhs))


# Run sw_vers on the target to be tested and return the results.
def darwin_get_sw_vers(commandPrefix=[]):
    name = lit.util.executeCommand(
        commandPrefix + ['/usr/bin/sw_vers', '-productName'])[0].rstrip()
    vers = lit.util.executeCommand(
        commandPrefix + ['/usr/bin/sw_vers', '-productVersion'])[0].rstrip()
    build = lit.util.executeCommand(
        commandPrefix + ['/usr/bin/sw_vers', '-buildVersion'])[0].rstrip()
    return (name, vers, build)


# Returns the "prefix" command that should be prepended to the command line to
# run an executable compiled for iOS or AppleTV simulator.
def get_simulator_command(run_os, sdk_path):
    (name, vers, build) = darwin_get_sdk_version(sdk_path)
    if run_os == 'ios':
        # There are two binaries for the iOS simulator: 'sim' and 'simctl'.
        # 'sim' is only supported for iOS <= 8.1 and early versions of 8.2.
        # 'simctl' is supported for iOS >= 8.2.
        # 'simctl' used to have a bug where it failed to propagate the exit
        # code of the child process.  This was fixed only in the middle of 8.2
        # development cycle.
        if ((darwin_sdk_build_version_cmp(build, "12E999") <= 0) or
            (darwin_sdk_build_version_cmp("12F1", build) <= 0 and
             darwin_sdk_build_version_cmp(build, "12F12") <= 0) or
            (darwin_sdk_build_version_cmp("12H1", build) <= 0 and
             darwin_sdk_build_version_cmp(build, "12H11") <= 0)):
            return "sim"
        else:
            return "simctl spawn 'iPhone 6'"
    elif run_os == 'tvos':
        return "simctl spawn 'Apple TV 1080p'"
    elif run_os == 'watchos':
        return "simctl spawn 'Apple Watch - 42mm'"
    else:
        lit_config.fatal("Unknown simulator OS %r" % run_os)

assert darwin_sdk_build_version_cmp("11A1", "12A1") < 0
assert darwin_sdk_build_version_cmp("12A1", "11A1") > 0

assert darwin_sdk_build_version_cmp("11A1", "11B1") < 0
assert darwin_sdk_build_version_cmp("11B1", "11A1") > 0

assert darwin_sdk_build_version_cmp("11A22", "11A100") < 0
assert darwin_sdk_build_version_cmp("11A100", "11A22") > 0

###

# Check that the object root is known.
if config.test_exec_root is None:
    # Otherwise, we haven't loaded the site specific configuration (the user is
    # probably trying to run on a test file directly, and either the site
    # configuration hasn't been created by the build system, or we are in an
    # out-of-tree build situation).

    # Check for 'swift_site_config' user parameter, and use that if available.
    site_cfg = lit_config.params.get('swift_site_config', None)
    if site_cfg and os.path.exists(site_cfg):
        lit_config.load_config(config, site_cfg)
        raise SystemExit

    lit_config.fatal("lit must be pointed at a build folder")

###

class SwiftTest(lit.formats.ShTest, object):
    def __init__(self, coverage_mode=None, execute_external=True):
        super(SwiftTest, self).__init__(execute_external=execute_external)
        if coverage_mode == "FALSE":
            self.coverage_mode = None
        else:
            self.coverage_mode = coverage_mode

    def profdir_for_test(self, test):
        _, tmp_base = lit.TestRunner.getTempPaths(test)
        return tmp_base + ".profdir"

    def before_test(self, test, litConfig):
        if self.coverage_mode:
            profdir = self.profdir_for_test(test)
            if not os.path.exists(profdir):
                os.makedirs(profdir)

            test.config.environment["LLVM_PROFILE_FILE"] = \
                os.path.join(profdir, "swift-%p.profraw")

    def after_test(self, test, litConfig, result):
        if self.coverage_mode == "MERGED":
            profdir = self.profdir_for_test(test)
{'fraction_non_alphanumeric': 0.13376010781671158, 'fraction_numerical': 0.019036388140161724, 'mean_word_length': 2.9327591917853595, 'pattern_counts': {'":': 4, '<': 23, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6761307', 'n_tokens_mistral': 3838, 'n_tokens_neox': 3630, 'n_words': 1040}