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 /** | 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) { | |
|
ahe
2012/11/14 18:46:16
Bail-out early:
if (!useDart2jsFromSdk) return nu
kustermann
2012/11/16 14:58:42
Done.
| |
| 449 var snapshotPath = TestUtils.absolutePath(new Path(buildDir). | |
| 450 join(new Path('dart-sdk/lib/_internal/compiler/implementation/dart2js. dart.snapshot'))); | |
|
ricow1
2012/11/14 08:53:28
Long line
ahe
2012/11/14 18:46:16
You can always split a string in two using:
new P
kustermann
2012/11/16 14:58:42
Done.
kustermann
2012/11/16 14:58:42
Done.
| |
| 451 return [new Uri("file://$snapshotPath")]; | |
|
ahe
2012/11/14 18:46:16
See http://blogs.msdn.com/b/ie/archive/2006/12/06/
| |
| 452 } | |
| 453 return null; | |
| 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 = <Command>[new Dart2JsCommand("$tempDir/out.js", |
| 716 !useDart2JsFromSdk, dart2JsBootstrapDependencies, dartShellFileName, a rgs)]; | |
|
ahe
2012/11/14 18:46:16
Long line.
ahe
2012/11/14 18:46:16
It is not necessary to pass in !useDart2JsFromSdk.
kustermann
2012/11/16 14:58:42
Done.
kustermann
2012/11/16 14:58:42
I changed dart2JsBootstrapDependencies to return [
| |
| 702 if (info.hasCompileError) { | 717 if (info.hasCompileError) { |
| 703 // Do not attempt to run the compiled result. A compilation | 718 // Do not attempt to run the compiled result. A compilation |
| 704 // error should be reported by the compilation command. | 719 // error should be reported by the compilation command. |
| 705 } else if (configuration['runtime'] == 'd8') { | 720 } else if (configuration['runtime'] == 'd8') { |
| 706 commands.add(new Command(d8FileName, ['$tempDir/out.js'])); | 721 commands.add(new Command(d8FileName, ['$tempDir/out.js'])); |
| 707 } else if (configuration['runtime'] == 'jsshell') { | 722 } else if (configuration['runtime'] == 'jsshell') { |
| 708 commands.add(new Command(jsShellFileName, ['$tempDir/out.js'])); | 723 commands.add(new Command(jsShellFileName, ['$tempDir/out.js'])); |
| 709 } | 724 } |
| 710 return commands; | 725 return commands; |
| 711 | 726 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 992 args.add(inputFile); | 1007 args.add(inputFile); |
| 993 break; | 1008 break; |
| 994 default: | 1009 default: |
| 995 Expect.fail('unimplemented compiler $compiler'); | 1010 Expect.fail('unimplemented compiler $compiler'); |
| 996 } | 1011 } |
| 997 if (executable.endsWith('.dart')) { | 1012 if (executable.endsWith('.dart')) { |
| 998 // Run the compiler script via the Dart VM. | 1013 // Run the compiler script via the Dart VM. |
| 999 args.insertRange(0, 1, executable); | 1014 args.insertRange(0, 1, executable); |
| 1000 executable = dartShellFileName; | 1015 executable = dartShellFileName; |
| 1001 } | 1016 } |
| 1017 if (configuration['compiler'] == 'dart2js') { | |
| 1018 return new Dart2JsCommand(outputFile, !useDart2JsFromSdk, | |
| 1019 dart2JsBootstrapDependencies, dartShellFileName, args); | |
| 1020 } | |
| 1002 return new Command(executable, args); | 1021 return new Command(executable, args); |
| 1003 } | 1022 } |
| 1004 | 1023 |
| 1005 /** | 1024 /** |
| 1006 * Create a directory for the generated test. If a Dart language test | 1025 * 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 | 1026 * 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. | 1027 * 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 | 1028 * These scripts and pages are written to a generated_test directory |
| 1010 * inside the build directory of the checkout. | 1029 * inside the build directory of the checkout. |
| 1011 * | 1030 * |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1453 '$dartDir/third_party/rhino/1_7R3/js.jar', | 1472 '$dartDir/third_party/rhino/1_7R3/js.jar', |
| 1454 '$dartDir/third_party/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar', | 1473 '$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', | 1474 '$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', | 1475 '$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', | 1476 '$dartDir/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar', |
| 1458 '$dartDir/third_party/junit/v4_8_2/junit.jar'], | 1477 '$dartDir/third_party/junit/v4_8_2/junit.jar'], |
| 1459 Platform.operatingSystem == 'windows'? ';': ':'); // Path separator. | 1478 Platform.operatingSystem == 'windows'? ';': ':'); // Path separator. |
| 1460 } | 1479 } |
| 1461 } | 1480 } |
| 1462 | 1481 |
| 1482 class TimeStampCache { | |
| 1483 Map<String,Date> _cache = <String,Date>{}; | |
|
ahe
2012/11/14 18:46:16
Add space after comma (twice).
kustermann
2012/11/16 14:58:42
Done.
| |
| 1484 | |
| 1485 /** | |
| 1486 * Returns the timestamp of the given [Uri] and caches the result for | |
|
ahe
2012/11/14 18:46:16
Try to write documentation comments so that the fi
kustermann
2012/11/16 14:58:42
Done.
| |
| 1487 * future queries. If [uri] is a local file, it's last modified [Date] | |
| 1488 * will be returned. If the file does not exist, null will be returned | |
| 1489 * instead. | |
| 1490 * In case [uri] is not a local file, this method will always return | |
| 1491 * the current date. | |
| 1492 */ | |
| 1493 Date getTimeStamp(Uri uri) { | |
|
ahe
2012/11/14 18:46:16
I would have called this "getLastModified".
kustermann
2012/11/16 14:58:42
Done.
| |
| 1494 if (uri.scheme == "file") { | |
| 1495 if (_cache.containsKey(uri.path)) { | |
| 1496 return _cache[uri.path]; | |
| 1497 } | |
| 1498 var file = new File(uri.path); | |
| 1499 _cache[uri.path] = file.existsSync() ? file.lastModifiedSync() : null; | |
| 1500 return _cache[uri.path]; | |
| 1501 } | |
| 1502 return new Date.now(); | |
| 1503 } | |
| 1504 } | |
| 1505 | |
| 1463 class TestUtils { | 1506 class TestUtils { |
| 1464 /** | 1507 /** |
| 1465 * The libraries in this directory relies on finding various files | 1508 * The libraries in this directory relies on finding various files |
| 1466 * relative to the 'test.dart' script in '.../dart/tools/test.dart'. If | 1509 * 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 | 1510 * the main script using 'test_suite.dart' is not there, the main |
| 1468 * script must set this to '.../dart/tools/test.dart'. | 1511 * script must set this to '.../dart/tools/test.dart'. |
| 1469 */ | 1512 */ |
| 1470 static String testScriptPath = new Options().script; | 1513 static String testScriptPath = new Options().script; |
| 1514 static TimeStampCache timestampCache = new TimeStampCache(); | |
| 1471 | 1515 |
|
Bill Hesse
2012/11/14 09:37:34
Why not cache currentDirectoryPath here, the way t
kustermann
2012/11/16 14:58:42
Done.
| |
| 1472 /** | 1516 /** |
| 1473 * Creates a directory using a [relativePath] to an existing | 1517 * Creates a directory using a [relativePath] to an existing |
| 1474 * [base] directory if that [relativePath] does not already exist. | 1518 * [base] directory if that [relativePath] does not already exist. |
| 1475 */ | 1519 */ |
| 1476 static Directory mkdirRecursive(Path base, Path relativePath) { | 1520 static Directory mkdirRecursive(Path base, Path relativePath) { |
| 1477 Directory dir = new Directory.fromPath(base); | 1521 Directory dir = new Directory.fromPath(base); |
| 1478 Expect.isTrue(dir.existsSync(), | 1522 Expect.isTrue(dir.existsSync(), |
| 1479 "Expected ${dir} to already exist"); | 1523 "Expected ${dir} to already exist"); |
| 1480 var segments = relativePath.segments(); | 1524 var segments = relativePath.segments(); |
| 1481 for (String segment in segments) { | 1525 for (String segment in segments) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1508 // When running on a built bot, the file can be made visible in the waterfal l UI. | 1552 // When running on a built bot, the file can be made visible in the waterfal l UI. |
| 1509 return ".flaky.log"; | 1553 return ".flaky.log"; |
| 1510 } | 1554 } |
| 1511 | 1555 |
| 1512 static void ensureExists(String filename, Map configuration) { | 1556 static void ensureExists(String filename, Map configuration) { |
| 1513 if (!configuration['list'] && !(new File(filename).existsSync())) { | 1557 if (!configuration['list'] && !(new File(filename).existsSync())) { |
| 1514 throw "Executable '$filename' does not exist"; | 1558 throw "Executable '$filename' does not exist"; |
| 1515 } | 1559 } |
| 1516 } | 1560 } |
| 1517 | 1561 |
| 1562 static Path absolutePath(Path path) { | |
| 1563 if (!path.isAbsolute) { | |
| 1564 var cwd = new Path(new Directory.current().path); | |
|
Bill Hesse
2012/11/14 09:37:34
Can we cache this (new Path(new Directory.current(
kustermann
2012/11/16 14:58:42
Done.
| |
| 1565 return cwd.join(path); | |
| 1566 } | |
| 1567 return path; | |
| 1568 } | |
| 1569 | |
| 1518 static String outputDir(Map configuration) { | 1570 static String outputDir(Map configuration) { |
| 1519 var result = ''; | 1571 var result = ''; |
| 1520 var system = configuration['system']; | 1572 var system = configuration['system']; |
| 1521 if (system == 'linux') { | 1573 if (system == 'linux') { |
| 1522 result = 'out/'; | 1574 result = 'out/'; |
| 1523 } else if (system == 'macos') { | 1575 } else if (system == 'macos') { |
| 1524 result = 'xcodebuild/'; | 1576 result = 'xcodebuild/'; |
| 1525 } else if (system == 'windows') { | 1577 } else if (system == 'windows') { |
| 1526 result = 'build/'; | 1578 result = 'build/'; |
| 1527 } | 1579 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1631 * $pass tests are expected to pass | 1683 * $pass tests are expected to pass |
| 1632 * $failOk tests are expected to fail that we won't fix | 1684 * $failOk tests are expected to fail that we won't fix |
| 1633 * $fail tests are expected to fail that we should fix | 1685 * $fail tests are expected to fail that we should fix |
| 1634 * $crash tests are expected to crash that we should fix | 1686 * $crash tests are expected to crash that we should fix |
| 1635 * $timeout tests are allowed to timeout | 1687 * $timeout tests are allowed to timeout |
| 1636 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 1688 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
| 1637 """; | 1689 """; |
| 1638 print(report); | 1690 print(report); |
| 1639 } | 1691 } |
| 1640 } | 1692 } |
| OLD | NEW |