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: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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } | 181 } |
| 182 foundImports.add(relativePath); | 182 foundImports.add(relativePath); |
| 183 toSearch.add(libraryDir.join(relativePath)); | 183 toSearch.add(libraryDir.join(relativePath)); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 return foundImports; | 188 return foundImports; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void DoMultitest(Path filePath, | 191 Future doMultitest(Path filePath, String outputDir, Path suiteDir, |
| 192 String outputDir, | 192 CreateTest doTest) { |
| 193 Path suiteDir, | |
| 194 CreateTest doTest, | |
| 195 VoidFunction multitestDone) { | |
| 196 // Each new test is a single String value in the Map tests. | 193 // Each new test is a single String value in the Map tests. |
| 197 Map<String, String> tests = new Map<String, String>(); | 194 Map<String, String> tests = new Map<String, String>(); |
| 198 Map<String, Set<String>> outcomes = new Map<String, Set<String>>(); | 195 Map<String, Set<String>> outcomes = new Map<String, Set<String>>(); |
| 199 ExtractTestsFromMultitest(filePath, tests, outcomes); | 196 ExtractTestsFromMultitest(filePath, tests, outcomes); |
| 200 | 197 |
| 201 Path sourceDir = filePath.directoryPath; | 198 Path sourceDir = filePath.directoryPath; |
| 202 Path targetDir = CreateMultitestDirectory(outputDir, suiteDir); | 199 Path targetDir = CreateMultitestDirectory(outputDir, suiteDir); |
| 203 Expect.isNotNull(targetDir); | 200 Expect.isNotNull(targetDir); |
| 204 | 201 |
| 205 // Copy all the relative imports of the multitest. | 202 // Copy all the relative imports of the multitest. |
| 206 Set<Path> importsToCopy = _findAllRelativeImports(filePath); | 203 Set<Path> importsToCopy = _findAllRelativeImports(filePath); |
| 207 List<Future> futureCopies = []; | 204 List<Future> futureCopies = []; |
| 208 for (Path importPath in importsToCopy) { | 205 for (Path importPath in importsToCopy) { |
| 209 // Make sure the target directory exists. | 206 // Make sure the target directory exists. |
| 210 Path importDir = importPath.directoryPath; | 207 Path importDir = importPath.directoryPath; |
| 211 if (!importDir.isEmpty) { | 208 if (!importDir.isEmpty) { |
| 212 TestUtils.mkdirRecursive(targetDir, importDir); | 209 TestUtils.mkdirRecursive(targetDir, importDir); |
| 213 } | 210 } |
| 214 // Copy file. | 211 // Copy file. |
| 215 futureCopies.add(TestUtils.copyFile(sourceDir.join(importPath), | 212 futureCopies.add(TestUtils.copyFile(sourceDir.join(importPath), |
| 216 targetDir.join(importPath))); | 213 targetDir.join(importPath))); |
| 217 } | 214 } |
| 218 | 215 |
| 219 // Wait until all imports are copied before scheduling test cases. | 216 // Wait until all imports are copied before scheduling test cases. |
| 220 Futures.wait(futureCopies).then((ignored) { | 217 return Futures.wait(futureCopies).transform((_) { |
| 221 String baseFilename = filePath.filenameWithoutExtension; | 218 String baseFilename = filePath.filenameWithoutExtension; |
| 222 for (String key in tests.keys) { | 219 for (String key in tests.keys) { |
| 223 final Path multitestFilename = | 220 final Path multitestFilename = |
| 224 targetDir.append('${baseFilename}_$key.dart'); | 221 targetDir.append('${baseFilename}_$key.dart'); |
| 225 final File file = new File.fromPath(multitestFilename); | 222 final File file = new File.fromPath(multitestFilename); |
| 226 | 223 |
| 227 file.createSync(); | 224 file.createSync(); |
| 228 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); | 225 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); |
| 229 var bytes = tests[key].charCodes; | 226 var bytes = tests[key].charCodes; |
| 230 openedFile.writeListSync(bytes, 0, bytes.length); | 227 openedFile.writeListSync(bytes, 0, bytes.length); |
| 231 openedFile.closeSync(); | 228 openedFile.closeSync(); |
| 232 Set<String> outcome = outcomes[key]; | 229 Set<String> outcome = outcomes[key]; |
| 233 bool enableFatalTypeErrors = outcome.contains('static type warning'); | 230 bool enableFatalTypeErrors = outcome.contains('static type warning'); |
| 234 bool hasRuntimeErrors = outcome.contains('runtime error'); | 231 bool hasRuntimeErrors = outcome.contains('runtime error'); |
| 235 bool hasCompileError = outcome.contains('compile-time error'); | 232 bool hasCompileError = outcome.contains('compile-time error'); |
| 236 bool isNegativeIfChecked = outcome.contains('dynamic type error'); | 233 bool isNegativeIfChecked = outcome.contains('dynamic type error'); |
| 237 doTest(multitestFilename, | 234 doTest(multitestFilename, |
| 238 hasCompileError, | 235 hasCompileError, |
| 239 hasRuntimeErrors, | 236 hasRuntimeErrors, |
| 240 isNegativeIfChecked: isNegativeIfChecked, | 237 isNegativeIfChecked: isNegativeIfChecked, |
| 241 hasFatalTypeErrors: enableFatalTypeErrors, | 238 hasFatalTypeErrors: enableFatalTypeErrors, |
| 242 multitestOutcome: outcome); | 239 multitestOutcome: outcome); |
| 243 } | 240 } |
| 244 multitestDone(); | 241 |
| 242 return null; | |
|
Emily Fortuna
2012/11/09 01:41:44
shouldn't we get rid of these lines if we're retur
Bob Nystrom
2012/11/09 20:56:26
This code's a bit hard to read. So the return here
Emily Fortuna
2012/11/09 21:03:14
Oh, I see. And I apparently misread the indentatio
| |
| 245 }); | 243 }); |
| 246 } | 244 } |
| 247 | 245 |
| 248 | 246 |
| 249 Path CreateMultitestDirectory(String outputDir, Path suiteDir) { | 247 Path CreateMultitestDirectory(String outputDir, Path suiteDir) { |
| 250 final String generatedTestDirectory = 'generated_tests'; | 248 final String generatedTestDirectory = 'generated_tests'; |
| 251 Directory generatedTestDir = new Directory('$outputDir/generated_tests'); | 249 Directory generatedTestDir = new Directory('$outputDir/generated_tests'); |
| 252 if (!new Directory(outputDir).existsSync()) { | 250 if (!new Directory(outputDir).existsSync()) { |
| 253 new Directory(outputDir).createSync(); | 251 new Directory(outputDir).createSync(); |
| 254 } | 252 } |
| 255 if (!generatedTestDir.existsSync()) { | 253 if (!generatedTestDir.existsSync()) { |
| 256 generatedTestDir.createSync(); | 254 generatedTestDir.createSync(); |
| 257 } | 255 } |
| 258 var split = suiteDir.segments(); | 256 var split = suiteDir.segments(); |
| 259 if (split.last == 'src') { | 257 if (split.last == 'src') { |
| 260 // TODO(sigmund): remove this once all tests are migrated to use | 258 // TODO(sigmund): remove this once all tests are migrated to use |
| 261 // TestSuite.forDirectory. | 259 // TestSuite.forDirectory. |
| 262 split.removeLast(); | 260 split.removeLast(); |
| 263 } | 261 } |
| 264 String path = '${generatedTestDir.path}/${split.last}'; | 262 String path = '${generatedTestDir.path}/${split.last}'; |
| 265 Directory dir = new Directory(path); | 263 Directory dir = new Directory(path); |
| 266 if (!dir.existsSync()) { | 264 if (!dir.existsSync()) { |
| 267 dir.createSync(); | 265 dir.createSync(); |
| 268 } | 266 } |
| 269 return new Path.fromNative(new File(path).fullPathSync()); | 267 return new Path.fromNative(new File(path).fullPathSync()); |
| 270 } | 268 } |
| OLD | NEW |