| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Helper script to update the test error expectations based on actual results. | 6 """Helper script to update the test error expectations based on actual results. |
| 7 | 7 |
| 8 This is useful for regenerating test expectations after making changes to the | 8 This is useful for regenerating test expectations after making changes to the |
| 9 error format. | 9 error format. |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 # Update the file. | 101 # Update the file. |
| 102 write_string_to_file(contents, path) | 102 write_string_to_file(contents, path) |
| 103 | 103 |
| 104 | 104 |
| 105 def fixup_py_file(path, actual_errors): | 105 def fixup_py_file(path, actual_errors): |
| 106 """Replaces the 'errors = XXX' section of the test's python script""" | 106 """Replaces the 'errors = XXX' section of the test's python script""" |
| 107 contents = read_file_to_string(path) | 107 contents = read_file_to_string(path) |
| 108 | 108 |
| 109 # This assumes that the errors variable uses triple quotes. | 109 # This assumes that the errors variable uses triple quotes. |
| 110 prog = re.compile(r'^errors = """(.*?)"""', re.MULTILINE | re.DOTALL) | 110 prog = re.compile(r'^errors = (""".*?"""|None)', re.MULTILINE | re.DOTALL) |
| 111 result = prog.search(contents) | 111 result = prog.search(contents) |
| 112 | 112 |
| 113 # Replace the stuff in between the triple quotes with the actual errors. | 113 # Replace the stuff in between the triple quotes with the actual errors. |
| 114 contents = replace_string(contents, result.start(1), result.end(1), | 114 contents = replace_string(contents, result.start(1), result.end(1), |
| 115 actual_errors) | 115 '"""' + actual_errors + '"""') |
| 116 | 116 |
| 117 # Update the file. | 117 # Update the file. |
| 118 write_string_to_file(contents, path) | 118 write_string_to_file(contents, path) |
| 119 | 119 |
| 120 | 120 |
| 121 def get_src_root(): | 121 def get_src_root(): |
| 122 """Returns the path to the enclosing //src directory. This assumes the | 122 """Returns the path to the enclosing //src directory. This assumes the |
| 123 current script is inside the source tree.""" | 123 current script is inside the source tree.""" |
| 124 cur_dir = os.path.dirname(os.path.realpath(__file__)) | 124 cur_dir = os.path.dirname(os.path.realpath(__file__)) |
| 125 | 125 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 for m in failed_test_regex.finditer(test_stdout): | 169 for m in failed_test_regex.finditer(test_stdout): |
| 170 actual_errors = m.group(1) | 170 actual_errors = m.group(1) |
| 171 actual_errors = actual_errors.decode('string-escape') | 171 actual_errors = actual_errors.decode('string-escape') |
| 172 relative_test_path = m.group(2) | 172 relative_test_path = m.group(2) |
| 173 fixup_errors_for_file(actual_errors, get_abs_path(relative_test_path)) | 173 fixup_errors_for_file(actual_errors, get_abs_path(relative_test_path)) |
| 174 | 174 |
| 175 | 175 |
| 176 if __name__ == "__main__": | 176 if __name__ == "__main__": |
| 177 main() | 177 main() |
| OLD | NEW |