| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Script that updates dart2js status lines automatically for tests under the | 5 /// Script that updates dart2js status lines automatically for tests under the |
| 6 /// '$dart2js_with_kernel' configuration. | 6 /// '$dart2js_with_kernel' configuration. |
| 7 /// | 7 /// |
| 8 /// This script is hardcoded to only support this configuration and relies on | 8 /// This script is hardcoded to only support this configuration and relies on |
| 9 /// a convention for how the status files are structured, In particular, | 9 /// a convention for how the status files are structured, In particular, |
| 10 /// every status file for dart2js should have 2 sections: | 10 /// every status file for dart2js should have 2 sections: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 section.add(record); | 76 section.add(record); |
| 77 last = record; | 77 last = record; |
| 78 } | 78 } |
| 79 section?.update(); | 79 section?.update(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 /// Represents an existing entry in the logs. | 82 /// Represents an existing entry in the logs. |
| 83 class ExistingEntry { | 83 class ExistingEntry { |
| 84 final String test; | 84 final String test; |
| 85 final String status; | 85 final String status; |
| 86 final bool hasComment; |
| 86 | 87 |
| 87 ExistingEntry(this.test, this.status); | 88 ExistingEntry(this.test, this.status, this.hasComment); |
| 88 | 89 |
| 89 static parse(String line) { | 90 static parse(String line) { |
| 90 var colonIndex = line.indexOf(':'); | 91 var colonIndex = line.indexOf(':'); |
| 91 var test = line.substring(0, colonIndex); | 92 var test = line.substring(0, colonIndex); |
| 92 var status = line.substring(colonIndex + 1).trim(); | 93 var status = line.substring(colonIndex + 1).trim(); |
| 93 var commentIndex = status.indexOf("#"); | 94 var commentIndex = status.indexOf("#"); |
| 94 if (commentIndex != -1) { | 95 if (commentIndex != -1) { |
| 95 status = status.substring(0, commentIndex); | 96 status = status.substring(0, commentIndex); |
| 96 } | 97 } |
| 97 return new ExistingEntry(test, status); | 98 return new ExistingEntry(test, status, commentIndex != -1); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 /// Represents a section in a .status file that corresponds to a specific suite | 102 /// Represents a section in a .status file that corresponds to a specific suite |
| 102 /// and configuration. | 103 /// and configuration. |
| 103 class ConfigurationInSuiteSection { | 104 class ConfigurationInSuiteSection { |
| 104 final String suite; | 105 final String suite; |
| 105 final String _statusFile; | 106 final String _statusFile; |
| 106 final String _contents; | 107 final String _contents; |
| 107 final int _begin; | 108 final int _begin; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 // same order: preserving entries that didn't change, and updating entries | 127 // same order: preserving entries that didn't change, and updating entries |
| 127 // where the logs show that the test status changed. | 128 // where the logs show that the test status changed. |
| 128 | 129 |
| 129 // Records are already sorted, but we sort the file contents in case the | 130 // Records are already sorted, but we sort the file contents in case the |
| 130 // file has been tampered with. | 131 // file has been tampered with. |
| 131 originalEntries.sort(); | 132 originalEntries.sort(); |
| 132 | 133 |
| 133 var newContents = new StringBuffer(); | 134 var newContents = new StringBuffer(); |
| 134 newContents.write(_contents.substring(0, _begin)); | 135 newContents.write(_contents.substring(0, _begin)); |
| 135 addFromRecord(Record record) { | 136 addFromRecord(Record record) { |
| 136 newContents.writeln('${record.test}: ${record.actual}'); | 137 var comment = record.reason != null ? ' # ${record.reason}' : ''; |
| 138 newContents.writeln('${record.test}: ${record.actual}$comment'); |
| 137 } | 139 } |
| 138 | 140 |
| 139 int i = 0, j = 0; | 141 int i = 0, j = 0; |
| 140 while (i < originalEntries.length && j < _records.length) { | 142 while (i < originalEntries.length && j < _records.length) { |
| 141 var existingLine = originalEntries[i]; | 143 var existingLine = originalEntries[i]; |
| 142 if (existingLine.trim().isEmpty) { | 144 if (existingLine.trim().isEmpty) { |
| 143 i++; | 145 i++; |
| 144 continue; | 146 continue; |
| 145 } | 147 } |
| 146 var existing = ExistingEntry.parse(existingLine); | 148 var existing = ExistingEntry.parse(existingLine); |
| 147 var record = _records[j]; | 149 var record = _records[j]; |
| 148 var compare = existing.test.compareTo(record.test); | 150 var compare = existing.test.compareTo(record.test); |
| 149 if (compare < 0) { | 151 if (compare < 0) { |
| 150 // Existing test was unaffected, copy the status line. | 152 // Existing test was unaffected, copy the status line. |
| 151 newContents.writeln(existingLine); | 153 newContents.writeln(existingLine); |
| 152 i++; | 154 i++; |
| 153 } else if (compare > 0) { | 155 } else if (compare > 0) { |
| 154 // New entry, if it's a failure, we haven't seen this before and must | 156 // New entry, if it's a failure, we haven't seen this before and must |
| 155 // add it. If the status says it is passing, we ignore it. We do this | 157 // add it. If the status says it is passing, we ignore it. We do this |
| 156 // to support making this script idempotent if the patching has already | 158 // to support making this script idempotent if the patching has already |
| 157 // been done. | 159 // been done. |
| 158 if (!record.isPassing) { | 160 if (!record.isPassing) { |
| 159 // New failure never seen before | 161 // New failure never seen before |
| 160 addFromRecord(record); | 162 addFromRecord(record); |
| 161 changes++; | 163 changes++; |
| 162 } | 164 } |
| 163 j++; | 165 j++; |
| 164 } else if (existing.status == record.actual) { | 166 } else if (existing.status == record.actual) { |
| 165 // This also should only happen if the patching has already been done. | 167 if (!existing.hasComment && record.reason != null) { |
| 166 // We don't complain to make this script idempotent. | 168 addFromRecord(record); |
| 167 newContents.writeln(existingLine); | 169 changes++; |
| 170 } else { |
| 171 // This also should only happen if the patching has already been done. |
| 172 // We don't complain to make this script idempotent. |
| 173 newContents.writeln(existingLine); |
| 174 } |
| 168 ignored++; | 175 ignored++; |
| 169 i++; | 176 i++; |
| 170 j++; | 177 j++; |
| 171 } else { | 178 } else { |
| 172 changes++; | 179 changes++; |
| 173 // The status changed, if it is now passing, we omit the entry entirely, | 180 // The status changed, if it is now passing, we omit the entry entirely, |
| 174 // otherwise we use the status from the logs. | 181 // otherwise we use the status from the logs. |
| 175 if (!record.isPassing) { | 182 if (!record.isPassing) { |
| 176 addFromRecord(record); | 183 addFromRecord(record); |
| 177 } | 184 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 208 exit(1); | 215 exit(1); |
| 209 } | 216 } |
| 210 int begin = contents.indexOf('\n', sectionDeclaration) + 1; | 217 int begin = contents.indexOf('\n', sectionDeclaration) + 1; |
| 211 assert(begin != 0); | 218 assert(begin != 0); |
| 212 int end = contents.indexOf('\n[', begin + 1); | 219 int end = contents.indexOf('\n[', begin + 1); |
| 213 end = end == -1 ? contents.length : end + 1; | 220 end = end == -1 ? contents.length : end + 1; |
| 214 return new ConfigurationInSuiteSection( | 221 return new ConfigurationInSuiteSection( |
| 215 suite, statusFile, contents, begin, end); | 222 suite, statusFile, contents, begin, end); |
| 216 } | 223 } |
| 217 } | 224 } |
| OLD | NEW |