From a1a91eb9155ce2ac8a6f4890311c67333bb83b82 Mon Sep 17 00:00:00 2001 From: "floitsch@google.com" Date: Wed, 28 Aug 2013 09:24:50 +0000 Subject: [PATCH] Add async_helper package. This package is private and should not be published to pub (nor should its documentation be published to api.dartlang.org). R=kustermann@google.com Review URL: https://codereview.chromium.org//23547005 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26774 260f80e4-7a28-3924-810f-c04153c831b5 --- pkg/async_helper/lib/async_helper.dart | 63 ++++++++++++++++++++++++++ pkg/async_helper/pubspec.yaml | 9 ++++ tools/publish_all_pkgs.py | 4 +- utils/apidoc/apidoc.gyp | 1 + 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 pkg/async_helper/lib/async_helper.dart create mode 100644 pkg/async_helper/pubspec.yaml diff --git a/pkg/async_helper/lib/async_helper.dart b/pkg/async_helper/lib/async_helper.dart new file mode 100644 index 00000000000..f1a84b369f7 --- /dev/null +++ b/pkg/async_helper/lib/async_helper.dart @@ -0,0 +1,63 @@ +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// This library is used for testing asynchronous tests. +/// If a test is asynchronous, it needs to notify the testing driver +/// about this (otherwise tests may get reported as passing [after main() +/// finished] even if the asynchronous operations fail). +/// Tests which can't use the unittest framework should use the helper functions +/// in this library. +/// This library provides two methods +/// - asyncStart(): Needs to be called before an asynchronous operation is +/// scheduled. +/// - asyncEnd(): Needs to be called as soon as the asynchronous operation +/// ended. +/// After the last asyncStart() called was matched with a corresponding +/// asyncEnd() call, the testing driver will be notified that the tests is done. + +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; +int _asyncLevel = 0; + +Exception _buildException(String msg) { + return new Exception('Fatal: $msg. This is most likely a bug in your test.'); +} + +void asyncStart() { + if (_initialized && _asyncLevel == 0) { + throw _buildException('asyncStart() was called even though we are done ' + 'with testing.'); + } + if (!_initialized) { + print('unittest-suite-wait-for-done'); + _initialized = true; + _port = new ReceivePort(); + } + _asyncLevel++; +} + +void asyncEnd() { + if (_asyncLevel <= 0) { + if (!_initialized) { + throw _buildException('asyncEnd() was called before asyncStart().'); + } else { + throw _buildException('asyncEnd() was called more often than ' + 'asyncStart().'); + } + } + _asyncLevel--; + if (_asyncLevel == 0) { + _port.close(); + _port = null; + print('unittest-suite-success'); + } +} diff --git a/pkg/async_helper/pubspec.yaml b/pkg/async_helper/pubspec.yaml new file mode 100644 index 00000000000..e4f33dea1b9 --- /dev/null +++ b/pkg/async_helper/pubspec.yaml @@ -0,0 +1,9 @@ +name: async_helper +author: "Dart Team " +homepage: http://www.dartlang.org +description: > + Async_helper is used for asynchronous tests that do not want to + make use of the Dart unittest library - for example, the core + language tests. + Third parties are discouraged from using this, and should use + the facilities provided in the unittest library. diff --git a/tools/publish_all_pkgs.py b/tools/publish_all_pkgs.py index 81aab97e4d4..a43f57b1613 100644 --- a/tools/publish_all_pkgs.py +++ b/tools/publish_all_pkgs.py @@ -17,11 +17,13 @@ import os.path import subprocess import sys +BLACK_LISTED_DIRECTORIES = ['.svn', 'async_helper', 'expect', 'third_party']; + def Main(argv): for pkgdir in ['pkg', 'pkg/third_party']: for name in os.listdir(pkgdir): if os.path.isdir(os.path.join(pkgdir, name)): - if (name != '.svn' and name != 'expect' and name != 'third_party'): + if name not in BLACK_LISTED_DIRECTORIES: pkgs_to_publish.append(os.path.join(pkgdir, name)) for pkg in pkgs_to_publish: diff --git a/utils/apidoc/apidoc.gyp b/utils/apidoc/apidoc.gyp index fad6410dce6..e19f080c2d3 100644 --- a/utils/apidoc/apidoc.gyp +++ b/utils/apidoc/apidoc.gyp @@ -85,6 +85,7 @@ '--package-root=<(PRODUCT_DIR)/packages', '--mode=static', '--exclude-lib=analyzer_experimental', + '--exclude-lib=async_helper', '--exclude-lib=barback', '--exclude-lib=browser', '--exclude-lib=dartdoc',