From f07e3a3cc8dc7fc05f3965c8d69247f3373c7dcc Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum <nweiz@google.com> Date: Thu, 12 Feb 2015 15:12:02 -0800 Subject: [PATCH] Get new tests working on dart2js. This fixes tests that don't require dart:io and marks those that do dart:io as Skip. R=kevmoo@google.com Review URL: https://codereview.chromium.org//918853005 --- .status | 5 +++++ lib/src/invoker.dart | 7 +++++-- test/io.dart | 24 ++++++++++++++++++++++++ test/loader_test.dart | 1 + test/utils.dart | 17 ----------------- 5 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 test/io.dart diff --git a/.status b/.status index 4f6b6fd5..6d836348 100644 --- a/.status +++ b/.status @@ -20,6 +20,11 @@ lib/*/*: Skip lib/*/*/*: Skip lib/*/*/*/*: Skip +# dart:io-specific tests. +[ $browser ] +build/test/loader_test: SkipByDesign +built/test/vm_listener_test: SkipByDesign + [ $runtime == jsshell ] build/test/missing_tick_test: Fail # Timer interface not supported: dartbug.com/7728 build/test/nested_groups_setup_teardown_test: RuntimeError # http://dartbug.com/10109 diff --git a/lib/src/invoker.dart b/lib/src/invoker.dart index 5950500d..4d14b48d 100644 --- a/lib/src/invoker.dart +++ b/lib/src/invoker.dart @@ -69,7 +69,10 @@ class Invoker { /// The current invoker, or `null` if none is defined. /// /// An invoker is only set within the zone scope of a running test. - static Invoker get current => Zone.current[#unittest._invoker]; + static Invoker get current { + // TODO(nweiz): Use a private symbol when dart2js supports it (issue 17526). + return Zone.current[#unittest.invoker]; + } Invoker._(Suite suite, LocalTest test) { _controller = new LiveTestController(suite, test, _onRun); @@ -171,7 +174,7 @@ class Invoker { new State(Status.complete, liveTest.state.result)); _controller.completer.complete(); }); - }, zoneValues: {#unittest._invoker: this}, onError: handleError); + }, zoneValues: {#unittest.invoker: this}, onError: handleError); }); } } diff --git a/test/io.dart b/test/io.dart new file mode 100644 index 00000000..3868981c --- /dev/null +++ b/test/io.dart @@ -0,0 +1,24 @@ +// Copyright (c) 2015, 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. + +library unittest.test.io; + +import 'dart:io'; + +import 'package:path/path.dart' as p; +import 'package:stack_trace/stack_trace.dart'; + +/// The root directory of the `unittest` package. +final String packageDir = _computePackageDir(); +String _computePackageDir() { + var trace = new Trace.current(); + return p.dirname(p.dirname(p.fromUri(trace.frames.first.uri))); +} + +/// Returns a matcher that matches a [FileSystemException] with the given +/// [message]. +Matcher isFileSystemException(String message) => predicate( + (error) => error is FileSystemException && error.message == message, + 'is a FileSystemException with message "$message"'); + diff --git a/test/loader_test.dart b/test/loader_test.dart index 643e6b0b..95a4a8b1 100644 --- a/test/loader_test.dart +++ b/test/loader_test.dart @@ -11,6 +11,7 @@ import 'package:unittest/src/loader.dart'; import 'package:unittest/src/state.dart'; import 'package:unittest/unittest.dart'; +import 'io.dart'; import 'utils.dart'; Loader _loader; diff --git a/test/utils.dart b/test/utils.dart index 88845833..f9b4075d 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -6,10 +6,6 @@ library unittest.test.utils; import 'dart:async'; import 'dart:collection'; -import 'dart:io'; - -import 'package:path/path.dart' as p; -import 'package:stack_trace/stack_trace.dart'; import 'package:unittest/src/live_test.dart'; import 'package:unittest/src/remote_exception.dart'; @@ -19,13 +15,6 @@ import 'package:unittest/unittest.dart'; // The last state change detected via [expectStates]. State lastState; -final String packageDir = _computePackageDir(); - -String _computePackageDir() { - var trace = new Trace.current(); - return p.dirname(p.dirname(p.fromUri(trace.frames.first.uri))); -} - /// Asserts that exactly [states] will be emitted via [liveTest.onStateChange]. /// /// The most recent emitted state is stored in [_lastState]. @@ -82,12 +71,6 @@ Matcher isRemoteException(String message) => predicate( (error) => error is RemoteException && error.message == message, 'is a RemoteException with message "$message"'); -/// Returns a matcher that matches a [FileSystemException] with the given -/// [message]. -Matcher isFileSystemException(String message) => predicate( - (error) => error is FileSystemException && error.message == message, - 'is a FileSystemException with message "$message"'); - /// Returns a [Future] that completes after pumping the event queue [times] /// times. /// -- GitLab