Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 unittest.runner.loader; | 5 library unittest.runner.loader; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 | 10 |
| 11 import 'package:path/path.dart' as p; | 11 import 'package:path/path.dart' as p; |
| 12 | 12 |
| 13 import '../backend/suite.dart'; | 13 import '../backend/suite.dart'; |
| 14 import '../util/dart.dart'; | 14 import '../util/dart.dart'; |
| 15 import '../util/io.dart'; | 15 import '../util/io.dart'; |
|
kevmoo
2015/03/04 23:41:04
unused import
nweiz
2015/03/05 01:08:02
This is needed for [packageRootFor].
| |
| 16 import '../util/remote_exception.dart'; | 16 import '../util/remote_exception.dart'; |
| 17 import 'vm/isolate_test.dart'; | 17 import 'vm/isolate_test.dart'; |
| 18 import 'load_exception.dart'; | 18 import 'load_exception.dart'; |
| 19 | 19 |
| 20 /// A class for finding test files and loading them into a runnable form. | 20 /// A class for finding test files and loading them into a runnable form. |
| 21 class Loader { | 21 class Loader { |
| 22 /// The package root to use for loading tests, or `null` to use the automatic | 22 /// The package root to use for loading tests, or `null` to use the automatic |
| 23 /// root. | 23 /// root. |
| 24 final String _packageRoot; | 24 final String _packageRoot; |
| 25 | 25 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 48 // isolates failing to load without stopping the rest. | 48 // isolates failing to load without stopping the rest. |
| 49 return loadFile(entry.path); | 49 return loadFile(entry.path); |
| 50 })).then((suites) => suites.toSet()..remove(null)); | 50 })).then((suites) => suites.toSet()..remove(null)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 /// Loads a test suite from the file at [path]. | 53 /// Loads a test suite from the file at [path]. |
| 54 /// | 54 /// |
| 55 /// This will throw a [LoadException] if the file fails to load. | 55 /// This will throw a [LoadException] if the file fails to load. |
| 56 Future<Suite> loadFile(String path) { | 56 Future<Suite> loadFile(String path) { |
| 57 // TODO(nweiz): Support browser tests. | 57 // TODO(nweiz): Support browser tests. |
| 58 var packageRoot = _packageRoot == null | 58 var packageRoot = packageRootFor(path, _packageRoot); |
| 59 ? p.join(p.dirname(path), 'packages') | |
| 60 : _packageRoot; | |
| 61 | |
| 62 if (!new Directory(packageRoot).existsSync()) { | |
| 63 throw new LoadException(path, "Directory $packageRoot does not exist."); | |
| 64 } | |
| 65 | |
| 66 var receivePort = new ReceivePort(); | 59 var receivePort = new ReceivePort(); |
| 67 return runInIsolate(''' | 60 return runInIsolate(''' |
| 68 import "package:unittest/src/runner/vm/isolate_listener.dart"; | 61 import "package:unittest/src/runner/vm/isolate_listener.dart"; |
| 69 | 62 |
| 70 import "${p.toUri(p.absolute(path))}" as test; | 63 import "${p.toUri(p.absolute(path))}" as test; |
| 71 | 64 |
| 72 void main(_, Map message) { | 65 void main(_, Map message) { |
| 73 var sendPort = message['reply']; | 66 var sendPort = message['reply']; |
| 74 IsolateListener.start(sendPort, () => test.main); | 67 IsolateListener.start(sendPort, () => test.main); |
| 75 } | 68 } |
| 76 ''', { | 69 ''', { |
| 77 'reply': receivePort.sendPort | 70 'reply': receivePort.sendPort |
| 78 }, packageRoot: packageRoot).catchError((error, stackTrace) { | 71 }, packageRoot: packageRoot) |
| 72 .catchError((error, stackTrace) { | |
| 79 receivePort.close(); | 73 receivePort.close(); |
| 80 return new Future.error(new LoadException(path, error), stackTrace); | 74 return new Future.error(new LoadException(path, error), stackTrace); |
| 81 }).then((isolate) { | 75 }).then((isolate) { |
| 82 _isolates.add(isolate); | 76 _isolates.add(isolate); |
| 83 return receivePort.first; | 77 return receivePort.first; |
| 84 }).then((response) { | 78 }).then((response) { |
| 85 if (response["type"] == "loadException") { | 79 if (response["type"] == "loadException") { |
| 86 return new Future.error(new LoadException(path, response["message"])); | 80 return new Future.error(new LoadException(path, response["message"])); |
| 87 } else if (response["type"] == "error") { | 81 } else if (response["type"] == "error") { |
| 88 var asyncError = RemoteException.deserialize(response["error"]); | 82 var asyncError = RemoteException.deserialize(response["error"]); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 99 | 93 |
| 100 /// Closes the loader and releases all resources allocated by it. | 94 /// Closes the loader and releases all resources allocated by it. |
| 101 Future close() { | 95 Future close() { |
| 102 for (var isolate in _isolates) { | 96 for (var isolate in _isolates) { |
| 103 isolate.kill(); | 97 isolate.kill(); |
| 104 } | 98 } |
| 105 _isolates.clear(); | 99 _isolates.clear(); |
| 106 return new Future.value(); | 100 return new Future.value(); |
| 107 } | 101 } |
| 108 } | 102 } |
| OLD | NEW |