| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Utility module for checking testharness test output.""" | 5 """Utility module for checking testharness test output.""" |
| 6 | 6 |
| 7 _TESTHARNESSREPORT_HEADER = 'This is a testharness.js-based test.' | 7 _TESTHARNESSREPORT_HEADER = 'This is a testharness.js-based test.' |
| 8 _TESTHARNESSREPORT_FOOTER = 'Harness: the test ran to completion.' | 8 _TESTHARNESSREPORT_FOOTER = 'Harness: the test ran to completion.' |
| 9 | 9 |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 for line in lines: | 27 for line in lines: |
| 28 if line == _TESTHARNESSREPORT_HEADER: | 28 if line == _TESTHARNESSREPORT_HEADER: |
| 29 found_header = True | 29 found_header = True |
| 30 elif line == _TESTHARNESSREPORT_FOOTER: | 30 elif line == _TESTHARNESSREPORT_FOOTER: |
| 31 found_footer = True | 31 found_footer = True |
| 32 | 32 |
| 33 return found_header and found_footer | 33 return found_header and found_footer |
| 34 | 34 |
| 35 | 35 |
| 36 def is_testharness_output_passing(content_text): | 36 def is_testharness_output_passing(content_text): |
| 37 """Checks whether |content_text| is a passing testharness output. | 37 """Returns whether |content_text| is a passing testharness output.""" |
| 38 | 38 |
| 39 Under a relatively loose/accepting definition of passing | 39 # Leading and trailing white spaces are accepted. |
| 40 testharness output, we consider any output with at least one | |
| 41 PASS result and no FAIL result (or TIMEOUT or NOTRUN). | |
| 42 """ | |
| 43 # Leading and trailing whitespace are ignored. | |
| 44 lines = content_text.strip().splitlines() | 40 lines = content_text.strip().splitlines() |
| 45 lines = [line.strip() for line in lines] | 41 lines = [line.strip() for line in lines] |
| 46 | 42 |
| 47 at_least_one_pass = False | 43 # The check is very conservative and rejects any unexpected content in the o
utput. |
| 44 previous_line_is_console_line = False |
| 45 for line in lines: |
| 46 # There should be no empty lines, unless the empty line follows a consol
e message. |
| 47 if len(line) == 0: |
| 48 if previous_line_is_console_line: |
| 49 continue |
| 50 else: |
| 51 return False |
| 48 | 52 |
| 49 for line in lines: | 53 # Those lines are expected to be exactly equivalent. |
| 54 if line == _TESTHARNESSREPORT_HEADER or line == _TESTHARNESSREPORT_FOOTE
R: |
| 55 previous_line_is_console_line = False |
| 56 continue |
| 57 |
| 58 # Those are expected passing output. |
| 59 if line.startswith('CONSOLE'): |
| 60 previous_line_is_console_line = True |
| 61 continue |
| 62 |
| 50 if line.startswith('PASS'): | 63 if line.startswith('PASS'): |
| 51 at_least_one_pass = True | 64 previous_line_is_console_line = False |
| 52 continue | 65 continue |
| 66 |
| 67 # Those are expected failing output. |
| 53 if (line.startswith('FAIL') or | 68 if (line.startswith('FAIL') or |
| 54 line.startswith('TIMEOUT') or | 69 line.startswith('TIMEOUT') or |
| 55 line.startswith('NOTRUN') or | 70 line.startswith('NOTRUN') or |
| 56 line.startswith('Harness Error. harness_status = ')): | 71 line.startswith('Harness Error. harness_status = ')): |
| 57 return False | 72 return False |
| 58 | 73 |
| 59 return at_least_one_pass | 74 # Unexpected output should be considered as a failure. |
| 75 return False |
| 76 |
| 77 return True |
| 60 | 78 |
| 61 | 79 |
| 62 def has_console_errors_or_warnings(content_text): | 80 def has_console_errors_or_warnings(content_text): |
| 63 """Returns whether |content_text| is has console errors or warnings.""" | 81 """Returns whether |content_text| is has console errors or warnings.""" |
| 64 | 82 |
| 65 def is_warning_or_error(line): | 83 def is_warning_or_error(line): |
| 66 return line.startswith('CONSOLE ERROR:') or line.startswith('CONSOLE WAR
NING:') | 84 return line.startswith('CONSOLE ERROR:') or line.startswith('CONSOLE WAR
NING:') |
| 67 | 85 |
| 68 lines = content_text.strip().splitlines() | 86 lines = content_text.strip().splitlines() |
| 69 return any(is_warning_or_error(line) for line in lines) | 87 return any(is_warning_or_error(line) for line in lines) |
| OLD | NEW |