Repository: dotnet/runtime
File: src/tests/run.py (Python)

Code before:
        # It is possible there has already been a match therefore we need to remove the punctuation again.
        basename_to_match = re.sub("[%s]" % string.punctuation, "_", os.path.basename(test_path))
        if basename_to_match in dir_contents:
            test_path = os.path.join(os.path.dirname(test_path), dir_contents[basename_to_match])

        size_of_largest_name_file = len(max(dir_contents, key=len))
        return test_path, size_of_largest_name_file

    def dir_has_nested_substrings(test_path, test_item):
        """ Return True if a directory has multiple paths where one path is a substring of another
        """
        dir_contents = get_dir_contents(test_path)
        test_item = re.sub("[%s]" % string.punctuation, "_", test_item)

        count = 0
        for item in dir_contents:
            if test_item in item:
                count += 1

        return count > 1

    ### Start find_test_from_name code

    # For some reason, out-of-process tests on Linux are named with ".cmd" wrapper script names,
    # not .sh extension names. Fix that before trying to find the test filename.
    if sys.platform != "win32":
        test_name_wo_extension, test_name_extension = os.path.splitext(test_name)
        if test_name_extension == ".cmd":
            test_name = test_name_wo_extension + ".sh"

    # REVIEW: It looks like this code might be mostly relevant to the pre-merged-test case.

    # Try a simple check first, before trying to construct a path from what is expected to be a pathname
    # with path separators ("\" "/") replaced by underscores ("_").

    test_path = os.path.abspath(os.path.join(test_location, test_name))
    if os.path.isfile(test_path):
        # Simple; we're done
        return test_path

    location = test_name

    # Find the test by searching down the directory list.
    starting_path = test_location
    loc_split = location.split("_")
    append = False
    for index, item in enumerate(loc_split):
        if not append:
            test_path = os.path.join(starting_path, item)
            # Ensure the joined path is correct. Avoid forming /Vector256/1/ for Vector256_1
            # where both Vector256 and Vector256_1 are valid dirs.

Review comment (suggestion):
I understand this is for consistency, but these two options (before and after) should be equivalent.

Code after:
        # It is possible there has already been a match therefore we need to remove the punctuation again.
        basename_to_match = re.sub("[%s]" % string.punctuation, "_", os.path.basename(test_path))
        if basename_to_match in dir_contents:
            test_path = os.path.join(os.path.dirname(test_path), dir_contents[basename_to_match])

        size_of_largest_name_file = len(max(dir_contents, key=len))
        return test_path, size_of_largest_name_file

    def dir_has_nested_substrings(test_path, test_item):
        """ Return True if a directory has multiple paths where one path is a substring of another
        """
        dir_contents = get_dir_contents(test_path)
        test_item = re.sub("[%s]" % string.punctuation, "_", test_item)

        count = 0
        for item in dir_contents:
            if test_item in item:
                count += 1

        return count > 1

    ### Start find_test_from_name code

    # For some reason, out-of-process tests on Linux are named with ".cmd" wrapper script names,
    # not .sh extension names. Fix that before trying to find the test filename.
    if host_os != "windows":
        test_name_wo_extension, test_name_extension = os.path.splitext(test_name)
        if test_name_extension == ".cmd":
            test_name = test_name_wo_extension + ".sh"

    # REVIEW: It looks like this code might be mostly relevant to the pre-merged-test case.

    # Try a simple check first, before trying to construct a path from what is expected to be a pathname
    # with path separators ("\" "/") replaced by underscores ("_").

    test_path = os.path.abspath(os.path.join(test_location, test_name))
    if os.path.isfile(test_path):
        # Simple; we're done
        return test_path

    location = test_name

    # Find the test by searching down the directory list.
    starting_path = test_location
    loc_split = location.split("_")
    append = False
    for index, item in enumerate(loc_split):
        if not append:
            test_path = os.path.join(starting_path, item)
            # Ensure the joined path is correct. Avoid forming /Vector256/1/ for Vector256_1
            # where both Vector256 and Vector256_1 are valid dirs.