Skip to content

Commit

Permalink
pkg/unittest: remove deprecated features
Browse files Browse the repository at this point in the history
R=sigmund@google.com

Review URL: https://codereview.chromium.org//270943002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@35954 260f80e4-7a28-3924-810f-c04153c831b5
  • Loading branch information
kevmoo committed May 9, 2014
1 parent 86d01fb commit d60ad1a
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 191 deletions.
12 changes: 0 additions & 12 deletions pkg/unittest/lib/matcher.dart

This file was deleted.

12 changes: 0 additions & 12 deletions pkg/unittest/lib/mirror_matchers.dart

This file was deleted.

12 changes: 0 additions & 12 deletions pkg/unittest/lib/mock.dart

This file was deleted.

4 changes: 3 additions & 1 deletion pkg/unittest/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/unittest/lib/src/simple_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, StackTrace>(reason, trace));
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/unittest/lib/src/spread_args_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pkg/unittest/lib/src/test_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 23 additions & 37 deletions pkg/unittest/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -63,3 +27,25 @@ class Pair<E, F> {
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);
}
115 changes: 4 additions & 111 deletions pkg/unittest/lib/unittest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,18 @@ 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;
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';

Expand Down Expand Up @@ -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
Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
3 changes: 1 addition & 2 deletions pkg/unittest/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: unittest
version: 0.10.1+2
version: 0.11.0-dev
author: Dart Team <misc@dartlang.org>
description: A library for writing dart unit tests.
homepage: http://www.dartlang.org
Expand All @@ -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'

0 comments on commit d60ad1a

Please sign in to comment.