| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return original[0:start] + replacement + original[end:] | 86 return original[0:start] + replacement + original[end:] |
| 87 | 87 |
| 88 | 88 |
| 89 def fixup_pem_file(path, actual_errors): | 89 def fixup_pem_file(path, actual_errors): |
| 90 """Updates the ERRORS block in the test .pem file""" | 90 """Updates the ERRORS block in the test .pem file""" |
| 91 contents = read_file_to_string(path) | 91 contents = read_file_to_string(path) |
| 92 | 92 |
| 93 m = errors_block_regex.search(contents) | 93 m = errors_block_regex.search(contents) |
| 94 | 94 |
| 95 if not m: | 95 if not m: |
| 96 print "Couldn't find ERRORS block in %s" % (path) | 96 contents += '\n' + common.text_data_to_pem('ERRORS', actual_errors) |
| 97 return | 97 else: |
| 98 | 98 contents = replace_string(contents, m.start(1), m.end(1), |
| 99 contents = replace_string(contents, m.start(1), m.end(1), | 99 common.text_data_to_pem('ERRORS', actual_errors)) |
| 100 common.text_data_to_pem('ERRORS', actual_errors)) | |
| 101 | 100 |
| 102 # Update the file. | 101 # Update the file. |
| 103 write_string_to_file(contents, path) | 102 write_string_to_file(contents, path) |
| 104 | 103 |
| 105 | 104 |
| 106 def fixup_py_file(path, actual_errors): | 105 def fixup_py_file(path, actual_errors): |
| 107 """Replaces the 'errors = XXX' section of the test's python script""" | 106 """Replaces the 'errors = XXX' section of the test's python script""" |
| 108 contents = read_file_to_string(path) | 107 contents = read_file_to_string(path) |
| 109 | 108 |
| 110 # This assumes that the errors variable uses triple quotes. | 109 # This assumes that the errors variable uses triple quotes. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 168 |
| 170 for m in failed_test_regex.finditer(test_stdout): | 169 for m in failed_test_regex.finditer(test_stdout): |
| 171 actual_errors = m.group(1) | 170 actual_errors = m.group(1) |
| 172 actual_errors = actual_errors.decode('string-escape') | 171 actual_errors = actual_errors.decode('string-escape') |
| 173 relative_test_path = m.group(2) | 172 relative_test_path = m.group(2) |
| 174 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)) |
| 175 | 174 |
| 176 | 175 |
| 177 if __name__ == "__main__": | 176 if __name__ == "__main__": |
| 178 main() | 177 main() |
| OLD | NEW |