Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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:io"); | 7 #import("dart:io"); |
| 8 #import("test_suite.dart"); | 8 #import("test_suite.dart"); |
| 9 | 9 |
| 10 // Multitests are Dart test scripts containing lines of the form | 10 // Multitests are Dart test scripts containing lines of the form |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 80 |
| 81 List<String> testTemplate = new List<String>(); | 81 List<String> testTemplate = new List<String>(); |
| 82 testTemplate.add('// Test created from multitest named $filename.'); | 82 testTemplate.add('// Test created from multitest named $filename.'); |
| 83 // Create the set of multitests, which will have a new test added each | 83 // Create the set of multitests, which will have a new test added each |
| 84 // time we see a multitest line with a new key. | 84 // time we see a multitest line with a new key. |
| 85 Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); | 85 Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); |
| 86 | 86 |
| 87 int lineCount = 0; | 87 int lineCount = 0; |
| 88 for (String line in lines) { | 88 for (String line in lines) { |
| 89 lineCount++; | 89 lineCount++; |
| 90 if (line.contains('///')) { | 90 var annotation = new _Annotation.from(line); |
| 91 var parts = line.split('///')[1].split(':'); | 91 if (annotation != null) { |
| 92 var key = parts[0].trim(); | 92 testsAsLines.putIfAbsent(annotation.key, |
| 93 var rest = parts[1].trim(); | 93 () => new List<String>.from(testTemplate)).add(line); |
| 94 if (testsAsLines.containsKey(key)) { | 94 outcomes.putIfAbsent(annotation.key, |
| 95 Expect.equals('continued', rest); | 95 () => new Set<String>()); |
| 96 testsAsLines[key].add(line); | 96 if (annotation.rest == 'continued') { |
| 97 continue; | |
| 97 } else { | 98 } else { |
| 98 (testsAsLines[key] = new List<String>.from(testTemplate)).add(line); | 99 for (String nextOutcome in annotation.outcomesList) { |
| 99 List<String> outcomesList = rest.split(','); | |
| 100 for (String nextOutcome in outcomesList) { | |
| 101 nextOutcome = nextOutcome.trim(); | 100 nextOutcome = nextOutcome.trim(); |
| 102 outcomes.putIfAbsent(key, () => new Set<String>()).add(nextOutcome); | 101 outcomes[annotation.key].add(nextOutcome); |
| 103 if (!validMultitestOutcomes.contains(nextOutcome)) { | 102 if (!validMultitestOutcomes.contains(nextOutcome)) { |
| 104 Expect.fail( | 103 Expect.fail( |
| 105 "Invalid test directive '$nextOutcome' on line ${lineCount}: $rest "); | 104 "Invalid test directive '$nextOutcome' on line ${lineCount}: ${ann otation.rest} "); |
|
Bill Hesse
2012/03/12 16:02:49
Line too long?
I think they have put concatenation
zundel
2012/03/12 20:06:23
Looks like we need to update the dart executable t
| |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 } | 107 } |
| 109 } else { | 108 } else { |
| 110 testTemplate.add(line); | 109 testTemplate.add(line); |
| 111 for (var test in testsAsLines.getValues()) test.add(line); | 110 for (var test in testsAsLines.getValues()) test.add(line); |
| 112 } | 111 } |
| 113 } | 112 } |
| 113 | |
| 114 // Check that every key (other than the none case) has at least one outcome | |
| 115 for (var outcomeKey in outcomes.getKeys()) { | |
| 116 if (outcomeKey == "none") { | |
| 117 continue; | |
| 118 } | |
| 119 if (outcomes[outcomeKey].isEmpty()) { | |
|
Bill Hesse
2012/03/12 16:02:49
Why not: if outcomeKey != 'none' && outcomes[outco
zundel
2012/03/12 20:06:23
Done.
| |
| 120 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes. Expected one of: ${validMultitestOutcomes.toString()}"); | |
|
Bill Hesse
2012/03/12 16:02:49
Long line.
| |
| 121 } | |
| 122 } | |
| 123 | |
| 114 // Add the template, with no multitest lines, as a test with key 'none'. | 124 // Add the template, with no multitest lines, as a test with key 'none'. |
| 115 testsAsLines['none'] = testTemplate; | 125 testsAsLines['none'] = testTemplate; |
| 116 outcomes['none'] = new Set<String>(); | 126 outcomes['none'] = new Set<String>(); |
| 117 | 127 |
| 118 // Copy all the tests into the output map tests, as multiline strings. | 128 // Copy all the tests into the output map tests, as multiline strings. |
| 119 for (String key in testsAsLines.getKeys()) { | 129 for (String key in testsAsLines.getKeys()) { |
| 120 tests[key] = | 130 tests[key] = |
| 121 Strings.join(testsAsLines[key], line_separator) + line_separator; | 131 Strings.join(testsAsLines[key], line_separator) + line_separator; |
| 122 } | 132 } |
| 123 } | 133 } |
| 124 | 134 |
| 135 // Represents a mutlitest annotation in the special /// comment. | |
| 136 class _Annotation { | |
| 137 String key; | |
| 138 String rest; | |
| 139 List<String> outcomesList; | |
| 140 _Annotation() {} | |
| 141 factory _Annotation.from(String line) { | |
| 142 if (!line.contains('///')) { | |
| 143 return null; | |
| 144 } | |
| 145 var annotation = new _Annotation(); | |
| 146 var parts = line.split('///')[1].split(':'); | |
| 147 annotation.key = parts[0].trim(); | |
| 148 annotation.rest = parts[1].trim(); | |
| 149 annotation.outcomesList = annotation.rest.split(','); | |
|
Bill Hesse
2012/03/12 16:02:49
annotation.outcomesList = annotation.rest.split(',
| |
| 150 return annotation; | |
| 151 } | |
| 152 } | |
| 153 | |
| 125 // Find all relative imports and copy them into the dir that contains | 154 // Find all relative imports and copy them into the dir that contains |
| 126 // the generated tests. | 155 // the generated tests. |
| 127 Set<String> _findAllRelativeImports(String topLibrary) { | 156 Set<String> _findAllRelativeImports(String topLibrary) { |
| 128 Set<String> toSearch = new Set<String>.from([topLibrary]); | 157 Set<String> toSearch = new Set<String>.from([topLibrary]); |
| 129 Set<String> foundImports = new HashSet<String>(); | 158 Set<String> foundImports = new HashSet<String>(); |
| 130 String pathSep = new Platform().pathSeparator(); | 159 String pathSep = new Platform().pathSeparator(); |
| 131 int end = topLibrary.lastIndexOf(pathSep); | 160 int end = topLibrary.lastIndexOf(pathSep); |
| 132 String libraryDir = topLibrary.substring(0, end); | 161 String libraryDir = topLibrary.substring(0, end); |
| 133 | 162 |
| 134 // Matches #import( or #source( followed by " or ' followed by anything | 163 // Matches #import( or #source( followed by " or ' followed by anything |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 var split = testDir.split('/'); | 266 var split = testDir.split('/'); |
| 238 var lastComponent = split.removeLast(); | 267 var lastComponent = split.removeLast(); |
| 239 Expect.isTrue(lastComponent == 'src'); | 268 Expect.isTrue(lastComponent == 'src'); |
| 240 String path = '${generatedTestDir.path}/${split.last()}'; | 269 String path = '${generatedTestDir.path}/${split.last()}'; |
| 241 Directory dir = new Directory(path); | 270 Directory dir = new Directory(path); |
| 242 if (!dir.existsSync()) { | 271 if (!dir.existsSync()) { |
| 243 dir.createSync(); | 272 dir.createSync(); |
| 244 } | 273 } |
| 245 return path; | 274 return path; |
| 246 } | 275 } |
| OLD | NEW |