Skip to content

Commit

Permalink
fixes #292, report async_helper test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
John Messerly committed Aug 19, 2015
1 parent 8f9c38b commit 3806525
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 278 deletions.
14 changes: 10 additions & 4 deletions pkg/dev_compiler/test/browser/language_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
let _isolate_helper = dart_library.import('dart/_isolate_helper');
_isolate_helper.startRootIsolate(function() {}, []);

let async_helper = dart_library.import('async_helper/async_helper');

function dartLanguageTests(tests) {
for (const name of tests) {
test(name, () => {
console.debug('Running language test: ' + name);
test(name, (done) => {
async_helper.asyncTestInitialize(done);
console.debug('Running language test: ' + name);
dart_library.import('language/' + name).main();
if (!async_helper.asyncTestStarted) done();
});
}
}
Expand Down Expand Up @@ -48,7 +52,8 @@
'async_rethrow_test',
// TODO(jmesserly): fix errors
// 'async_return_types_test',
'async_switch_test',
// TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/294
// 'async_switch_test',
'async_test',
'async_this_bound_test',
'async_throw_in_catch_test'
Expand All @@ -63,7 +68,8 @@
//'async_star_cancel_and_throw_in_finally_test',
'async_star_regression_23116_test',
'asyncstar_concat_test',
'asyncstar_throw_in_catch_test',
// TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/294
// 'asyncstar_throw_in_catch_test',
'asyncstar_yield_test',
'asyncstar_yieldstar_test'
]);
Expand Down
35 changes: 25 additions & 10 deletions pkg/dev_compiler/test/codegen/async_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,44 @@
library async_helper;

// TODO(kustermann): This is problematic because we rely on a working
// 'dart:isolate' (i.e. it is in particular problematic with dart2js).
// It would be nice if we could use a different mechanism for different
// runtimes.
import 'dart:isolate';

bool _initialized = false;
ReceivePort _port = null;

typedef void _Action0();
_Action0 _onAsyncEnd;

int _asyncLevel = 0;

Exception _buildException(String msg) {
return new Exception('Fatal: $msg. This is most likely a bug in your test.');
}

/// Implementation method called from language_tests.js.
/// Registers the callback that will be used complete the test.
void asyncTestInitialize(_Action0 callback) {
_asyncLevel = 0;
_initialized = false;
_onAsyncEnd = callback;
}

/// Implementation method called from language_tests.js.
/// Returns true if an asyncTest was started.
bool get asyncTestStarted => _initialized;

/// Call this method before an asynchronous test is created.
void asyncStart() {
if (_initialized && _asyncLevel == 0) {
throw _buildException('asyncStart() was called even though we are done '
'with testing.');
}
if (!_initialized) {
if (_onAsyncEnd == null) {
throw _buildException(
'asyncStart() was called before asyncTestInitialize()');
}

print('unittest-suite-wait-for-done');
_initialized = true;
_port = new ReceivePort();

}
_asyncLevel++;
}
Expand All @@ -63,8 +77,9 @@ void asyncEnd() {
}
_asyncLevel--;
if (_asyncLevel == 0) {
_port.close();
_port = null;
var callback = _onAsyncEnd;
_onAsyncEnd = null;
callback();
print('unittest-suite-success');
}
}
Expand Down
29 changes: 22 additions & 7 deletions pkg/dev_compiler/test/codegen/expect/async_helper.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
dart_library.library('async_helper', null, /* Imports */[
"dart_runtime/dart",
'dart/core',
'dart/isolate'
'dart/core'
], /* Lazy imports */[
], function(exports, dart, core, isolate) {
], function(exports, dart, core) {
'use strict';
let dartx = dart.dartx;
exports._initialized = false;
exports._port = null;
let _Action0 = dart.typedef('_Action0', () => dart.functionType(dart.void, []));
exports._onAsyncEnd = null;
exports._asyncLevel = 0;
function _buildException(msg) {
return core.Exception.new(`Fatal: ${msg}. This is most likely a bug in your test.`);
}
dart.fn(_buildException, core.Exception, [core.String]);
function asyncTestInitialize(callback) {
exports._asyncLevel = 0;
exports._initialized = false;
exports._onAsyncEnd = callback;
}
dart.fn(asyncTestInitialize, dart.void, [_Action0]);
dart.copyProperties(exports, {
get asyncTestStarted() {
return exports._initialized;
}
});
function asyncStart() {
if (dart.notNull(exports._initialized) && exports._asyncLevel == 0) {
dart.throw(_buildException('asyncStart() was called even though we are done ' + 'with testing.'));
}
if (!dart.notNull(exports._initialized)) {
if (exports._onAsyncEnd == null) {
dart.throw(_buildException('asyncStart() was called before asyncTestInitialize()'));
}
core.print('unittest-suite-wait-for-done');
exports._initialized = true;
exports._port = isolate.ReceivePort.new();
}
exports._asyncLevel = dart.notNull(exports._asyncLevel) + 1;
}
Expand All @@ -35,8 +48,9 @@ dart_library.library('async_helper', null, /* Imports */[
}
exports._asyncLevel = dart.notNull(exports._asyncLevel) - 1;
if (exports._asyncLevel == 0) {
exports._port.close();
exports._port = null;
let callback = exports._onAsyncEnd;
exports._onAsyncEnd = null;
callback();
core.print('unittest-suite-success');
}
}
Expand All @@ -51,6 +65,7 @@ dart_library.library('async_helper', null, /* Imports */[
}
dart.fn(asyncTest, dart.void, [dart.functionType(dart.dynamic, [])]);
// Exports:
exports.asyncTestInitialize = asyncTestInitialize;
exports.asyncStart = asyncStart;
exports.asyncEnd = asyncEnd;
exports.asyncSuccess = asyncSuccess;
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/test/codegen/expect/async_helper.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Messages from compiling async_helper.dart
info: [DynamicInvoke] f().then(asyncSuccess) requires dynamic invoke (test/codegen/async_helper.dart, line 93, col 3)
info: [DynamicInvoke] f().then(asyncSuccess) requires dynamic invoke (test/codegen/async_helper.dart, line 108, col 3)
29 changes: 22 additions & 7 deletions pkg/dev_compiler/test/codegen/expect/async_helper/async_helper.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
dart_library.library('async_helper/async_helper', null, /* Imports */[
"dart_runtime/dart",
'dart/core',
'dart/isolate'
'dart/core'
], /* Lazy imports */[
], function(exports, dart, core, isolate) {
], function(exports, dart, core) {
'use strict';
let dartx = dart.dartx;
exports._initialized = false;
exports._port = null;
let _Action0 = dart.typedef('_Action0', () => dart.functionType(dart.void, []));
exports._onAsyncEnd = null;
exports._asyncLevel = 0;
function _buildException(msg) {
return core.Exception.new(`Fatal: ${msg}. This is most likely a bug in your test.`);
}
dart.fn(_buildException, core.Exception, [core.String]);
function asyncTestInitialize(callback) {
exports._asyncLevel = 0;
exports._initialized = false;
exports._onAsyncEnd = callback;
}
dart.fn(asyncTestInitialize, dart.void, [_Action0]);
dart.copyProperties(exports, {
get asyncTestStarted() {
return exports._initialized;
}
});
function asyncStart() {
if (dart.notNull(exports._initialized) && exports._asyncLevel == 0) {
dart.throw(_buildException('asyncStart() was called even though we are done ' + 'with testing.'));
}
if (!dart.notNull(exports._initialized)) {
if (exports._onAsyncEnd == null) {
dart.throw(_buildException('asyncStart() was called before asyncTestInitialize()'));
}
core.print('unittest-suite-wait-for-done');
exports._initialized = true;
exports._port = isolate.ReceivePort.new();
}
exports._asyncLevel = dart.notNull(exports._asyncLevel) + 1;
}
Expand All @@ -35,8 +48,9 @@ dart_library.library('async_helper/async_helper', null, /* Imports */[
}
exports._asyncLevel = dart.notNull(exports._asyncLevel) - 1;
if (exports._asyncLevel == 0) {
exports._port.close();
exports._port = null;
let callback = exports._onAsyncEnd;
exports._onAsyncEnd = null;
callback();
core.print('unittest-suite-success');
}
}
Expand All @@ -51,6 +65,7 @@ dart_library.library('async_helper/async_helper', null, /* Imports */[
}
dart.fn(asyncTest, dart.void, [dart.functionType(dart.dynamic, [])]);
// Exports:
exports.asyncTestInitialize = asyncTestInitialize;
exports.asyncStart = asyncStart;
exports.asyncEnd = asyncEnd;
exports.asyncSuccess = asyncSuccess;
Expand Down
Loading

0 comments on commit 3806525

Please sign in to comment.