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

Unified Diff: lib/src/vm_listener.dart

Issue 933083002: Add a test runner executable. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/utils.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/vm_listener.dart
diff --git a/lib/src/vm_listener.dart b/lib/src/vm_listener.dart
index 7deb0b42eb52be1e943af0456317959a28420f31..2a35f2219b95470dd3e858922c6eb260b939a175 100644
--- a/lib/src/vm_listener.dart
+++ b/lib/src/vm_listener.dart
@@ -11,6 +11,7 @@ import 'declarer.dart';
import 'remote_exception.dart';
import 'suite.dart';
import 'test.dart';
+import 'utils.dart';
/// A class that runs tests in a separate isolate and communicates the results
/// back to the main isolate.
@@ -18,18 +19,54 @@ class VmListener {
/// The test suite to run.
final Suite _suite;
- /// Extracts metadata about all the tests in [main] and sends information
- /// about them over [sendPort].
+ /// Extracts metadata about all the tests in the function returned by
+ /// [getMain] and sends information about them over [sendPort].
+ ///
+ /// The main function is wrapped in a closure so that we can handle it being
+ /// undefined here rather than in the generated code.
///
/// Once that's done, this starts listening for commands about which tests to
/// run.
- static void start(SendPort sendPort, main()) {
+ static void start(SendPort sendPort, Function getMain()) {
+ var main;
+ try {
+ main = getMain();
+ } on NoSuchMethodError catch (_) {
+ _sendLoadException(sendPort, "No top-level main() function defined.");
+ return;
+ }
+
+ if (main is! Function) {
+ _sendLoadException(sendPort, "Top-level main getter is not a function.");
+ return;
+ } else if (main is! AsyncFunction) {
+ _sendLoadException(
+ sendPort, "Top-level main() function takes arguments.");
+ return;
+ }
+
var declarer = new Declarer();
- runZoned(main, zoneValues: {#unittest.declarer: declarer});
+ try {
+ runZoned(main, zoneValues: {#unittest.declarer: declarer});
+ } catch (error, stackTrace) {
+ sendPort.send({
+ "type": "error",
+ "error": RemoteException.serialize(error, stackTrace)
+ });
+ return;
+ }
+
new VmListener._(new Suite("VmListener", declarer.tests))
._listen(sendPort);
}
+ /// Sends a message over [sendPort] indicating that the tests failed to load.
+ ///
+ /// [message] should describe the failure.
+ static void _sendLoadException(SendPort sendPort, String message) {
+ sendPort.send({"type": "loadException", "message": message});
+ }
+
VmListener._(this._suite);
/// Send information about [_suite] across [sendPort] and start listening for
@@ -47,7 +84,10 @@ class VmListener {
});
}
- sendPort.send(tests);
+ sendPort.send({
+ "type": "success",
+ "tests": tests
+ });
}
/// Runs [test] and send the results across [sendPort].
« no previous file with comments | « lib/src/utils.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698