Chromium Code Reviews| Index: tools/testing/dart/multitest.dart |
| diff --git a/tools/testing/dart/multitest.dart b/tools/testing/dart/multitest.dart |
| index 3aed790d6fc096cfb39cfdfac36b5dc026574772..d17c62a3ab83f3ea714b8899ce2a09e27c4b8a97 100644 |
| --- a/tools/testing/dart/multitest.dart |
| +++ b/tools/testing/dart/multitest.dart |
| @@ -84,24 +84,27 @@ void ExtractTestsFromMultitest(Path filePath, |
| 'checked mode compile-time error']); |
| List<String> testTemplate = new List<String>(); |
| - testTemplate.add( |
| - '// Test created from multitest named ${filePath.toNativePath()}.'); |
| // Create the set of multitests, which will have a new test added each |
| // time we see a multitest line with a new key. |
| Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); |
| + // Add the template, with no multitest lines, as a test with key 'none'. |
|
Bill Hesse
2015/03/20 10:32:57
Maybe drop the testTemplate variable completely, a
Lasse Reichstein Nielsen
2015/03/20 13:06:30
Done.
|
| + testsAsLines['none'] = testTemplate; |
| + outcomes['none'] = new Set<String>(); |
| + |
| int lineCount = 0; |
| for (String line in lines) { |
| lineCount++; |
| var annotation = new _Annotation.from(line); |
| if (annotation != null) { |
| - testsAsLines.putIfAbsent(annotation.key, |
| - () => new List<String>.from(testTemplate)).add(line); |
| - outcomes.putIfAbsent(annotation.key, |
| - () => new Set<String>()); |
| - if (annotation.rest == 'continued') { |
| - continue; |
| - } else { |
| + // Add empty line to all tests. |
| + for (var test in testsAsLines.values) test.add(""); |
| + var testLines = testsAsLines.putIfAbsent(annotation.key, |
| + () => new List<String>.from(testTemplate)); |
| + // Replace empty line with actual line only in matching test. |
| + testLines[testLines.length - 1] = line; |
| + outcomes.putIfAbsent(annotation.key, () => new Set<String>()); |
| + if (annotation.rest != 'continued') { |
|
Bill Hesse
2015/03/20 10:32:57
I think the code is clearer if we remove the testL
Lasse Reichstein Nielsen
2015/03/20 13:06:30
That is more readable. Done.
|
| for (String nextOutcome in annotation.outcomesList) { |
| if (validMultitestOutcomes.contains(nextOutcome)) { |
| outcomes[annotation.key].add(nextOutcome); |
| @@ -113,10 +116,15 @@ void ExtractTestsFromMultitest(Path filePath, |
| } |
| } |
| } else { |
| - testTemplate.add(line); |
| for (var test in testsAsLines.values) test.add(line); |
| } |
| } |
| + // End marker, has a final line separator so we don't need to add it after |
| + // joining the lines. |
| + var marker = |
| + '// Test created from multitest named ${filePath.toNativePath()}.' |
| + '$line_separator'; |
| + for (var test in testsAsLines.values) test.add(marker); |
| var keysToDelete = []; |
| // Check that every key (other than the none case) has at least one outcome |
| @@ -131,16 +139,12 @@ void ExtractTestsFromMultitest(Path filePath, |
| } |
| } |
| // If a key/multitest was marked for deletion, do the necessary cleanup. |
| - keysToDelete.forEach((key) => outcomes.remove(key)); |
| - keysToDelete.forEach((key) => testsAsLines.remove(key)); |
| - |
| - // Add the template, with no multitest lines, as a test with key 'none'. |
| - testsAsLines['none'] = testTemplate; |
| - outcomes['none'] = new Set<String>(); |
| + keysToDelete.forEach(outcomes.remove); |
| + keysToDelete.forEach(testsAsLines.remove); |
| // Copy all the tests into the output map tests, as multiline strings. |
| for (String key in testsAsLines.keys) { |
| - tests[key] = testsAsLines[key].join(line_separator) + line_separator; |
| + tests[key] = testsAsLines[key].join(line_separator); |
| } |
| } |