| 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, |
| 11 * and creating [TestCase]s for those files that meet the relevant criteria. | 11 * and creating [TestCase]s for those files that meet the relevant criteria. |
| 12 * - Preparing tests, including copying files and frameworks to temporary | 12 * - Preparing tests, including copying files and frameworks to temporary |
| 13 * directories, and computing the command line and arguments to be run. | 13 * directories, and computing the command line and arguments to be run. |
| 14 */ | 14 */ |
| 15 #library("test_suite"); | 15 #library("test_suite"); |
| 16 | 16 |
| 17 #import("dart:io"); | 17 #import("dart:io"); |
| 18 #import("dart:isolate"); | 18 #import("dart:isolate"); |
| 19 #import("status_file_parser.dart"); | 19 #import("status_file_parser.dart"); |
| 20 #import("test_runner.dart"); | 20 #import("test_runner.dart"); |
| 21 #import("multitest.dart"); | 21 #import("multitest.dart"); |
| 22 #import("drt_updater.dart"); | 22 #import("drt_updater.dart"); |
| 23 #import("dart:uri"); |
| 23 | 24 |
| 24 #source("browser_test.dart"); | 25 #source("browser_test.dart"); |
| 25 | 26 |
| 26 | 27 |
| 27 // TODO(rnystrom): Add to dart:core? | 28 // TODO(rnystrom): Add to dart:core? |
| 28 /** | 29 /** |
| 29 * A simple function that tests [arg] and returns `true` or `false`. | 30 * A simple function that tests [arg] and returns `true` or `false`. |
| 30 */ | 31 */ |
| 31 typedef bool Predicate<T>(T arg); | 32 typedef bool Predicate<T>(T arg); |
| 32 | 33 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 Map configuration, Path directory) { | 437 Map configuration, Path directory) { |
| 437 final name = directory.filename; | 438 final name = directory.filename; |
| 438 | 439 |
| 439 return new StandardTestSuite(configuration, | 440 return new StandardTestSuite(configuration, |
| 440 name, directory, | 441 name, directory, |
| 441 ['$directory/$name.status', '$directory/${name}_dart2js.status'], | 442 ['$directory/$name.status', '$directory/${name}_dart2js.status'], |
| 442 isTestFilePredicate: (filename) => filename.endsWith('_test.dart'), | 443 isTestFilePredicate: (filename) => filename.endsWith('_test.dart'), |
| 443 recursive: true); | 444 recursive: true); |
| 444 } | 445 } |
| 445 | 446 |
| 447 Collection<Uri> get dart2JsBootstrapDependencies { |
| 448 if (!useDart2JsFromSdk) return []; |
| 449 |
| 450 var snapshotPath = TestUtils.absolutePath(new Path(buildDir).join( |
| 451 new Path('dart-sdk/lib/_internal/compiler/' |
| 452 'implementation/dart2js.dart.snapshot'))).toString(); |
| 453 return [new Uri.fromComponents(scheme: 'file', path: snapshotPath)]; |
| 454 } |
| 455 |
| 456 bool get useDart2JsFromSdk { |
| 457 return configuration['use_sdk']; |
| 458 } |
| 459 |
| 446 /** | 460 /** |
| 447 * The default implementation assumes a file is a test if | 461 * The default implementation assumes a file is a test if |
| 448 * it ends in "Test.dart". | 462 * it ends in "Test.dart". |
| 449 */ | 463 */ |
| 450 bool isTestFile(String filename) { | 464 bool isTestFile(String filename) { |
| 451 // Use the specified predicate, if provided. | 465 // Use the specified predicate, if provided. |
| 452 if (isTestFilePredicate != null) return isTestFilePredicate(filename); | 466 if (isTestFilePredicate != null) return isTestFilePredicate(filename); |
| 453 | 467 |
| 454 return filename.endsWith("Test.dart"); | 468 return filename.endsWith("Test.dart"); |
| 455 } | 469 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 info: info)); | 705 info: info)); |
| 692 } | 706 } |
| 693 } | 707 } |
| 694 | 708 |
| 695 List<Command> makeCommands(TestInformation info, var vmOptions, var args) { | 709 List<Command> makeCommands(TestInformation info, var vmOptions, var args) { |
| 696 switch (configuration['compiler']) { | 710 switch (configuration['compiler']) { |
| 697 case 'dart2js': | 711 case 'dart2js': |
| 698 args = new List.from(args); | 712 args = new List.from(args); |
| 699 String tempDir = createOutputDirectory(info.filePath, ''); | 713 String tempDir = createOutputDirectory(info.filePath, ''); |
| 700 args.add('--out=$tempDir/out.js'); | 714 args.add('--out=$tempDir/out.js'); |
| 701 List<Command> commands = <Command>[new Command(dartShellFileName, args)]; | 715 List<Command> commands = |
| 716 <Command>[new Dart2JsCommand("$tempDir/out.js", |
| 717 !useDart2JsFromSdk, |
| 718 dart2JsBootstrapDependencies, |
| 719 dartShellFileName, |
| 720 args)]; |
| 702 if (info.hasCompileError) { | 721 if (info.hasCompileError) { |
| 703 // Do not attempt to run the compiled result. A compilation | 722 // Do not attempt to run the compiled result. A compilation |
| 704 // error should be reported by the compilation command. | 723 // error should be reported by the compilation command. |
| 705 } else if (configuration['runtime'] == 'd8') { | 724 } else if (configuration['runtime'] == 'd8') { |
| 706 commands.add(new Command(d8FileName, ['$tempDir/out.js'])); | 725 commands.add(new Command(d8FileName, ['$tempDir/out.js'])); |
| 707 } else if (configuration['runtime'] == 'jsshell') { | 726 } else if (configuration['runtime'] == 'jsshell') { |
| 708 commands.add(new Command(jsShellFileName, ['$tempDir/out.js'])); | 727 commands.add(new Command(jsShellFileName, ['$tempDir/out.js'])); |
| 709 } | 728 } |
| 710 return commands; | 729 return commands; |
| 711 | 730 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 args.add(inputFile); | 1011 args.add(inputFile); |
| 993 break; | 1012 break; |
| 994 default: | 1013 default: |
| 995 Expect.fail('unimplemented compiler $compiler'); | 1014 Expect.fail('unimplemented compiler $compiler'); |
| 996 } | 1015 } |
| 997 if (executable.endsWith('.dart')) { | 1016 if (executable.endsWith('.dart')) { |
| 998 // Run the compiler script via the Dart VM. | 1017 // Run the compiler script via the Dart VM. |
| 999 args.insertRange(0, 1, executable); | 1018 args.insertRange(0, 1, executable); |
| 1000 executable = dartShellFileName; | 1019 executable = dartShellFileName; |
| 1001 } | 1020 } |
| 1021 if (configuration['compiler'] == 'dart2js') { |
| 1022 return new Dart2JsCommand(outputFile, |
| 1023 !useDart2JsFromSdk, |
| 1024 dart2JsBootstrapDependencies, |
| 1025 dartShellFileName, |
| 1026 args); |
| 1027 } |
| 1002 return new Command(executable, args); | 1028 return new Command(executable, args); |
| 1003 } | 1029 } |
| 1004 | 1030 |
| 1005 /** | 1031 /** |
| 1006 * Create a directory for the generated test. If a Dart language test | 1032 * Create a directory for the generated test. If a Dart language test |
| 1007 * needs to be run in a browser, the Dart test needs to be embedded in | 1033 * needs to be run in a browser, the Dart test needs to be embedded in |
| 1008 * an HTML page, with a testing framework based on scripting and DOM events. | 1034 * an HTML page, with a testing framework based on scripting and DOM events. |
| 1009 * These scripts and pages are written to a generated_test directory | 1035 * These scripts and pages are written to a generated_test directory |
| 1010 * inside the build directory of the checkout. | 1036 * inside the build directory of the checkout. |
| 1011 * | 1037 * |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 '$dartDir/third_party/rhino/1_7R3/js.jar', | 1479 '$dartDir/third_party/rhino/1_7R3/js.jar', |
| 1454 '$dartDir/third_party/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar', | 1480 '$dartDir/third_party/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar', |
| 1455 '$dartDir/third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar', | 1481 '$dartDir/third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar', |
| 1456 '$dartDir/third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar', | 1482 '$dartDir/third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar', |
| 1457 '$dartDir/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar', | 1483 '$dartDir/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar', |
| 1458 '$dartDir/third_party/junit/v4_8_2/junit.jar'], | 1484 '$dartDir/third_party/junit/v4_8_2/junit.jar'], |
| 1459 Platform.operatingSystem == 'windows'? ';': ':'); // Path separator. | 1485 Platform.operatingSystem == 'windows'? ';': ':'); // Path separator. |
| 1460 } | 1486 } |
| 1461 } | 1487 } |
| 1462 | 1488 |
| 1489 class LastModifiedCache { |
| 1490 Map<String, Date> _cache = <String, Date>{}; |
| 1491 |
| 1492 /** |
| 1493 * Returns the last modified date of the given [uri]. |
| 1494 * |
| 1495 * The return value will be cached for future queries. If [uri] is a local |
| 1496 * file, it's last modified [Date] will be returned. If the file does not |
| 1497 * exist, null will be returned instead. |
| 1498 * In case [uri] is not a local file, this method will always return |
| 1499 * the current date. |
| 1500 */ |
| 1501 Date getLastModified(Uri uri) { |
| 1502 if (uri.scheme == "file") { |
| 1503 if (_cache.containsKey(uri.path)) { |
| 1504 return _cache[uri.path]; |
| 1505 } |
| 1506 var file = new File(uri.path); |
| 1507 _cache[uri.path] = file.existsSync() ? file.lastModifiedSync() : null; |
| 1508 return _cache[uri.path]; |
| 1509 } |
| 1510 return new Date.now(); |
| 1511 } |
| 1512 } |
| 1513 |
| 1463 class TestUtils { | 1514 class TestUtils { |
| 1464 /** | 1515 /** |
| 1465 * The libraries in this directory relies on finding various files | 1516 * The libraries in this directory relies on finding various files |
| 1466 * relative to the 'test.dart' script in '.../dart/tools/test.dart'. If | 1517 * relative to the 'test.dart' script in '.../dart/tools/test.dart'. If |
| 1467 * the main script using 'test_suite.dart' is not there, the main | 1518 * the main script using 'test_suite.dart' is not there, the main |
| 1468 * script must set this to '.../dart/tools/test.dart'. | 1519 * script must set this to '.../dart/tools/test.dart'. |
| 1469 */ | 1520 */ |
| 1470 static String testScriptPath = new Options().script; | 1521 static String testScriptPath = new Options().script; |
| 1471 | 1522 static LastModifiedCache lastModifiedCache = new LastModifiedCache(); |
| 1523 static Path currentWorkingDirectory = new Path(new Directory.current().path); |
| 1472 /** | 1524 /** |
| 1473 * Creates a directory using a [relativePath] to an existing | 1525 * Creates a directory using a [relativePath] to an existing |
| 1474 * [base] directory if that [relativePath] does not already exist. | 1526 * [base] directory if that [relativePath] does not already exist. |
| 1475 */ | 1527 */ |
| 1476 static Directory mkdirRecursive(Path base, Path relativePath) { | 1528 static Directory mkdirRecursive(Path base, Path relativePath) { |
| 1477 Directory dir = new Directory.fromPath(base); | 1529 Directory dir = new Directory.fromPath(base); |
| 1478 Expect.isTrue(dir.existsSync(), | 1530 Expect.isTrue(dir.existsSync(), |
| 1479 "Expected ${dir} to already exist"); | 1531 "Expected ${dir} to already exist"); |
| 1480 var segments = relativePath.segments(); | 1532 var segments = relativePath.segments(); |
| 1481 for (String segment in segments) { | 1533 for (String segment in segments) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1509 // waterfall UI. | 1561 // waterfall UI. |
| 1510 return ".flaky.log"; | 1562 return ".flaky.log"; |
| 1511 } | 1563 } |
| 1512 | 1564 |
| 1513 static void ensureExists(String filename, Map configuration) { | 1565 static void ensureExists(String filename, Map configuration) { |
| 1514 if (!configuration['list'] && !(new File(filename).existsSync())) { | 1566 if (!configuration['list'] && !(new File(filename).existsSync())) { |
| 1515 throw "Executable '$filename' does not exist"; | 1567 throw "Executable '$filename' does not exist"; |
| 1516 } | 1568 } |
| 1517 } | 1569 } |
| 1518 | 1570 |
| 1571 static Path absolutePath(Path path) { |
| 1572 if (!path.isAbsolute) { |
| 1573 return currentWorkingDirectory.join(path); |
| 1574 } |
| 1575 return path; |
| 1576 } |
| 1577 |
| 1519 static String outputDir(Map configuration) { | 1578 static String outputDir(Map configuration) { |
| 1520 var result = ''; | 1579 var result = ''; |
| 1521 var system = configuration['system']; | 1580 var system = configuration['system']; |
| 1522 if (system == 'linux') { | 1581 if (system == 'linux') { |
| 1523 result = 'out/'; | 1582 result = 'out/'; |
| 1524 } else if (system == 'macos') { | 1583 } else if (system == 'macos') { |
| 1525 result = 'xcodebuild/'; | 1584 result = 'xcodebuild/'; |
| 1526 } else if (system == 'windows') { | 1585 } else if (system == 'windows') { |
| 1527 result = 'build/'; | 1586 result = 'build/'; |
| 1528 } | 1587 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 * $pass tests are expected to pass | 1691 * $pass tests are expected to pass |
| 1633 * $failOk tests are expected to fail that we won't fix | 1692 * $failOk tests are expected to fail that we won't fix |
| 1634 * $fail tests are expected to fail that we should fix | 1693 * $fail tests are expected to fail that we should fix |
| 1635 * $crash tests are expected to crash that we should fix | 1694 * $crash tests are expected to crash that we should fix |
| 1636 * $timeout tests are allowed to timeout | 1695 * $timeout tests are allowed to timeout |
| 1637 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 1696 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
| 1638 """; | 1697 """; |
| 1639 print(report); | 1698 print(report); |
| 1640 } | 1699 } |
| 1641 } | 1700 } |
| OLD | NEW |