Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library multitest; | 5 library multitest; |
| 6 | 6 |
| 7 import "dart:async"; | 7 import "dart:async"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 | 9 |
| 10 import "path.dart"; | 10 import "path.dart"; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 List<String> lines = contents.split(line_separator); | 77 List<String> lines = contents.split(line_separator); |
| 78 if (lines.last == '') lines.removeLast(); | 78 if (lines.last == '') lines.removeLast(); |
| 79 bytes = null; | 79 bytes = null; |
| 80 contents = null; | 80 contents = null; |
| 81 Set<String> validMultitestOutcomes = new Set<String>.from( | 81 Set<String> validMultitestOutcomes = new Set<String>.from( |
| 82 ['ok', 'compile-time error', 'runtime error', | 82 ['ok', 'compile-time error', 'runtime error', |
| 83 'static type warning', 'dynamic type error', | 83 'static type warning', 'dynamic type error', |
| 84 'checked mode compile-time error']); | 84 'checked mode compile-time error']); |
| 85 | 85 |
| 86 List<String> testTemplate = new List<String>(); | 86 List<String> testTemplate = new List<String>(); |
| 87 testTemplate.add( | |
| 88 '// Test created from multitest named ${filePath.toNativePath()}.'); | |
| 89 // Create the set of multitests, which will have a new test added each | 87 // Create the set of multitests, which will have a new test added each |
| 90 // time we see a multitest line with a new key. | 88 // time we see a multitest line with a new key. |
| 91 Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); | 89 Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); |
| 92 | 90 |
| 91 // 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.
| |
| 92 testsAsLines['none'] = testTemplate; | |
| 93 outcomes['none'] = new Set<String>(); | |
| 94 | |
| 93 int lineCount = 0; | 95 int lineCount = 0; |
| 94 for (String line in lines) { | 96 for (String line in lines) { |
| 95 lineCount++; | 97 lineCount++; |
| 96 var annotation = new _Annotation.from(line); | 98 var annotation = new _Annotation.from(line); |
| 97 if (annotation != null) { | 99 if (annotation != null) { |
| 98 testsAsLines.putIfAbsent(annotation.key, | 100 // Add empty line to all tests. |
| 99 () => new List<String>.from(testTemplate)).add(line); | 101 for (var test in testsAsLines.values) test.add(""); |
| 100 outcomes.putIfAbsent(annotation.key, | 102 var testLines = testsAsLines.putIfAbsent(annotation.key, |
| 101 () => new Set<String>()); | 103 () => new List<String>.from(testTemplate)); |
| 102 if (annotation.rest == 'continued') { | 104 // Replace empty line with actual line only in matching test. |
| 103 continue; | 105 testLines[testLines.length - 1] = line; |
| 104 } else { | 106 outcomes.putIfAbsent(annotation.key, () => new Set<String>()); |
| 107 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.
| |
| 105 for (String nextOutcome in annotation.outcomesList) { | 108 for (String nextOutcome in annotation.outcomesList) { |
| 106 if (validMultitestOutcomes.contains(nextOutcome)) { | 109 if (validMultitestOutcomes.contains(nextOutcome)) { |
| 107 outcomes[annotation.key].add(nextOutcome); | 110 outcomes[annotation.key].add(nextOutcome); |
| 108 } else { | 111 } else { |
| 109 DebugLogger.warning( | 112 DebugLogger.warning( |
| 110 "Warning: Invalid test directive '$nextOutcome' on line " | 113 "Warning: Invalid test directive '$nextOutcome' on line " |
| 111 "${lineCount}:\n${annotation.rest} "); | 114 "${lineCount}:\n${annotation.rest} "); |
| 112 } | 115 } |
| 113 } | 116 } |
| 114 } | 117 } |
| 115 } else { | 118 } else { |
| 116 testTemplate.add(line); | |
| 117 for (var test in testsAsLines.values) test.add(line); | 119 for (var test in testsAsLines.values) test.add(line); |
| 118 } | 120 } |
| 119 } | 121 } |
| 122 // End marker, has a final line separator so we don't need to add it after | |
| 123 // joining the lines. | |
| 124 var marker = | |
| 125 '// Test created from multitest named ${filePath.toNativePath()}.' | |
| 126 '$line_separator'; | |
| 127 for (var test in testsAsLines.values) test.add(marker); | |
| 120 | 128 |
| 121 var keysToDelete = []; | 129 var keysToDelete = []; |
| 122 // Check that every key (other than the none case) has at least one outcome | 130 // Check that every key (other than the none case) has at least one outcome |
| 123 for (var outcomeKey in outcomes.keys) { | 131 for (var outcomeKey in outcomes.keys) { |
| 124 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty) { | 132 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty) { |
| 125 DebugLogger.warning( | 133 DebugLogger.warning( |
| 126 "Warning: Test ${outcomeKey} has no valid annotated outcomes.\n" | 134 "Warning: Test ${outcomeKey} has no valid annotated outcomes.\n" |
| 127 "Expected one of: ${validMultitestOutcomes.toString()}"); | 135 "Expected one of: ${validMultitestOutcomes.toString()}"); |
| 128 // If this multitest doesn't have an outcome, mark the multitest for | 136 // If this multitest doesn't have an outcome, mark the multitest for |
| 129 // deletion. | 137 // deletion. |
| 130 keysToDelete.add(outcomeKey); | 138 keysToDelete.add(outcomeKey); |
| 131 } | 139 } |
| 132 } | 140 } |
| 133 // If a key/multitest was marked for deletion, do the necessary cleanup. | 141 // If a key/multitest was marked for deletion, do the necessary cleanup. |
| 134 keysToDelete.forEach((key) => outcomes.remove(key)); | 142 keysToDelete.forEach(outcomes.remove); |
| 135 keysToDelete.forEach((key) => testsAsLines.remove(key)); | 143 keysToDelete.forEach(testsAsLines.remove); |
| 136 | |
| 137 // Add the template, with no multitest lines, as a test with key 'none'. | |
| 138 testsAsLines['none'] = testTemplate; | |
| 139 outcomes['none'] = new Set<String>(); | |
| 140 | 144 |
| 141 // Copy all the tests into the output map tests, as multiline strings. | 145 // Copy all the tests into the output map tests, as multiline strings. |
| 142 for (String key in testsAsLines.keys) { | 146 for (String key in testsAsLines.keys) { |
| 143 tests[key] = testsAsLines[key].join(line_separator) + line_separator; | 147 tests[key] = testsAsLines[key].join(line_separator); |
| 144 } | 148 } |
| 145 } | 149 } |
| 146 | 150 |
| 147 // Represents a mutlitest annotation in the special /// comment. | 151 // Represents a mutlitest annotation in the special /// comment. |
| 148 class _Annotation { | 152 class _Annotation { |
| 149 String key; | 153 String key; |
| 150 String rest; | 154 String rest; |
| 151 List<String> outcomesList; | 155 List<String> outcomesList; |
| 152 _Annotation() {} | 156 _Annotation() {} |
| 153 factory _Annotation.from(String line) { | 157 factory _Annotation.from(String line) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // TestSuite.forDirectory. | 302 // TestSuite.forDirectory. |
| 299 split.removeLast(); | 303 split.removeLast(); |
| 300 } | 304 } |
| 301 String path = '${generatedTestDir.path}/${split.last}'; | 305 String path = '${generatedTestDir.path}/${split.last}'; |
| 302 Directory dir = new Directory(path); | 306 Directory dir = new Directory(path); |
| 303 if (!dir.existsSync()) { | 307 if (!dir.existsSync()) { |
| 304 dir.createSync(); | 308 dir.createSync(); |
| 305 } | 309 } |
| 306 return new Path(new File(path).absolute.path); | 310 return new Path(new File(path).absolute.path); |
| 307 } | 311 } |
| OLD | NEW |