diff --git a/pkg/unittest/lib/matcher.dart b/pkg/unittest/lib/matcher.dart deleted file mode 100644 index 3fd692e13440..000000000000 --- a/pkg/unittest/lib/matcher.dart +++ /dev/null @@ -1,12 +0,0 @@ -// 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. - -/// `unittest.matcher` has been moved to the `matcher` package. -/// -/// Add `matcher` to your `pubspec.yaml` file and import it via -/// `import 'package:matcher/matcher.dart';` -@deprecated -library unittest.matcher; - -export 'package:matcher/matcher.dart'; diff --git a/pkg/unittest/lib/mirror_matchers.dart b/pkg/unittest/lib/mirror_matchers.dart deleted file mode 100644 index d144554e0339..000000000000 --- a/pkg/unittest/lib/mirror_matchers.dart +++ /dev/null @@ -1,12 +0,0 @@ -// 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. - -/// `unittest.mirror_matchers` has been moved to the `matcher` package. -/// -/// Add `matcher` to your `pubspec.yaml` file and import it via -/// `import 'package:matcher/mirror_matchers.dart';` -@deprecated -library unittest.mirror_matchers; - -export 'package:matcher/mirror_matchers.dart'; diff --git a/pkg/unittest/lib/mock.dart b/pkg/unittest/lib/mock.dart deleted file mode 100644 index 18b6537cf218..000000000000 --- a/pkg/unittest/lib/mock.dart +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2012, 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. - -/// `unittest.mock` has been moved to the `mock` package. -/// -/// Add `mock` to your `pubspec.yaml` file and import it via -/// `import 'package:mock/mock.dart';` -@deprecated -library unittest.mock; - -export 'package:mock/mock.dart'; diff --git a/pkg/unittest/lib/src/configuration.dart b/pkg/unittest/lib/src/configuration.dart index 6893adca7535..ca901328cdc3 100644 --- a/pkg/unittest/lib/src/configuration.dart +++ b/pkg/unittest/lib/src/configuration.dart @@ -2,7 +2,9 @@ // 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. -part of unittest; +library unittest.configuration; + +import 'package:unittest/unittest.dart' show TestCase, SimpleConfiguration; /// Describes the interface used by the unit test system for communicating the /// results of a test run. diff --git a/pkg/unittest/lib/src/simple_configuration.dart b/pkg/unittest/lib/src/simple_configuration.dart index 1d9d46e073da..aa249778fa4a 100644 --- a/pkg/unittest/lib/src/simple_configuration.dart +++ b/pkg/unittest/lib/src/simple_configuration.dart @@ -121,7 +121,7 @@ class SimpleConfiguration extends Configuration { try { throw ''; } catch (_, stack) { - var trace = _getTrace(stack); + var trace = getTrace(stack, formatStacks, filterStacks); if (trace == null) trace = stack; _testLogBuffer.add(new Pair(reason, trace)); } diff --git a/pkg/unittest/lib/src/spread_args_helper.dart b/pkg/unittest/lib/src/spread_args_helper.dart index cf024f3565cc..9367201967c3 100644 --- a/pkg/unittest/lib/src/spread_args_helper.dart +++ b/pkg/unittest/lib/src/spread_args_helper.dart @@ -8,8 +8,6 @@ class _ArgPlaceHolder { } /// Simulates spread arguments using named arguments. -// TODO(sigmund): remove this class and simply use a closure with named -// arguments (if still applicable). class _SpreadArgsHelper { final Function callback; final int minExpectedCalls; diff --git a/pkg/unittest/lib/src/test_case.dart b/pkg/unittest/lib/src/test_case.dart index 0948e79e1979..03eafd290d62 100644 --- a/pkg/unittest/lib/src/test_case.dart +++ b/pkg/unittest/lib/src/test_case.dart @@ -120,7 +120,7 @@ class TestCase { // is the first time the result is being set. void _setResult(String testResult, String messageText, StackTrace stack) { _message = messageText; - _stackTrace = _getTrace(stack); + _stackTrace = getTrace(stack, formatStacks, filterStacks); if (_stackTrace == null) _stackTrace = stack; if (result == null) { _result = testResult; diff --git a/pkg/unittest/lib/src/utils.dart b/pkg/unittest/lib/src/utils.dart index 9aaae5b52c49..877cfb2263ba 100644 --- a/pkg/unittest/lib/src/utils.dart +++ b/pkg/unittest/lib/src/utils.dart @@ -4,43 +4,7 @@ library unittest.utils; -/// Returns the name of the type of [x], or "Unknown" if the type name can't be -/// determined. -String typeName(x) { - // dart2js blows up on some objects (e.g. window.navigator). - // So we play safe here. - try { - if (x == null) return "null"; - var type = x.runtimeType.toString(); - // TODO(nweiz): if the object's type is private, find a public superclass to - // display once there's a portable API to do that. - return type.startsWith("_") ? "?" : type; - } catch (e) { - return "?"; - } -} - -/// Returns [source] with any control characters replaced by their escape -/// sequences. -/// -/// This doesn't add quotes to the string, but it does escape single quote -/// characters so that single quotes can be applied externally. -String escapeString(String source) => - source.split("").map(_escapeChar).join(""); - -/// Return the escaped form of a character [ch]. -String _escapeChar(String ch) { - if (ch == "'") - return "\\'"; - else if (ch == '\n') - return '\\n'; - else if (ch == '\r') - return '\\r'; - else if (ch == '\t') - return '\\t'; - else - return ch; -} +import 'package:stack_trace/stack_trace.dart'; /// Indent each line in [str] by two spaces. String indent(String str) => @@ -63,3 +27,25 @@ class Pair { int get hashCode => first.hashCode ^ last.hashCode; } +/// Returns a Trace object from a StackTrace object or a String, or the +/// unchanged input if formatStacks is false; +Trace getTrace(stack, bool formatStacks, bool filterStacks) { + Trace trace; + if (stack == null || !formatStacks) return null; + if (stack is String) { + trace = new Trace.parse(stack); + } else if (stack is StackTrace) { + trace = new Trace.from(stack); + } else { + throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.'); + } + + if (!filterStacks) return trace; + + // Format the stack trace by removing everything above TestCase._runTest, + // which is usually going to be irrelevant. Also fold together unittest and + // core library calls so only the function the user called is visible. + return new Trace(trace.frames.takeWhile((frame) { + return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; + })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); +} diff --git a/pkg/unittest/lib/unittest.dart b/pkg/unittest/lib/unittest.dart index b736c6ec633e..05eca70f9fcc 100644 --- a/pkg/unittest/lib/unittest.dart +++ b/pkg/unittest/lib/unittest.dart @@ -137,7 +137,6 @@ library unittest; import 'dart:async'; import 'dart:collection'; import 'dart:isolate'; -import 'package:stack_trace/stack_trace.dart'; import 'package:matcher/matcher.dart' show DefaultFailureHandler, configureExpectFailureHandler, TestFailure, wrapAsync; @@ -145,9 +144,11 @@ export 'package:matcher/matcher.dart'; import 'src/utils.dart'; -part 'src/configuration.dart'; -part 'src/group_context.dart'; +import 'src/configuration.dart'; +export 'src/configuration.dart'; + part 'src/simple_configuration.dart'; +part 'src/group_context.dart'; part 'src/spread_args_helper.dart'; part 'src/test_case.dart'; @@ -300,30 +301,6 @@ Function expectAsync(Function callback, {int count: 1, int max: 0, String id}) => new _SpreadArgsHelper(callback, count, max, id).func; -/// *Deprecated* -/// -/// Use [expectAsync] instead. -@deprecated -Function expectAsync0(Function callback, - {int count: 1, int max: 0, String id}) => - expectAsync(callback, count: count, max: max, id: id); - -/// *Deprecated* -/// -/// Use [expectAsync] instead. -@deprecated -Function expectAsync1(Function callback, - {int count: 1, int max: 0, String id}) => - expectAsync(callback, count: count, max: max, id: id); - -/// *Deprecated* -/// -/// Use [expectAsync] instead. -@deprecated -Function expectAsync2(Function callback, - {int count: 1, int max: 0, String id}) => - expectAsync(callback, count: count, max: max, id: id); - /// Indicate that [callback] is expected to be called until [isDone] returns /// true. The unittest framework check [isDone] after each callback and only /// when it returns true will it continue with the following test. Using @@ -335,57 +312,6 @@ Function expectAsync2(Function callback, Function expectAsyncUntil(Function callback, bool isDone(), {String id}) => new _SpreadArgsHelper(callback, 0, -1, id, isDone: isDone).func; -/// *Deprecated* -/// -/// Use [expectAsyncUntil] instead. -@deprecated -Function expectAsyncUntil0(Function callback, Function isDone, {String id}) => - expectAsyncUntil(callback, isDone, id: id); - -/// *Deprecated* -/// -/// Use [expectAsyncUntil] instead. -@deprecated -Function expectAsyncUntil1(Function callback, Function isDone, {String id}) => - expectAsyncUntil(callback, isDone, id: id); - -/// *Deprecated* -/// -/// Use [expectAsyncUntil] instead. -@deprecated -Function expectAsyncUntil2(Function callback, Function isDone, {String id}) => - expectAsyncUntil(callback, isDone, id: id); - -/// *Deprecated* -/// -/// All tests are now run an isolated [Zone]. -/// -/// You can safely remove calls to this method. -@deprecated -Function protectAsync0(Function callback, {String id}) { - return callback; -} - -/// *Deprecated* -/// -/// All tests are now run an isolated [Zone]. -/// -/// You can safely remove calls to this method. -@deprecated -Function protectAsync1(Function callback, {String id}) { - return callback; -} - -/// *Deprecated* -/// -/// All tests are now run an isolated [Zone]. -/// -/// You can safely remove calls to this method. -@deprecated -Function protectAsync2(Function callback, {String id}) { - return callback; -} - /// Creates a new named group of tests. Calls to group() or test() within the /// body of the function passed to this will inherit this group's description. void group(String description, void body()) { @@ -488,16 +414,6 @@ void runTests() { _runTest(); } -/// *Deprecated* -/// -/// All tests are now run an isolated [Zone]. -/// -/// You can safely remove calls to this method. -@deprecated -guardAsync(Function tryBody) { - return tryBody(); -} - /// Registers that an exception was caught for the current test. void registerException(e, [trace]) { _registerException(currentTestCase, e, trace); @@ -646,26 +562,3 @@ void _requireNotRunning() { throw new StateError('Not allowed when tests are running.'); } } - -/// Returns a Trace object from a StackTrace object or a String, or the -/// unchanged input if formatStacks is false; -Trace _getTrace(stack) { - Trace trace; - if (stack == null || !formatStacks) return null; - if (stack is String) { - trace = new Trace.parse(stack); - } else if (stack is StackTrace) { - trace = new Trace.from(stack); - } else { - throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.'); - } - - if (!filterStacks) return trace; - - // Format the stack trace by removing everything above TestCase._runTest, - // which is usually going to be irrelevant. Also fold together unittest and - // core library calls so only the function the user called is visible. - return new Trace(trace.frames.takeWhile((frame) { - return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; - })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); -} diff --git a/pkg/unittest/pubspec.yaml b/pkg/unittest/pubspec.yaml index 0370e3533966..06083f5bceb2 100644 --- a/pkg/unittest/pubspec.yaml +++ b/pkg/unittest/pubspec.yaml @@ -1,5 +1,5 @@ name: unittest -version: 0.10.1+2 +version: 0.11.0-dev author: Dart Team description: A library for writing dart unit tests. homepage: http://www.dartlang.org @@ -8,5 +8,4 @@ environment: documentation: http://api.dartlang.org/docs/pkg/unittest dependencies: matcher: '>=0.10.0 <0.11.0' - mock: '>=0.10.0 <0.11.0' stack_trace: '>=0.9.0 <0.10.0'