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 testharness.""" | 5 """Utility module for testharness.""" |
6 | 6 |
7 | 7 |
8 # const definitions | 8 # const definitions |
9 TESTHARNESSREPORT_HEADER = 'This is a testharness.js-based test.' | 9 TESTHARNESSREPORT_HEADER = 'This is a testharness.js-based test.' |
10 TESTHARNESSREPORT_FOOTER = 'Harness: the test ran to completion.' | 10 TESTHARNESSREPORT_FOOTER = 'Harness: the test ran to completion.' |
11 | 11 |
12 | 12 |
13 def is_testharness_output(content_text): | 13 def is_testharness_output(content_text): |
14 """ | 14 """Returns whether the content_text in parameter is a testharness output.""" |
15 Returns whether the content_text in parameter is a testharness output. | |
16 """ | |
17 | 15 |
18 # Leading and trailing white spaces are accepted. | 16 # Leading and trailing white spaces are accepted. |
19 lines = content_text.strip().splitlines() | 17 lines = content_text.strip().splitlines() |
20 lines = [line.strip() for line in lines] | 18 lines = [line.strip() for line in lines] |
21 | 19 |
22 # A testharness output is defined as containing the header and the footer. | 20 # A testharness output is defined as containing the header and the footer. |
23 found_header = False | 21 found_header = False |
24 found_footer = False | 22 found_footer = False |
25 for line in lines: | 23 for line in lines: |
26 if line == TESTHARNESSREPORT_HEADER: | 24 if line == TESTHARNESSREPORT_HEADER: |
27 found_header = True | 25 found_header = True |
28 elif line == TESTHARNESSREPORT_FOOTER: | 26 elif line == TESTHARNESSREPORT_FOOTER: |
29 found_footer = True | 27 found_footer = True |
30 | 28 |
31 return found_header and found_footer | 29 return found_header and found_footer |
32 | 30 |
33 | 31 |
34 def is_testharness_output_passing(content_text): | 32 def is_testharness_output_passing(content_text): |
35 """ | 33 """Returns whether the content_text in parameter is a passing testharness ou
tput. |
36 Returns whether the content_text in parameter is a passing testharness outpu
t. | |
37 | 34 |
38 Note: | 35 Note: |
39 It is expected that the |content_text| is a testharness output. | 36 It is expected that the |content_text| is a testharness output. |
40 """ | 37 """ |
41 | 38 |
42 # Leading and trailing white spaces are accepted. | 39 # Leading and trailing white spaces are accepted. |
43 lines = content_text.strip().splitlines() | 40 lines = content_text.strip().splitlines() |
44 lines = [line.strip() for line in lines] | 41 lines = [line.strip() for line in lines] |
45 | 42 |
46 # The check is very conservative and rejects any unexpected content in the o
utput. | 43 # The check is very conservative and rejects any unexpected content in the o
utput. |
(...skipping 28 matching lines...) Expand all Loading... |
75 line.startswith('Harness Error. harness_status = '): | 72 line.startswith('Harness Error. harness_status = '): |
76 return False | 73 return False |
77 | 74 |
78 # Unexpected output should be considered as a failure. | 75 # Unexpected output should be considered as a failure. |
79 return False | 76 return False |
80 | 77 |
81 return True | 78 return True |
82 | 79 |
83 | 80 |
84 def is_testharness_output_with_console_errors_or_warnings(content_text): | 81 def is_testharness_output_with_console_errors_or_warnings(content_text): |
85 """ | 82 """Returns whether the content_text in parameter is a testharness output wit
h |
86 Returns whether the content_text in parameter is a testharness output with | |
87 console errors. | 83 console errors. |
88 | 84 |
89 Note: | 85 Note: |
90 It is expected that the |content_text| is a testharness output. | 86 It is expected that the |content_text| is a testharness output. |
91 """ | 87 """ |
92 | 88 |
93 lines = content_text.strip().splitlines() | 89 lines = content_text.strip().splitlines() |
94 for line in lines: | 90 for line in lines: |
95 if line.startswith('CONSOLE ERROR:') or line.startswith('CONSOLE WARNING
:'): | 91 if line.startswith('CONSOLE ERROR:') or line.startswith('CONSOLE WARNING
:'): |
96 return True | 92 return True |
97 | 93 |
98 return False | 94 return False |
OLD | NEW |