• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 the V8 project authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import re
6
7from . import base
8
9
10class ExceptionOutProc(base.OutProc):
11  """Output processor for tests with expected exception."""
12  def __init__(self, expected_outcomes, expected_exception=None):
13    super(ExceptionOutProc, self).__init__(expected_outcomes)
14    self._expected_exception = expected_exception
15
16  def _is_failure_output(self, output):
17    if output.exit_code != 0:
18      return True
19    if self._expected_exception != self._parse_exception(output.stdout):
20      return True
21    return 'FAILED!' in output.stdout
22
23  def _parse_exception(self, string):
24    # somefile:somelinenumber: someerror[: sometext]
25    # somefile might include an optional drive letter on windows e.g. "e:".
26    match = re.search(
27        '^(?:\w:)?[^:]*:[0-9]+: ([^: ]+?)($|: )', string, re.MULTILINE)
28    if match:
29      return match.group(1).strip()
30    else:
31      return None
32
33
34def _is_failure_output(self, output):
35  return (
36    output.exit_code != 0 or
37    'FAILED!' in output.stdout
38  )
39
40
41class NoExceptionOutProc(base.OutProc):
42  """Output processor optimized for tests without expected exception."""
43NoExceptionOutProc._is_failure_output = _is_failure_output
44
45
46class PassNoExceptionOutProc(base.PassOutProc):
47  """
48  Output processor optimized for tests expected to PASS without expected
49  exception.
50  """
51PassNoExceptionOutProc._is_failure_output = _is_failure_output
52
53
54PASS_NO_EXCEPTION = PassNoExceptionOutProc()
55