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 difflib
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cifrom . import base
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciclass OutProc(base.OutProc):
111cb0ef41Sopenharmony_ci  def __init__(self, expected_outcomes, expected_path):
121cb0ef41Sopenharmony_ci    super(OutProc, self).__init__(expected_outcomes)
131cb0ef41Sopenharmony_ci    self._expected_path = expected_path
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  def _is_failure_output(self, output):
161cb0ef41Sopenharmony_ci    with open(self._expected_path) as f:
171cb0ef41Sopenharmony_ci      expected = f.read()
181cb0ef41Sopenharmony_ci    expected_lines = expected.splitlines()
191cb0ef41Sopenharmony_ci    actual_lines = output.stdout.splitlines()
201cb0ef41Sopenharmony_ci    diff = difflib.unified_diff(expected_lines, actual_lines, lineterm="",
211cb0ef41Sopenharmony_ci                                fromfile="expected_path")
221cb0ef41Sopenharmony_ci    diffstring = '\n'.join(diff)
231cb0ef41Sopenharmony_ci    if diffstring != "":
241cb0ef41Sopenharmony_ci      if "generated from a non-shipping build" in output.stdout:
251cb0ef41Sopenharmony_ci        return False
261cb0ef41Sopenharmony_ci      if not "generated from a shipping build" in output.stdout:
271cb0ef41Sopenharmony_ci        output.stdout = "Unexpected output:\n\n" + output.stdout
281cb0ef41Sopenharmony_ci        return True
291cb0ef41Sopenharmony_ci      output.stdout = diffstring
301cb0ef41Sopenharmony_ci      return True
311cb0ef41Sopenharmony_ci    return False
32