| 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 /** | 5 /** |
| 6 * Classes and methods for enumerating and preparing tests. | 6 * Classes and methods for enumerating and preparing tests. |
| 7 * | 7 * |
| 8 * This library includes: | 8 * This library includes: |
| 9 * | 9 * |
| 10 * - Creating tests by listing all the Dart files in certain directories, | 10 * - Creating tests by listing all the Dart files in certain directories, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 RuntimeConfiguration; | 32 RuntimeConfiguration; |
| 33 | 33 |
| 34 part "browser_test.dart"; | 34 part "browser_test.dart"; |
| 35 | 35 |
| 36 | 36 |
| 37 RegExp multiHtmlTestGroupRegExp = new RegExp(r"\s*[^/]\s*group\('[^,']*"); | 37 RegExp multiHtmlTestGroupRegExp = new RegExp(r"\s*[^/]\s*group\('[^,']*"); |
| 38 RegExp multiHtmlTestRegExp = new RegExp(r"useHtmlIndividualConfiguration()"); | 38 RegExp multiHtmlTestRegExp = new RegExp(r"useHtmlIndividualConfiguration()"); |
| 39 // Require at least one non-space character before '///' | 39 // Require at least one non-space character before '///' |
| 40 RegExp multiTestRegExp = new RegExp(r"\S *" | 40 RegExp multiTestRegExp = new RegExp(r"\S *" |
| 41 r"/// \w+:(.*)"); | 41 r"/// \w+:(.*)"); |
| 42 RegExp dartExtension = new RegExp(r'\.dart$'); |
| 42 | 43 |
| 43 /** | 44 /** |
| 44 * A simple function that tests [arg] and returns `true` or `false`. | 45 * A simple function that tests [arg] and returns `true` or `false`. |
| 45 */ | 46 */ |
| 46 typedef bool Predicate<T>(T arg); | 47 typedef bool Predicate<T>(T arg); |
| 47 | 48 |
| 48 typedef void CreateTest(Path filePath, | 49 typedef void CreateTest(Path filePath, |
| 49 Path originTestPath, | 50 Path originTestPath, |
| 50 bool hasCompileError, | 51 bool hasCompileError, |
| 51 bool hasRuntimeError, | 52 bool hasRuntimeError, |
| (...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 htmlTest.closeSync(); | 1275 htmlTest.closeSync(); |
| 1275 } | 1276 } |
| 1276 | 1277 |
| 1277 if (compiler != 'none') { | 1278 if (compiler != 'none') { |
| 1278 commands.add( | 1279 commands.add( |
| 1279 _compileCommand( | 1280 _compileCommand( |
| 1280 dartWrapperFilename, | 1281 dartWrapperFilename, |
| 1281 compiledDartWrapperFilename, | 1282 compiledDartWrapperFilename, |
| 1282 compiler, | 1283 compiler, |
| 1283 tempDir, | 1284 tempDir, |
| 1284 vmOptions, | |
| 1285 optionsFromFile)); | 1285 optionsFromFile)); |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 // some tests require compiling multiple input scripts. | 1288 // some tests require compiling multiple input scripts. |
| 1289 List<String> otherScripts = optionsFromFile['otherScripts']; | 1289 List<String> otherScripts = optionsFromFile['otherScripts']; |
| 1290 for (String name in otherScripts) { | 1290 for (String name in otherScripts) { |
| 1291 Path namePath = new Path(name); | 1291 Path namePath = new Path(name); |
| 1292 String fileName = namePath.filename; | 1292 String fileName = namePath.filename; |
| 1293 Path fromPath = filePath.directoryPath.join(namePath); | 1293 Path fromPath = filePath.directoryPath.join(namePath); |
| 1294 if (compiler != 'none') { | 1294 if (compiler != 'none') { |
| 1295 assert(namePath.extension == 'dart'); | 1295 assert(namePath.extension == 'dart'); |
| 1296 commands.add( | 1296 commands.add( |
| 1297 _compileCommand( | 1297 _compileCommand( |
| 1298 fromPath.toNativePath(), | 1298 fromPath.toNativePath(), |
| 1299 '$tempDir/$fileName.js', | 1299 '$tempDir/$fileName.js', |
| 1300 compiler, | 1300 compiler, |
| 1301 tempDir, | 1301 tempDir, |
| 1302 vmOptions, | |
| 1303 optionsFromFile)); | 1302 optionsFromFile)); |
| 1304 } | 1303 } |
| 1305 if (compiler == 'none') { | 1304 if (compiler == 'none') { |
| 1306 // For the tests that require multiple input scripts but are not | 1305 // For the tests that require multiple input scripts but are not |
| 1307 // compiled, move the input scripts over with the script so they can | 1306 // compiled, move the input scripts over with the script so they can |
| 1308 // be accessed. | 1307 // be accessed. |
| 1309 String result = new File(fromPath.toNativePath()).readAsStringSync(); | 1308 String result = new File(fromPath.toNativePath()).readAsStringSync(); |
| 1310 new File('$tempDir/$fileName').writeAsStringSync(result); | 1309 new File('$tempDir/$fileName').writeAsStringSync(result); |
| 1311 } | 1310 } |
| 1312 } | 1311 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 void enqueueHtmlTest( | 1375 void enqueueHtmlTest( |
| 1377 HtmlTestInformation info, | 1376 HtmlTestInformation info, |
| 1378 String testName, | 1377 String testName, |
| 1379 expectations) { | 1378 expectations) { |
| 1380 final String compiler = configuration['compiler']; | 1379 final String compiler = configuration['compiler']; |
| 1381 final String runtime = configuration['runtime']; | 1380 final String runtime = configuration['runtime']; |
| 1382 // Html tests work only with the browser controller. | 1381 // Html tests work only with the browser controller. |
| 1383 if (!TestUtils.isBrowserRuntime(runtime) || runtime == 'drt') { | 1382 if (!TestUtils.isBrowserRuntime(runtime) || runtime == 'drt') { |
| 1384 return; | 1383 return; |
| 1385 } | 1384 } |
| 1385 bool compileToJS = (compiler == 'dart2js'); |
| 1386 | 1386 |
| 1387 final Path filePath = info.filePath; | 1387 final Path filePath = info.filePath; |
| 1388 final String tempDir = createOutputDirectory(filePath, ''); | 1388 final String tempDir = createOutputDirectory(filePath, ''); |
| 1389 final Uri tempUri = new Uri.file('$tempDir/'); | 1389 final Uri tempUri = new Uri.file('$tempDir/'); |
| 1390 String contents = htmlTest.getContents(info); | 1390 String contents = htmlTest.getContents(info, compileToJS); |
| 1391 final commands = []; |
| 1391 | 1392 |
| 1392 void Fail(String message) { | 1393 void Fail(String message) { |
| 1393 var msg = "$message: ${info.filePath}"; | 1394 var msg = "$message: ${info.filePath}"; |
| 1394 DebugLogger.warning(msg); | 1395 DebugLogger.warning(msg); |
| 1395 contents = htmlTest.makeFailingHtmlFile(msg); | 1396 contents = htmlTest.makeFailingHtmlFile(msg); |
| 1396 } | 1397 } |
| 1397 | 1398 |
| 1398 if (info.scripts.length > 0) { | 1399 if (info.scripts.length > 0) { |
| 1399 Uri testUri = new Uri.file(filePath.toNativePath()); | 1400 Uri testUri = new Uri.file(filePath.toNativePath()); |
| 1400 for (String scriptPath in info.scripts) { | 1401 for (String scriptPath in info.scripts) { |
| 1401 if (!scriptPath.endsWith('.dart') && !scriptPath.endsWith('.js')) { | 1402 if (!scriptPath.endsWith('.dart') && !scriptPath.endsWith('.js')) { |
| 1402 Fail('HTML test scripts must be dart or javascript: $scriptPath'); | 1403 Fail('HTML test scripts must be dart or javascript: $scriptPath'); |
| 1403 break; | 1404 break; |
| 1404 } | 1405 } |
| 1405 Uri uri = Uri.parse(scriptPath); | 1406 Uri uri = Uri.parse(scriptPath); |
| 1406 if (uri.isAbsolute) { | 1407 if (uri.isAbsolute) { |
| 1407 Fail('HTML test scripts must have relative paths: $scriptPath'); | 1408 Fail('HTML test scripts must have relative paths: $scriptPath'); |
| 1408 break; | 1409 break; |
| 1409 } | 1410 } |
| 1410 if (uri.pathSegments.length > 1) { | 1411 if (uri.pathSegments.length > 1) { |
| 1411 Fail('HTML test scripts must be in test directory: $scriptPath'); | 1412 Fail('HTML test scripts must be in test directory: $scriptPath'); |
| 1412 break; | 1413 break; |
| 1413 } | 1414 } |
| 1414 Uri script = testUri.resolveUri(uri); | 1415 Uri script = testUri.resolveUri(uri); |
| 1416 Uri copiedScript = tempUri.resolveUri(uri); |
| 1415 if (compiler == 'none' || scriptPath.endsWith('.js')) { | 1417 if (compiler == 'none' || scriptPath.endsWith('.js')) { |
| 1416 Uri copiedScript = tempUri.resolveUri(uri); | |
| 1417 new File.fromUri(copiedScript).writeAsStringSync( | 1418 new File.fromUri(copiedScript).writeAsStringSync( |
| 1418 new File.fromUri(script).readAsStringSync()); | 1419 new File.fromUri(script).readAsStringSync()); |
| 1419 } else { | 1420 } else { |
| 1420 // TODO(21514): Compile scripts into output directory. | 1421 commands.add(_compileCommand( |
| 1421 Fail('HTML test scripts don\'t support dart2js yet'); | 1422 script.toFilePath(), |
| 1422 break; | 1423 copiedScript.toFilePath().replaceFirst(dartExtension, '.js'), |
| 1424 compiler, |
| 1425 tempDir, |
| 1426 info.optionsFromFile)); |
| 1423 } | 1427 } |
| 1424 } | 1428 } |
| 1425 } | 1429 } |
| 1426 final Uri htmlFile = tempUri.resolve(filePath.filename); | 1430 final Uri htmlFile = tempUri.resolve(filePath.filename); |
| 1427 new File.fromUri(htmlFile).writeAsStringSync(contents); | 1431 new File.fromUri(htmlFile).writeAsStringSync(contents); |
| 1428 | 1432 |
| 1429 var htmlPath = _createUrlPathFromFile(new Path(htmlFile.toFilePath())); | 1433 var htmlPath = _createUrlPathFromFile(new Path(htmlFile.toFilePath())); |
| 1430 var fullHtmlPath = _getUriForBrowserTest(htmlPath, null).toString(); | 1434 var fullHtmlPath = _getUriForBrowserTest(htmlPath, null).toString(); |
| 1431 var commands = [ | 1435 commands.add(CommandBuilder.instance.getBrowserHtmlTestCommand( |
| 1432 CommandBuilder.instance.getBrowserHtmlTestCommand( | 1436 runtime, |
| 1433 runtime, | 1437 fullHtmlPath, |
| 1434 fullHtmlPath, | 1438 configuration, |
| 1435 configuration, | 1439 info.expectedMessages)); |
| 1436 info.expectedMessages)]; | |
| 1437 String testDisplayName = '$suiteName/$testName'; | 1440 String testDisplayName = '$suiteName/$testName'; |
| 1438 var testCase = new BrowserTestCase( | 1441 var testCase = new BrowserTestCase( |
| 1439 testDisplayName, | 1442 testDisplayName, |
| 1440 commands, | 1443 commands, |
| 1441 configuration, | 1444 configuration, |
| 1442 expectations, | 1445 expectations, |
| 1443 info, | 1446 info, |
| 1444 isNegative(info), | 1447 isNegative(info), |
| 1445 fullHtmlPath); | 1448 fullHtmlPath); |
| 1446 enqueueNewTestCase(testCase); | 1449 enqueueNewTestCase(testCase); |
| 1447 return; | 1450 return; |
| 1448 } | 1451 } |
| 1449 | 1452 |
| 1450 /** Helper to create a compilation command for a single input file. */ | 1453 /** Helper to create a compilation command for a single input file. */ |
| 1451 Command _compileCommand(String inputFile, String outputFile, | 1454 Command _compileCommand(String inputFile, String outputFile, |
| 1452 String compiler, String dir, vmOptions, optionsFromFile) { | 1455 String compiler, String dir, optionsFromFile) { |
| 1453 assert (['dart2js', 'dart2dart'].contains(compiler)); | 1456 assert (['dart2js', 'dart2dart'].contains(compiler)); |
| 1454 String executable = compilerPath; | 1457 String executable; |
| 1455 List<String> args = TestUtils.standardOptions(configuration); | 1458 List<String> args; |
| 1459 if (compilerPath.endsWith('.dart')) { |
| 1460 // Run the compiler script via the Dart VM. |
| 1461 executable = dartVmBinaryFileName; |
| 1462 args = [compilerPath]; |
| 1463 } else { |
| 1464 executable = compilerPath; |
| 1465 args = []; |
| 1466 } |
| 1467 args.addAll(TestUtils.standardOptions(configuration)); |
| 1456 String packageRoot = | 1468 String packageRoot = |
| 1457 packageRootArgument(optionsFromFile['packageRoot']); | 1469 packageRootArgument(optionsFromFile['packageRoot']); |
| 1458 if (packageRoot != null) { | 1470 if (packageRoot != null) args.add(packageRoot); |
| 1459 args.add(packageRoot); | |
| 1460 } | |
| 1461 args.add('--out=$outputFile'); | 1471 args.add('--out=$outputFile'); |
| 1462 if (configuration['csp']) args.add('--csp'); | 1472 if (configuration['csp']) args.add('--csp'); |
| 1463 args.add(inputFile); | 1473 args.add(inputFile); |
| 1464 args.addAll(optionsFromFile['sharedOptions']); | 1474 List<String> options = optionsFromFile['sharedOptions']; |
| 1465 if (executable.endsWith('.dart')) { | 1475 if (options != null) args.addAll(options); |
| 1466 // Run the compiler script via the Dart VM. | |
| 1467 args.insert(0, executable); | |
| 1468 executable = dartVmBinaryFileName; | |
| 1469 } | |
| 1470 return CommandBuilder.instance.getCompilationCommand( | 1476 return CommandBuilder.instance.getCompilationCommand( |
| 1471 compiler, outputFile, !useSdk, | 1477 compiler, outputFile, !useSdk, |
| 1472 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides); | 1478 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides); |
| 1473 } | 1479 } |
| 1474 | 1480 |
| 1475 /** Helper to create a Polymer deploy command for a single HTML file. */ | 1481 /** Helper to create a Polymer deploy command for a single HTML file. */ |
| 1476 Command _polymerDeployCommand(String inputFile, String outputDir, | 1482 Command _polymerDeployCommand(String inputFile, String outputDir, |
| 1477 optionsFromFile) { | 1483 optionsFromFile) { |
| 1478 List<String> args = []; | 1484 List<String> args = []; |
| 1479 String packageRoot = packageRootArgument(optionsFromFile['packageRoot']); | 1485 String packageRoot = packageRootArgument(optionsFromFile['packageRoot']); |
| (...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2476 * $pass tests are expected to pass | 2482 * $pass tests are expected to pass |
| 2477 * $failOk tests are expected to fail that we won't fix | 2483 * $failOk tests are expected to fail that we won't fix |
| 2478 * $fail tests are expected to fail that we should fix | 2484 * $fail tests are expected to fail that we should fix |
| 2479 * $crash tests are expected to crash that we should fix | 2485 * $crash tests are expected to crash that we should fix |
| 2480 * $timeout tests are allowed to timeout | 2486 * $timeout tests are allowed to timeout |
| 2481 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 2487 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
| 2482 """; | 2488 """; |
| 2483 print(report); | 2489 print(report); |
| 2484 } | 2490 } |
| 2485 } | 2491 } |
| OLD | NEW |