Changeset 90941 in webkit


Ignore:
Timestamp:
Jul 13, 2011 12:36:47 PM (13 years ago)
Author:
Dimitri Glazkov
Message:

Consolidate expectations parsing code.
https://bugs.webkit.org/show_bug.cgi?id=64460

Reviewed by Adam Barth.

  • Scripts/webkitpy/layout_tests/models/test_expectations.py: Folded TestExpectationParser._split_expectation_string into TestExpectationParser.parse.
Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r90940 r90941  
     12011-07-13  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        Consolidate expectations parsing code.
     4        https://bugs.webkit.org/show_bug.cgi?id=64460
     5
     6        Reviewed by Adam Barth.
     7
     8        * Scripts/webkitpy/layout_tests/models/test_expectations.py: Folded TestExpectationParser._split_expectation_string into TestExpectationParser.parse.
     9
    1102011-07-12  Brent Fulgham  <bfulgham@webkit.org>
    211
  • trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py

    r90934 r90941  
    174174
    175175        """
    176         result = TestExpectationLine()
     176        expectation = TestExpectationLine()
    177177        errors = []
    178         (modifiers, name, expectations, comment) = cls._split_expectation_string(expectation_string, errors)
     178        comment_index = expectation_string.find("//")
     179        if comment_index == -1:
     180            comment_index = len(expectation_string)
     181        else:
     182            expectation.comment = expectation_string[comment_index + 2:]
     183
     184        remaining_string = re.sub(r"\s+", " ", expectation_string[:comment_index].strip())
     185        if len(remaining_string) == 0:
     186            expectation.malformed = False
     187            expectation.valid = True
     188            return expectation, errors
     189
     190        parts = remaining_string.split(':')
     191        if len(parts) != 2:
     192            errors.append(("Missing a ':' in" if len(parts) < 2 else "Extraneous ':' in", "'" + expectation_string + "'"))
     193        else:
     194            test_and_expectation = parts[1].split('=')
     195            if len(test_and_expectation) != 2:
     196                errors.append(("Missing expectations in" if len(test_and_expectation) < 2 else "Extraneous '=' in", "'" + expectation_string + "'"))
     197
    179198        if len(errors) > 0:
    180             result.malformed = True
    181             result.comment = expectation_string
    182             result.valid = False
    183         else:
    184             result.malformed = False
    185             result.comment = comment
    186             result.valid = True
    187             result.name = name
    188             # FIXME: Modifiers should be its own class eventually.
    189             if modifiers is not None:
    190                 result.modifiers = cls._split_space_separated(modifiers)
    191             # FIXME: Expectations should be its own class eventually.
    192             if expectations is not None:
    193                 result.expectations = cls._split_space_separated(expectations)
    194 
    195         return (result, errors)
     199            expectation.comment = expectation_string
     200            expectation.malformed = True
     201            expectation.valid = False
     202        else:
     203            expectation.malformed = False
     204            expectation.valid = True
     205            expectation.modifiers = cls._split_space_separated(parts[0])
     206            expectation.name = test_and_expectation[0].strip()
     207            expectation.expectations = cls._split_space_separated(test_and_expectation[1])
     208
     209        return expectation, errors
    196210
    197211    @classmethod
     
    206220            expectations.append(expectation)
    207221        return expectations
    208 
    209     @classmethod
    210     def _split_expectation_string(cls, line, errors):
    211         """Splits line into a string of modifiers, a test name, a string of expectations, and a comment,
    212         returning them as a tuple. In case parsing error, returns empty tuple.
    213         """
    214         comment_index = line.find("//")
    215         comment = ''
    216         if comment_index == -1:
    217             comment_index = len(line)
    218             comment = None
    219         else:
    220             comment = line[comment_index + 2:]
    221 
    222         line = re.sub(r"\s+", " ", line[:comment_index].strip())
    223         if len(line) == 0:
    224             return (None, None, None, comment)
    225 
    226         parts = line.split(':')
    227         if len(parts) != 2:
    228             errors.append(("Missing a ':' in" if len(parts) < 2 else "Extraneous ':' in", "'" + line + "'"))
    229             return (None, None, None, None)
    230 
    231         test_and_expectation = parts[1].split('=')
    232         if len(test_and_expectation) != 2:
    233             errors.append(("Missing expectations in" if len(test_and_expectation) < 2 else "Extraneous '=' in", "'" + line + "'"))
    234             return (None, None, None, None)
    235 
    236         return (parts[0].strip(), test_and_expectation[0].strip(), test_and_expectation[1].strip(), comment)
    237222
    238223    @classmethod
Note: See TracChangeset for help on using the changeset viewer.