Commit 79ceee73 authored by Hixie's avatar Hixie

Port our testing framework to new test library

parent cbd49315
...@@ -10,12 +10,14 @@ import 'package:path/path.dart' as p; ...@@ -10,12 +10,14 @@ import 'package:path/path.dart' as p;
import 'package:sky_tools/src/test/json_socket.dart'; import 'package:sky_tools/src/test/json_socket.dart';
import 'package:sky_tools/src/test/remote_test.dart'; import 'package:sky_tools/src/test/remote_test.dart';
import 'package:stack_trace/stack_trace.dart'; import 'package:stack_trace/stack_trace.dart';
import 'package:test/src/backend/group.dart';
import 'package:test/src/backend/group_entry.dart';
import 'package:test/src/backend/metadata.dart'; import 'package:test/src/backend/metadata.dart';
import 'package:test/src/backend/test_platform.dart'; import 'package:test/src/backend/test_platform.dart';
import 'package:test/src/runner/configuration.dart'; import 'package:test/src/runner/configuration.dart';
import 'package:test/src/runner/hack_load_vm_file_hook.dart' as hack;
import 'package:test/src/runner/load_exception.dart'; import 'package:test/src/runner/load_exception.dart';
import 'package:test/src/runner/runner_suite.dart'; import 'package:test/src/runner/runner_suite.dart';
import 'package:test/src/runner/hack_load_vm_file_hook.dart' as hack;
import 'package:test/src/runner/vm/environment.dart'; import 'package:test/src/runner/vm/environment.dart';
import 'package:test/src/util/io.dart'; import 'package:test/src/util/io.dart';
import 'package:test/src/util/remote_exception.dart'; import 'package:test/src/util/remote_exception.dart';
...@@ -82,7 +84,7 @@ void main() { ...@@ -82,7 +84,7 @@ void main() {
} }
'''); ''');
Completer completer = new Completer(); Completer<Iterable<GroupEntry>> completer = new Completer<Iterable<GroupEntry>>();
Process process = await _startProcess(listenerFile.path, Process process = await _startProcess(listenerFile.path,
packageRoot: p.absolute(config.packageRoot)); packageRoot: p.absolute(config.packageRoot));
...@@ -105,44 +107,43 @@ void main() { ...@@ -105,44 +107,43 @@ void main() {
} }
}); });
Future<JSONSocket> socket = (() async { JSONSocket socket = new JSONSocket(await info.socket);
return new JSONSocket(await info.socket);
})();
socket.then((JSONSocket socket) async {
await cleanupTempDirectory();
StreamSubscription subscription; await cleanupTempDirectory();
subscription = socket.stream.listen((response) {
if (response["type"] == "print") {
print(response["line"]);
} else if (response["type"] == "loadException") {
process.kill();
completer.completeError(
new LoadException(path, response["message"]),
new Trace.current());
} else if (response["type"] == "error") {
process.kill();
AsyncError asyncError = RemoteException.deserialize(response["error"]);
completer.completeError(
new LoadException(path, asyncError.error),
asyncError.stackTrace);
} else {
assert(response["type"] == "success");
subscription.cancel();
completer.complete(response["tests"]);
}
});
});
return new RunnerSuite(const VMEnvironment(), StreamSubscription subscription;
(await completer.future).map((test) { subscription = socket.stream.listen((response) {
if (response["type"] == "print") {
print(response["line"]);
} else if (response["type"] == "loadException") {
process.kill();
completer.completeError(
new LoadException(path, response["message"]),
new Trace.current());
} else if (response["type"] == "error") {
process.kill();
AsyncError asyncError = RemoteException.deserialize(response["error"]);
completer.completeError(
new LoadException(path, asyncError.error),
asyncError.stackTrace);
} else {
assert(response["type"] == "success");
subscription.cancel();
completer.complete(response["tests"].map((test) {
var testMetadata = new Metadata.deserialize(test['metadata']); var testMetadata = new Metadata.deserialize(test['metadata']);
return new RemoteTest(test['name'], testMetadata, socket, test['index']); return new RemoteTest(test['name'], testMetadata, socket, test['index']);
}), }));
metadata: metadata, }
path: path, });
platform: TestPlatform.vm,
os: currentOS, Iterable<GroupEntry> entries = await completer.future;
onClose: process.kill);
return new RunnerSuite(
const VMEnvironment(),
new Group.root(entries, metadata: metadata),
path: path,
platform: TestPlatform.vm,
os: currentOS,
onClose: process.kill
);
} }
...@@ -41,7 +41,7 @@ class RemoteListener { ...@@ -41,7 +41,7 @@ class RemoteListener {
Isolate.current.setErrorsFatal(false); Isolate.current.setErrorsFatal(false);
Isolate.current.addErrorListener(errorPort.sendPort); Isolate.current.addErrorListener(errorPort.sendPort);
errorPort.listen((message) { errorPort.listen((message) {
// Masquerade as an IsoalteSpawnException because that's what this would // Masquerade as an IsolateSpawnException because that's what this would
// be if the error had been detected statically. // be if the error had been detected statically.
var error = new IsolateSpawnException(message[0]); var error = new IsolateSpawnException(message[0]);
var stackTrace = var stackTrace =
...@@ -69,7 +69,7 @@ class RemoteListener { ...@@ -69,7 +69,7 @@ class RemoteListener {
return; return;
} }
Declarer declarer = new Declarer(); Declarer declarer = new Declarer(metadata);
try { try {
await runZoned(() => new Future.sync(main), zoneValues: { await runZoned(() => new Future.sync(main), zoneValues: {
#test.declarer: declarer #test.declarer: declarer
...@@ -84,8 +84,8 @@ class RemoteListener { ...@@ -84,8 +84,8 @@ class RemoteListener {
return; return;
} }
Suite suite = new Suite(declarer.tests, Suite suite = new Suite(declarer.build(),
platform: TestPlatform.vm, os: currentOS, metadata: metadata); platform: TestPlatform.vm, os: currentOS);
new RemoteListener._(suite, socket)._listen(); new RemoteListener._(suite, socket)._listen();
} }
...@@ -101,8 +101,10 @@ class RemoteListener { ...@@ -101,8 +101,10 @@ class RemoteListener {
void _listen() { void _listen() {
List tests = []; List tests = [];
for (var i = 0; i < _suite.tests.length; i++) { for (var i = 0; i < _suite.group.entries.length; i++) {
Test test = _suite.tests[i]; // TODO(ianh): entries[] might return a Group instead of a Test. We don't
// currently support nested groups.
Test test = _suite.group.entries[i];
tests.add({ tests.add({
"name": test.name, "name": test.name,
"metadata": test.metadata.serialize(), "metadata": test.metadata.serialize(),
...@@ -118,7 +120,9 @@ class RemoteListener { ...@@ -118,7 +120,9 @@ class RemoteListener {
var message = JSON.decode(data); var message = JSON.decode(data);
if (message['command'] == 'run') { if (message['command'] == 'run') {
assert(_liveTest == null); assert(_liveTest == null);
Test test = _suite.tests[message['index']]; // TODO(ianh): entries[] might return a Group instead of a Test. We don't
// currently support nested groups.
Test test = _suite.group.entries[message['index']];
_liveTest = test.load(_suite); _liveTest = test.load(_suite);
_liveTest.onStateChange.listen((state) { _liveTest.onStateChange.listen((state) {
...@@ -148,6 +152,8 @@ class RemoteListener { ...@@ -148,6 +152,8 @@ class RemoteListener {
} else if (message['command'] == 'close') { } else if (message['command'] == 'close') {
_liveTest.close(); _liveTest.close();
_liveTest = null; _liveTest = null;
} else {
print('remote_listener.dart: ignoring command "${message["command"]}" from test harness');
} }
} }
} }
...@@ -7,18 +7,20 @@ import 'dart:async'; ...@@ -7,18 +7,20 @@ import 'dart:async';
import 'package:test/src/backend/live_test.dart'; import 'package:test/src/backend/live_test.dart';
import 'package:test/src/backend/live_test_controller.dart'; import 'package:test/src/backend/live_test_controller.dart';
import 'package:test/src/backend/metadata.dart'; import 'package:test/src/backend/metadata.dart';
import 'package:test/src/backend/operating_system.dart';
import 'package:test/src/backend/state.dart'; import 'package:test/src/backend/state.dart';
import 'package:test/src/backend/suite.dart'; import 'package:test/src/backend/suite.dart';
import 'package:test/src/backend/test.dart'; import 'package:test/src/backend/test.dart';
import 'package:test/src/backend/test_platform.dart';
import 'package:test/src/util/remote_exception.dart'; import 'package:test/src/util/remote_exception.dart';
import 'package:sky_tools/src/test/json_socket.dart'; import 'package:sky_tools/src/test/json_socket.dart';
class RemoteTest implements Test { class RemoteTest extends Test {
final String name; final String name;
final Metadata metadata; final Metadata metadata;
final Future<JSONSocket> _socket; final JSONSocket _socket;
final int _index; final int _index;
RemoteTest(this.name, this.metadata, this._socket, this._index); RemoteTest(this.name, this.metadata, this._socket, this._index);
...@@ -30,10 +32,9 @@ class RemoteTest implements Test { ...@@ -30,10 +32,9 @@ class RemoteTest implements Test {
controller = new LiveTestController(suite, this, () async { controller = new LiveTestController(suite, this, () async {
controller.setState(const State(Status.running, Result.success)); controller.setState(const State(Status.running, Result.success));
JSONSocket socket = await _socket; _socket.send({'command': 'run', 'index': _index});
socket.send({'command': 'run', 'index': _index});
subscription = socket.stream.listen((message) { subscription = _socket.stream.listen((message) {
if (message['type'] == 'error') { if (message['type'] == 'error') {
AsyncError asyncError = RemoteException.deserialize(message['error']); AsyncError asyncError = RemoteException.deserialize(message['error']);
controller.addError(asyncError.error, asyncError.stackTrace); controller.addError(asyncError.error, asyncError.stackTrace);
...@@ -52,8 +53,7 @@ class RemoteTest implements Test { ...@@ -52,8 +53,7 @@ class RemoteTest implements Test {
} }
}); });
}, () async { }, () async {
JSONSocket socket = await _socket; _socket.send({'command': 'close'});
socket.send({'command': 'close'});
if (subscription != null) { if (subscription != null) {
subscription.cancel(); subscription.cancel();
subscription = null; subscription = null;
...@@ -68,4 +68,10 @@ class RemoteTest implements Test { ...@@ -68,4 +68,10 @@ class RemoteTest implements Test {
if (metadata == null) metadata = this.metadata; if (metadata == null) metadata = this.metadata;
return new RemoteTest(name, metadata, _socket, _index); return new RemoteTest(name, metadata, _socket, _index);
} }
// TODO(ianh): Implement this if we need it.
Test forPlatform(TestPlatform platform, {OperatingSystem os}) {
assert(false);
return this;
}
} }
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
# Fast fail the script on failures. # Fast fail the script on failures.
set -e set -e
# Fetch all our dependencies
pub get
# Verify that the libraries are error free. # Verify that the libraries are error free.
pub global activate tuneup pub global activate tuneup
pub global run tuneup check pub global run tuneup check
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment