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 import "test_suite.dart"; | 9 import "test_suite.dart"; |
10 import "utils.dart"; | 10 import "utils.dart"; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 testsAsLines.putIfAbsent(annotation.key, | 89 testsAsLines.putIfAbsent(annotation.key, |
90 () => new List<String>.from(testTemplate)).add(line); | 90 () => new List<String>.from(testTemplate)).add(line); |
91 outcomes.putIfAbsent(annotation.key, | 91 outcomes.putIfAbsent(annotation.key, |
92 () => new Set<String>()); | 92 () => new Set<String>()); |
93 if (annotation.rest == 'continued') { | 93 if (annotation.rest == 'continued') { |
94 continue; | 94 continue; |
95 } else { | 95 } else { |
96 for (String nextOutcome in annotation.outcomesList) { | 96 for (String nextOutcome in annotation.outcomesList) { |
97 outcomes[annotation.key].add(nextOutcome); | 97 outcomes[annotation.key].add(nextOutcome); |
98 if (!validMultitestOutcomes.contains(nextOutcome)) { | 98 if (!validMultitestOutcomes.contains(nextOutcome)) { |
99 Expect.fail( | 99 print( |
100 "Invalid test directive '$nextOutcome' on line ${lineCount}:\n" | 100 "Invalid test directive '$nextOutcome' on line ${lineCount}:\n" |
101 "${annotation.rest} "); | 101 "${annotation.rest} "); |
| 102 exit(1); |
102 } | 103 } |
103 } | 104 } |
104 } | 105 } |
105 } else { | 106 } else { |
106 testTemplate.add(line); | 107 testTemplate.add(line); |
107 for (var test in testsAsLines.values) test.add(line); | 108 for (var test in testsAsLines.values) test.add(line); |
108 } | 109 } |
109 } | 110 } |
110 | 111 |
111 // Check that every key (other than the none case) has at least one outcome | 112 // Check that every key (other than the none case) has at least one outcome |
112 for (var outcomeKey in outcomes.keys) { | 113 for (var outcomeKey in outcomes.keys) { |
113 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty) { | 114 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty) { |
114 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes.\n" | 115 print("Test ${outcomeKey} has no valid annotated outcomes.\n" |
115 "Expected one of: ${validMultitestOutcomes.toString()}"); | 116 "Expected one of: ${validMultitestOutcomes.toString()}"); |
| 117 exit(1); |
116 } | 118 } |
117 } | 119 } |
118 | 120 |
119 // Add the template, with no multitest lines, as a test with key 'none'. | 121 // Add the template, with no multitest lines, as a test with key 'none'. |
120 testsAsLines['none'] = testTemplate; | 122 testsAsLines['none'] = testTemplate; |
121 outcomes['none'] = new Set<String>(); | 123 outcomes['none'] = new Set<String>(); |
122 | 124 |
123 // Copy all the tests into the output map tests, as multiline strings. | 125 // Copy all the tests into the output map tests, as multiline strings. |
124 for (String key in testsAsLines.keys) { | 126 for (String key in testsAsLines.keys) { |
125 tests[key] = testsAsLines[key].join(line_separator).concat(line_separator); | 127 tests[key] = testsAsLines[key].join(line_separator).concat(line_separator); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 Match match = relativeImportRegExp.firstMatch(line); | 167 Match match = relativeImportRegExp.firstMatch(line); |
166 if (match != null) { | 168 if (match != null) { |
167 Path relativePath = new Path(match.group(3)); | 169 Path relativePath = new Path(match.group(3)); |
168 if (foundImports.contains(relativePath)) { | 170 if (foundImports.contains(relativePath)) { |
169 continue; | 171 continue; |
170 } | 172 } |
171 if (relativePath.toString().contains('..')) { | 173 if (relativePath.toString().contains('..')) { |
172 // This is just for safety reasons, we don't want | 174 // This is just for safety reasons, we don't want |
173 // to unintentionally clobber files relative to the destination | 175 // to unintentionally clobber files relative to the destination |
174 // dir when copying them ove. | 176 // dir when copying them ove. |
175 Expect.fail("relative paths containing .. are not allowed."); | 177 print("relative paths containing .. are not allowed."); |
| 178 exit(1); |
176 } | 179 } |
177 foundImports.add(relativePath); | 180 foundImports.add(relativePath); |
178 toSearch.add(libraryDir.join(relativePath)); | 181 toSearch.add(libraryDir.join(relativePath)); |
179 } | 182 } |
180 } | 183 } |
181 } | 184 } |
182 } | 185 } |
183 return foundImports; | 186 return foundImports; |
184 } | 187 } |
185 | 188 |
186 Future doMultitest(Path filePath, String outputDir, Path suiteDir, | 189 Future doMultitest(Path filePath, String outputDir, Path suiteDir, |
187 CreateTest doTest) { | 190 CreateTest doTest) { |
188 // Each new test is a single String value in the Map tests. | 191 // Each new test is a single String value in the Map tests. |
189 Map<String, String> tests = new Map<String, String>(); | 192 Map<String, String> tests = new Map<String, String>(); |
190 Map<String, Set<String>> outcomes = new Map<String, Set<String>>(); | 193 Map<String, Set<String>> outcomes = new Map<String, Set<String>>(); |
191 ExtractTestsFromMultitest(filePath, tests, outcomes); | 194 ExtractTestsFromMultitest(filePath, tests, outcomes); |
192 | 195 |
193 Path sourceDir = filePath.directoryPath; | 196 Path sourceDir = filePath.directoryPath; |
194 Path targetDir = CreateMultitestDirectory(outputDir, suiteDir); | 197 Path targetDir = CreateMultitestDirectory(outputDir, suiteDir); |
195 Expect.isNotNull(targetDir); | 198 assert(targetDir != null); |
196 | 199 |
197 // Copy all the relative imports of the multitest. | 200 // Copy all the relative imports of the multitest. |
198 Set<Path> importsToCopy = _findAllRelativeImports(filePath); | 201 Set<Path> importsToCopy = _findAllRelativeImports(filePath); |
199 List<Future> futureCopies = []; | 202 List<Future> futureCopies = []; |
200 for (Path importPath in importsToCopy) { | 203 for (Path importPath in importsToCopy) { |
201 // Make sure the target directory exists. | 204 // Make sure the target directory exists. |
202 Path importDir = importPath.directoryPath; | 205 Path importDir = importPath.directoryPath; |
203 if (!importDir.isEmpty) { | 206 if (!importDir.isEmpty) { |
204 TestUtils.mkdirRecursive(targetDir, importDir); | 207 TestUtils.mkdirRecursive(targetDir, importDir); |
205 } | 208 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // TestSuite.forDirectory. | 256 // TestSuite.forDirectory. |
254 split.removeLast(); | 257 split.removeLast(); |
255 } | 258 } |
256 String path = '${generatedTestDir.path}/${split.last}'; | 259 String path = '${generatedTestDir.path}/${split.last}'; |
257 Directory dir = new Directory(path); | 260 Directory dir = new Directory(path); |
258 if (!dir.existsSync()) { | 261 if (!dir.existsSync()) { |
259 dir.createSync(); | 262 dir.createSync(); |
260 } | 263 } |
261 return new Path(new File(path).fullPathSync()); | 264 return new Path(new File(path).fullPathSync()); |
262 } | 265 } |
OLD | NEW |