Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: tools/testing/dart/test_suite.dart

Issue 12864003: Revert "Update the test runner to use the new dart:io API" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/testing/dart/test_runner.dart ('k') | tools/testing/dart/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 /** 46 /**
47 * Calls [function] asynchronously. Returns a future that completes with the 47 * Calls [function] asynchronously. Returns a future that completes with the
48 * result of the function. If the function is `null`, returns a future that 48 * result of the function. If the function is `null`, returns a future that
49 * completes immediately with `null`. 49 * completes immediately with `null`.
50 */ 50 */
51 Future asynchronously(function()) { 51 Future asynchronously(function()) {
52 if (function == null) return new Future.immediate(null); 52 if (function == null) return new Future.immediate(null);
53 53
54 var completer = new Completer(); 54 var completer = new Completer();
55 Timer.run(() => completer.complete(function())); 55 new Timer(0, (_) {
56 completer.complete(function());
57 });
56 58
57 return completer.future; 59 return completer.future;
58 } 60 }
59 61
60 /** A completer that waits until all added [Future]s complete. */ 62 /** A completer that waits until all added [Future]s complete. */
61 // TODO(rnystrom): Copied from web_components. Remove from here when it gets 63 // TODO(rnystrom): Copied from web_components. Remove from here when it gets
62 // added to dart:core. (See #6626.) 64 // added to dart:core. (See #6626.)
63 class FutureGroup { 65 class FutureGroup {
64 const _FINISHED = -1; 66 const _FINISHED = -1;
65 int _pending = 0; 67 int _pending = 0;
66 Completer<List> _completer = new Completer<List>(); 68 Completer<List> _completer = new Completer<List>();
67 final List<Future> futures = <Future>[]; 69 final List<Future> futures = <Future>[];
68 bool wasCompleted = false; 70 bool wasCompleted = false;
69 71
70 /** 72 /**
71 * Wait for [task] to complete (assuming this barrier has not already been 73 * Wait for [task] to complete (assuming this barrier has not already been
72 * marked as completed, otherwise you'll get an exception indicating that a 74 * marked as completed, otherwise you'll get an exception indicating that a
73 * future has already been completed). 75 * future has already been completed).
74 */ 76 */
75 void add(Future task) { 77 void add(Future task) {
76 if (_pending == _FINISHED) { 78 if (_pending == _FINISHED) {
77 throw new Exception("FutureFutureAlreadyCompleteException"); 79 throw new Exception("FutureFutureAlreadyCompleteException");
78 } 80 }
79 _pending++; 81 _pending++;
80 var handledTaskFuture = task.catchError((e) { 82 var handledTaskFuture = task.catchError((e) {
81 if (!wasCompleted) { 83 if (!wasCompleted) {
82 _completer.completeError(e.error, e.stackTrace); 84 _completer.completeError(e.error, task.stackTrace);
83 wasCompleted = true; 85 wasCompleted = true;
84 } 86 }
85 }).then((_) { 87 }).then((_) {
86 _pending--; 88 _pending--;
87 if (_pending == 0) { 89 if (_pending == 0) {
88 _pending = _FINISHED; 90 _pending = _FINISHED;
89 if (!wasCompleted) { 91 if (!wasCompleted) {
90 _completer.complete(futures); 92 _completer.complete(futures);
91 wasCompleted = true; 93 wasCompleted = true;
92 } 94 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 */ 137 */
136 String get compilerPath { 138 String get compilerPath {
137 if (configuration['compiler'] == 'none') { 139 if (configuration['compiler'] == 'none') {
138 return null; // No separate compiler for dartium tests. 140 return null; // No separate compiler for dartium tests.
139 } 141 }
140 var name; 142 var name;
141 switch (configuration['compiler']) { 143 switch (configuration['compiler']) {
142 case 'dartc': 144 case 'dartc':
143 case 'new_analyzer': 145 case 'new_analyzer':
144 name = executablePath; 146 name = executablePath;
145 break;
146 case 'dart2js': 147 case 'dart2js':
147 case 'dart2dart': 148 case 'dart2dart':
148 var prefix = 'sdk/bin/'; 149 var prefix = 'sdk/bin/';
149 String suffix = getExecutableSuffix(configuration['compiler']); 150 String suffix = getExecutableSuffix(configuration['compiler']);
150 if (configuration['host_checked']) { 151 if (configuration['host_checked']) {
151 // The script dart2js_developer is not included in the 152 // The script dart2js_developer is not included in the
152 // shipped SDK, that is the script is not installed in 153 // shipped SDK, that is the script is not installed in
153 // "$buildDir/dart-sdk/bin/" 154 // "$buildDir/dart-sdk/bin/"
154 name = '$prefix/dart2js_developer$suffix'; 155 name = '$prefix/dart2js_developer$suffix';
155 } else { 156 } else {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 * cache information about the test suite, so that directories do not need 250 * cache information about the test suite, so that directories do not need
250 * to be listed each time. 251 * to be listed each time.
251 */ 252 */
252 void forEachTest(TestCaseEvent onTest, Map testCache, [VoidFunction onDone]); 253 void forEachTest(TestCaseEvent onTest, Map testCache, [VoidFunction onDone]);
253 } 254 }
254 255
255 256
256 void ccTestLister() { 257 void ccTestLister() {
257 port.receive((String runnerPath, SendPort replyTo) { 258 port.receive((String runnerPath, SendPort replyTo) {
258 Future processFuture = Process.start(runnerPath, ["--list"]); 259 Future processFuture = Process.start(runnerPath, ["--list"]);
259 processFuture.then((Process p) { 260 processFuture.then((p) {
260 // Drain stderr to not leak resources. 261 // Drain stderr to not leak resources.
261 p.stderr.listen((_) { }); 262 p.stderr.onData = p.stderr.read;
262 Stream<String> stdoutStream = 263 StringInputStream stdoutStream = new StringInputStream(p.stdout);
263 p.stdout.transform(new StringDecoder())
264 .transform(new LineTransformer());
265 var streamDone = false; 264 var streamDone = false;
266 var processExited = false; 265 var processExited = false;
267 checkDone() { 266 checkDone() {
268 if (streamDone && processExited) { 267 if (streamDone && processExited) {
269 replyTo.send(""); 268 replyTo.send("");
270 } 269 }
271 } 270 }
272 stdoutStream.listen((String line) { 271 stdoutStream.onLine = () {
272 String line = stdoutStream.readLine();
273 replyTo.send(line); 273 replyTo.send(line);
274 }, 274 };
275 onDone: () { 275 stdoutStream.onClosed = () {
276 streamDone = true; 276 streamDone = true;
277 checkDone(); 277 checkDone();
278 }); 278 };
279 279 p.onExit = (code) {
280 p.exitCode.then((code) {
281 if (code < 0) { 280 if (code < 0) {
282 print("Failed to list tests: $runnerPath --list"); 281 print("Failed to list tests: $runnerPath --list");
283 replyTo.send(""); 282 replyTo.send("");
284 } else { 283 } else {
285 processExited = true; 284 processExited = true;
286 checkDone(); 285 checkDone();
287 } 286 }
288 }); 287 };
289 port.close(); 288 port.close();
290 }).catchError((e) { 289 }).catchError((e) {
291 print("Failed to list tests: $runnerPath --list"); 290 print("Failed to list tests: $runnerPath --list");
292 replyTo.send(""); 291 replyTo.send("");
293 return true; 292 return true;
294 }); 293 });
295 }); 294 });
296 } 295 }
297 296
298 297
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 enqueueDirectory(dir, group); 579 enqueueDirectory(dir, group);
581 return group.future; 580 return group.future;
582 } 581 }
583 }); 582 });
584 } 583 }
585 584
586 void enqueueDirectory(Directory dir, FutureGroup group) { 585 void enqueueDirectory(Directory dir, FutureGroup group) {
587 var listCompleter = new Completer(); 586 var listCompleter = new Completer();
588 group.add(listCompleter.future); 587 group.add(listCompleter.future);
589 588
590 var lister = dir.list(recursive: listRecursively) 589 var lister = dir.list(recursive: listRecursively);
591 .listen((FileSystemEntity fse) { 590 lister.onFile = (file) => enqueueFile(file, group);
592 if (fse is File) enqueueFile(fse.path, group); 591 lister.onDone = listCompleter.complete;
593 },
594 onDone: listCompleter.complete);
595 } 592 }
596 593
597 void enqueueFile(String filename, FutureGroup group) { 594 void enqueueFile(String filename, FutureGroup group) {
598 if (!isTestFile(filename)) return; 595 if (!isTestFile(filename)) return;
599 Path filePath = new Path(filename); 596 Path filePath = new Path(filename);
600 597
601 // Only run the tests that match the pattern. 598 // Only run the tests that match the pattern.
602 RegExp pattern = configuration['selectors'][suiteName]; 599 RegExp pattern = configuration['selectors'][suiteName];
603 if (!pattern.hasMatch('$filePath')) return; 600 if (!pattern.hasMatch('$filePath')) return;
604 if (filePath.filename.endsWith('test_config.dart')) return; 601 if (filePath.filename.endsWith('test_config.dart')) return;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 827
831 var fileString = file.toString(); 828 var fileString = file.toString();
832 if (fileString.startsWith(buildDir.toString())) { 829 if (fileString.startsWith(buildDir.toString())) {
833 var fileRelativeToBuildDir = file.relativeTo(buildDir); 830 var fileRelativeToBuildDir = file.relativeTo(buildDir);
834 return "/$PREFIX_BUILDDIR/$fileRelativeToBuildDir"; 831 return "/$PREFIX_BUILDDIR/$fileRelativeToBuildDir";
835 } else if (fileString.startsWith(dartDir.toString())) { 832 } else if (fileString.startsWith(dartDir.toString())) {
836 var fileRelativeToDartDir = file.relativeTo(dartDir); 833 var fileRelativeToDartDir = file.relativeTo(dartDir);
837 return "/$PREFIX_DARTDIR/$fileRelativeToDartDir"; 834 return "/$PREFIX_DARTDIR/$fileRelativeToDartDir";
838 } 835 }
839 // Unreachable 836 // Unreachable
840 Expect.fail('This should be unreachable.'); 837 Except.fail('This should be unreachable.');
841 } 838 }
842 839
843 String _getUriForBrowserTest(TestInformation info, 840 void _getUriForBrowserTest(TestInformation info,
844 String pathComponent, 841 String pathComponent,
845 subtestNames, 842 subtestNames,
846 subtestIndex) { 843 subtestIndex) {
847 // Note: If we run test.py with the "--list" option, no http servers 844 // Note: If we run test.py with the "--list" option, no http servers
848 // will be started. So we use PORT/CROSS_ORIGIN_PORT instead of real ports. 845 // will be started. So we use PORT/CROSS_ORIGIN_PORT instead of real ports.
849 var serverPort = "PORT"; 846 var serverPort = "PORT";
850 var crossOriginPort = "CROSS_ORIGIN_PORT"; 847 var crossOriginPort = "CROSS_ORIGIN_PORT";
851 if (!configuration['list']) { 848 if (!configuration['list']) {
852 Expect.isTrue(configuration.containsKey('_servers_')); 849 Expect.isTrue(configuration.containsKey('_servers_'));
853 serverPort = configuration['_servers_'].port; 850 serverPort = configuration['_servers_'].port;
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 if (hasDynamicTypeError) { 1494 if (hasDynamicTypeError) {
1498 // TODO(ahe): Remove this warning when co19 no longer uses this tag. 1495 // TODO(ahe): Remove this warning when co19 no longer uses this tag.
1499 1496
1500 // @dynamic-type-error has been replaced by tests that use 1497 // @dynamic-type-error has been replaced by tests that use
1501 // tests/co19/src/Utils/dynamic_check.dart to dynamically detect 1498 // tests/co19/src/Utils/dynamic_check.dart to dynamically detect
1502 // if a test is running in checked mode or not and change its 1499 // if a test is running in checked mode or not and change its
1503 // expectations accordingly. 1500 // expectations accordingly.
1504 1501
1505 // Using stderr.writeString to avoid breaking dartc/junit_tests 1502 // Using stderr.writeString to avoid breaking dartc/junit_tests
1506 // which parses the output of the --list option. 1503 // which parses the output of the --list option.
1507 stderr.writeln( 1504 stderr.writeString(
1508 "Warning: deprecated @dynamic-type-error tag used in $filePath"); 1505 "Warning: deprecated @dynamic-type-error tag used in $filePath\n");
1509 } 1506 }
1510 1507
1511 return { 1508 return {
1512 "vmOptions": <List>[[]], 1509 "vmOptions": <List>[[]],
1513 "dartOptions": null, 1510 "dartOptions": null,
1514 "packageRoot": null, 1511 "packageRoot": null,
1515 "hasCompileError": hasCompileError, 1512 "hasCompileError": hasCompileError,
1516 "hasRuntimeError": hasRuntimeError, 1513 "hasRuntimeError": hasRuntimeError,
1517 "isStaticClean" : !hasStaticWarning, 1514 "isStaticClean" : !hasStaticWarning,
1518 "otherScripts": <String>[], 1515 "otherScripts": <String>[],
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 testClasses = <String>[]; 1619 testClasses = <String>[];
1623 // Do not read the status file. 1620 // Do not read the status file.
1624 // All exclusions are hardcoded in this script, as they are in testcfg.py. 1621 // All exclusions are hardcoded in this script, as they are in testcfg.py.
1625 processDirectory(); 1622 processDirectory();
1626 } 1623 }
1627 1624
1628 void processDirectory() { 1625 void processDirectory() {
1629 directoryPath = '$dartDir/$directoryPath'; 1626 directoryPath = '$dartDir/$directoryPath';
1630 Directory dir = new Directory(directoryPath); 1627 Directory dir = new Directory(directoryPath);
1631 1628
1632 dir.list(recursive: true).listen((FileSystemEntity fse) { 1629 var lister = dir.list(recursive: true);
1633 if (fse is File) processFile(fse.path); 1630 lister.onFile = processFile;
1634 }, 1631 lister.onDone = createTest;
1635 onDone: createTest);
1636 } 1632 }
1637 1633
1638 void processFile(String filename) { 1634 void processFile(String filename) {
1639 if (!isTestFile(filename)) return; 1635 if (!isTestFile(filename)) return;
1640 1636
1641 int index = filename.indexOf('compiler/javatests/com/google/dart'); 1637 int index = filename.indexOf('compiler/javatests/com/google/dart');
1642 if (index != -1) { 1638 if (index != -1) {
1643 String testRelativePath = 1639 String testRelativePath =
1644 filename.substring(index + 'compiler/javatests/'.length, 1640 filename.substring(index + 'compiler/javatests/'.length,
1645 filename.length - '.java'.length); 1641 filename.length - '.java'.length);
1646 String testClass = testRelativePath.replaceAll('/', '.'); 1642 String testClass = testRelativePath.replaceAll('/', '.');
1647 testClasses.add(testClass); 1643 testClasses.add(testClass);
1648 } 1644 }
1649 } 1645 }
1650 1646
1651 void createTest() { 1647 void createTest(successIgnored) {
1652 var sdkDir = "$buildDir/dart-sdk".trim(); 1648 var sdkDir = "$buildDir/dart-sdk".trim();
1653 List<String> args = <String>[ 1649 List<String> args = <String>[
1654 '-ea', 1650 '-ea',
1655 '-classpath', classPath, 1651 '-classpath', classPath,
1656 '-Dcom.google.dart.sdk=$sdkDir', 1652 '-Dcom.google.dart.sdk=$sdkDir',
1657 '-Dcom.google.dart.corelib.SharedTests.test_py=$dartDir/tools/test.py', 1653 '-Dcom.google.dart.corelib.SharedTests.test_py=$dartDir/tools/test.py',
1658 'org.junit.runner.JUnitCore']; 1654 'org.junit.runner.JUnitCore'];
1659 args.addAll(testClasses); 1655 args.addAll(testClasses);
1660 1656
1661 // Lengthen the timeout for JUnit tests. It is normal for them 1657 // Lengthen the timeout for JUnit tests. It is normal for them
(...skipping 25 matching lines...) Expand all
1687 '$dartDir/third_party/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar', 1683 '$dartDir/third_party/hamcrest/v1_3/hamcrest-core-1.3.0RC2.jar',
1688 '$dartDir/third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar', 1684 '$dartDir/third_party/hamcrest/v1_3/hamcrest-generator-1.3.0RC2.jar',
1689 '$dartDir/third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar', 1685 '$dartDir/third_party/hamcrest/v1_3/hamcrest-integration-1.3.0RC2.jar',
1690 '$dartDir/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar', 1686 '$dartDir/third_party/hamcrest/v1_3/hamcrest-library-1.3.0RC2.jar',
1691 '$dartDir/third_party/junit/v4_8_2/junit.jar'] 1687 '$dartDir/third_party/junit/v4_8_2/junit.jar']
1692 .join(Platform.operatingSystem == 'windows'? ';': ':'); // Path separat or. 1688 .join(Platform.operatingSystem == 'windows'? ';': ':'); // Path separat or.
1693 } 1689 }
1694 } 1690 }
1695 1691
1696 class LastModifiedCache { 1692 class LastModifiedCache {
1697 Map<String, DateTime> _cache = <String, DateTime>{}; 1693 Map<String, Date> _cache = <String, Date>{};
1698 1694
1699 /** 1695 /**
1700 * Returns the last modified date of the given [uri]. 1696 * Returns the last modified date of the given [uri].
1701 * 1697 *
1702 * The return value will be cached for future queries. If [uri] is a local 1698 * The return value will be cached for future queries. If [uri] is a local
1703 * file, it's last modified [Date] will be returned. If the file does not 1699 * file, it's last modified [Date] will be returned. If the file does not
1704 * exist, null will be returned instead. 1700 * exist, null will be returned instead.
1705 * In case [uri] is not a local file, this method will always return 1701 * In case [uri] is not a local file, this method will always return
1706 * the current date. 1702 * the current date.
1707 */ 1703 */
1708 DateTime getLastModified(Uri uri) { 1704 Date getLastModified(Uri uri) {
1709 if (uri.scheme == "file") { 1705 if (uri.scheme == "file") {
1710 if (_cache.containsKey(uri.path)) { 1706 if (_cache.containsKey(uri.path)) {
1711 return _cache[uri.path]; 1707 return _cache[uri.path];
1712 } 1708 }
1713 var file = new File(new Path(uri.path).toNativePath()); 1709 var file = new File(new Path(uri.path).toNativePath());
1714 _cache[uri.path] = file.existsSync() ? file.lastModifiedSync() : null; 1710 _cache[uri.path] = file.existsSync() ? file.lastModifiedSync() : null;
1715 return _cache[uri.path]; 1711 return _cache[uri.path];
1716 } 1712 }
1717 return new Date.now(); 1713 return new Date.now();
1718 } 1714 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 Expect.isTrue(dir.existsSync(), "Failed to create ${dir.path}"); 1752 Expect.isTrue(dir.existsSync(), "Failed to create ${dir.path}");
1757 } 1753 }
1758 return dir; 1754 return dir;
1759 } 1755 }
1760 1756
1761 /** 1757 /**
1762 * Copy a [source] file to a new place. 1758 * Copy a [source] file to a new place.
1763 * Assumes that the directory for [dest] already exists. 1759 * Assumes that the directory for [dest] already exists.
1764 */ 1760 */
1765 static Future copyFile(Path source, Path dest) { 1761 static Future copyFile(Path source, Path dest) {
1766 return new File.fromPath(source).openRead() 1762 var output = new File.fromPath(dest).openOutputStream();
1767 .pipe(new File.fromPath(dest).openWrite()); 1763 new File.fromPath(source).openInputStream().pipe(output);
1764 var completer = new Completer();
1765 output.onClosed = (){ completer.complete(null); };
1766 return completer.future;
1768 } 1767 }
1769 1768
1770 static Path debugLogfile() { 1769 static Path debugLogfile() {
1771 return new Path(".debug.log"); 1770 return new Path(".debug.log");
1772 } 1771 }
1773 1772
1774 static String flakyFileName() { 1773 static String flakyFileName() {
1775 // If a flaky test did fail, infos about it (i.e. test name, stdin, stdout) 1774 // If a flaky test did fail, infos about it (i.e. test name, stdin, stdout)
1776 // will be written to this file. This is useful for the debugging of 1775 // will be written to this file. This is useful for the debugging of
1777 // flaky tests. 1776 // flaky tests.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1961 * $pass tests are expected to pass 1960 * $pass tests are expected to pass
1962 * $failOk tests are expected to fail that we won't fix 1961 * $failOk tests are expected to fail that we won't fix
1963 * $fail tests are expected to fail that we should fix 1962 * $fail tests are expected to fail that we should fix
1964 * $crash tests are expected to crash that we should fix 1963 * $crash tests are expected to crash that we should fix
1965 * $timeout tests are allowed to timeout 1964 * $timeout tests are allowed to timeout
1966 * $compileErrorSkip tests are skipped on browsers due to compile-time error 1965 * $compileErrorSkip tests are skipped on browsers due to compile-time error
1967 """; 1966 """;
1968 print(report); 1967 print(report);
1969 } 1968 }
1970 } 1969 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_runner.dart ('k') | tools/testing/dart/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698