예제 #1
0
 def createFile(self, caseList):
   testFile = CheckerFile("<test_file>")
   for caseEntry in caseList:
     caseName = caseEntry[0]
     testCase = TestCase(testFile, caseName, 0)
     assertionList = caseEntry[1]
     for assertionEntry in assertionList:
       content = assertionEntry[0]
       variant = assertionEntry[1]
       assertion = TestAssertion(testCase, variant, content, 0)
       assertion.addExpression(RegexExpression.createText(content))
   return testFile
예제 #2
0
파일: test.py 프로젝트: COS-Temp/art
 def createFile(self, caseList):
   testFile = CheckerFile("<test_file>")
   for caseEntry in caseList:
     caseName = caseEntry[0]
     testCase = TestCase(testFile, caseName, 0)
     assertionList = caseEntry[1]
     for assertionEntry in assertionList:
       content = assertionEntry[0]
       variant = assertionEntry[1]
       assertion = TestAssertion(testCase, variant, content, 0)
       assertion.addExpression(TestExpression.createPatternFromPlainText(content))
   return testFile
예제 #3
0
파일: parser.py 프로젝트: BenzoRoms/art
def ParseCheckerAssertion(parent, line, variant, lineNo):
  """ This method parses the content of a check line stripped of the initial
      comment symbol and the CHECK-* keyword.
  """
  assertion = TestAssertion(parent, variant, line, lineNo)
  isEvalLine = (variant == TestAssertion.Variant.Eval)

  # Loop as long as there is something to parse.
  while line:
    # Search for the nearest occurrence of the special markers.
    if isEvalLine:
      # The following constructs are not supported in CHECK-EVAL lines
      matchWhitespace = None
      matchPattern = None
      matchVariableDefinition = None
    else:
      matchWhitespace = re.search(r"\s+", line)
      matchPattern = re.search(TestExpression.Regex.regexPattern, line)
      matchVariableDefinition = re.search(TestExpression.Regex.regexVariableDefinition, line)
    matchVariableReference = re.search(TestExpression.Regex.regexVariableReference, line)

    # If one of the above was identified at the current position, extract them
    # from the line, parse them and add to the list of line parts.
    if __isMatchAtStart(matchWhitespace):
      # A whitespace in the check line creates a new separator of line parts.
      # This allows for ignored output between the previous and next parts.
      line = line[matchWhitespace.end():]
      assertion.addExpression(TestExpression.createSeparator())
    elif __isMatchAtStart(matchPattern):
      pattern = line[0:matchPattern.end()]
      pattern = pattern[2:-2]
      line = line[matchPattern.end():]
      assertion.addExpression(TestExpression.createPattern(pattern))
    elif __isMatchAtStart(matchVariableReference):
      var = line[0:matchVariableReference.end()]
      line = line[matchVariableReference.end():]
      name = var[2:-2]
      assertion.addExpression(TestExpression.createVariableReference(name))
    elif __isMatchAtStart(matchVariableDefinition):
      var = line[0:matchVariableDefinition.end()]
      line = line[matchVariableDefinition.end():]
      colonPos = var.find(":")
      name = var[2:colonPos]
      body = var[colonPos+1:-2]
      assertion.addExpression(TestExpression.createVariableDefinition(name, body))
    else:
      # If we're not currently looking at a special marker, this is a plain
      # text match all the way until the first special marker (or the end
      # of the line).
      firstMatch = __firstMatch([ matchWhitespace,
                                  matchPattern,
                                  matchVariableReference,
                                  matchVariableDefinition ],
                                line)
      text = line[0:firstMatch]
      line = line[firstMatch:]
      if isEvalLine:
        assertion.addExpression(TestExpression.createPlainText(text))
      else:
        assertion.addExpression(TestExpression.createPatternFromPlainText(text))
  return assertion
예제 #4
0
파일: parser.py 프로젝트: COS-Temp/art
def ParseCheckerAssertion(parent, line, variant, lineNo):
    """ This method parses the content of a check line stripped of the initial
      comment symbol and the CHECK-* keyword.
  """
    assertion = TestAssertion(parent, variant, line, lineNo)
    isEvalLine = (variant == TestAssertion.Variant.Eval)

    # Loop as long as there is something to parse.
    while line:
        # Search for the nearest occurrence of the special markers.
        if isEvalLine:
            # The following constructs are not supported in CHECK-EVAL lines
            matchWhitespace = None
            matchPattern = None
            matchVariableDefinition = None
        else:
            matchWhitespace = re.search(r"\s+", line)
            matchPattern = re.search(TestExpression.Regex.regexPattern, line)
            matchVariableDefinition = re.search(
                TestExpression.Regex.regexVariableDefinition, line)
        matchVariableReference = re.search(
            TestExpression.Regex.regexVariableReference, line)

        # If one of the above was identified at the current position, extract them
        # from the line, parse them and add to the list of line parts.
        if __isMatchAtStart(matchWhitespace):
            # A whitespace in the check line creates a new separator of line parts.
            # This allows for ignored output between the previous and next parts.
            line = line[matchWhitespace.end():]
            assertion.addExpression(TestExpression.createSeparator())
        elif __isMatchAtStart(matchPattern):
            pattern = line[0:matchPattern.end()]
            pattern = pattern[2:-2]
            line = line[matchPattern.end():]
            assertion.addExpression(TestExpression.createPattern(pattern))
        elif __isMatchAtStart(matchVariableReference):
            var = line[0:matchVariableReference.end()]
            line = line[matchVariableReference.end():]
            name = var[2:-2]
            assertion.addExpression(
                TestExpression.createVariableReference(name))
        elif __isMatchAtStart(matchVariableDefinition):
            var = line[0:matchVariableDefinition.end()]
            line = line[matchVariableDefinition.end():]
            colonPos = var.find(":")
            name = var[2:colonPos]
            body = var[colonPos + 1:-2]
            assertion.addExpression(
                TestExpression.createVariableDefinition(name, body))
        else:
            # If we're not currently looking at a special marker, this is a plain
            # text match all the way until the first special marker (or the end
            # of the line).
            firstMatch = __firstMatch([
                matchWhitespace, matchPattern, matchVariableReference,
                matchVariableDefinition
            ], line)
            text = line[0:firstMatch]
            line = line[firstMatch:]
            if isEvalLine:
                assertion.addExpression(TestExpression.createPlainText(text))
            else:
                assertion.addExpression(
                    TestExpression.createPatternFromPlainText(text))
    return assertion