11cb0ef41Sopenharmony_ci# Copyright 2018 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci# found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciimport re 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_cifrom . import base 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cidef _is_failure_output(output): 111cb0ef41Sopenharmony_ci return ( 121cb0ef41Sopenharmony_ci output.exit_code != 0 or 131cb0ef41Sopenharmony_ci 'FAILED!' in output.stdout 141cb0ef41Sopenharmony_ci ) 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciclass ExceptionOutProc(base.OutProc): 181cb0ef41Sopenharmony_ci """Output processor for tests with expected exception.""" 191cb0ef41Sopenharmony_ci def __init__( 201cb0ef41Sopenharmony_ci self, expected_outcomes, expected_exception=None, negative=False): 211cb0ef41Sopenharmony_ci super(ExceptionOutProc, self).__init__(expected_outcomes) 221cb0ef41Sopenharmony_ci self._expected_exception = expected_exception 231cb0ef41Sopenharmony_ci self._negative = negative 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci @property 261cb0ef41Sopenharmony_ci def negative(self): 271cb0ef41Sopenharmony_ci return self._negative 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci def _is_failure_output(self, output): 301cb0ef41Sopenharmony_ci if self._expected_exception != self._parse_exception(output.stdout): 311cb0ef41Sopenharmony_ci return True 321cb0ef41Sopenharmony_ci return _is_failure_output(output) 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci def _parse_exception(self, string): 351cb0ef41Sopenharmony_ci # somefile:somelinenumber: someerror[: sometext] 361cb0ef41Sopenharmony_ci # somefile might include an optional drive letter on windows e.g. "e:". 371cb0ef41Sopenharmony_ci match = re.search( 381cb0ef41Sopenharmony_ci '^(?:\w:)?[^:]*:[0-9]+: ([^: ]+?)($|: )', string, re.MULTILINE) 391cb0ef41Sopenharmony_ci if match: 401cb0ef41Sopenharmony_ci return match.group(1).strip() 411cb0ef41Sopenharmony_ci else: 421cb0ef41Sopenharmony_ci return None 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ciclass NoExceptionOutProc(base.OutProc): 461cb0ef41Sopenharmony_ci """Output processor optimized for tests without expected exception.""" 471cb0ef41Sopenharmony_ci def __init__(self, expected_outcomes): 481cb0ef41Sopenharmony_ci super(NoExceptionOutProc, self).__init__(expected_outcomes) 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci def _is_failure_output(self, output): 511cb0ef41Sopenharmony_ci return _is_failure_output(output) 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ciclass PassNoExceptionOutProc(base.PassOutProc): 551cb0ef41Sopenharmony_ci """ 561cb0ef41Sopenharmony_ci Output processor optimized for tests expected to PASS without expected 571cb0ef41Sopenharmony_ci exception. 581cb0ef41Sopenharmony_ci """ 591cb0ef41Sopenharmony_ci def _is_failure_output(self, output): 601cb0ef41Sopenharmony_ci return _is_failure_output(output) 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciPASS_NO_EXCEPTION = PassNoExceptionOutProc() 64