Skip to content

Commit d60ad1a

Browse files
committed
pkg/unittest: remove deprecated features
[email protected] 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
1 parent 86d01fb commit d60ad1a

10 files changed

+33
-191
lines changed

pkg/unittest/lib/matcher.dart

-12
This file was deleted.

pkg/unittest/lib/mirror_matchers.dart

-12
This file was deleted.

pkg/unittest/lib/mock.dart

-12
This file was deleted.

pkg/unittest/lib/src/configuration.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of unittest;
5+
library unittest.configuration;
6+
7+
import 'package:unittest/unittest.dart' show TestCase, SimpleConfiguration;
68

79
/// Describes the interface used by the unit test system for communicating the
810
/// results of a test run.

pkg/unittest/lib/src/simple_configuration.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class SimpleConfiguration extends Configuration {
121121
try {
122122
throw '';
123123
} catch (_, stack) {
124-
var trace = _getTrace(stack);
124+
var trace = getTrace(stack, formatStacks, filterStacks);
125125
if (trace == null) trace = stack;
126126
_testLogBuffer.add(new Pair<String, StackTrace>(reason, trace));
127127
}

pkg/unittest/lib/src/spread_args_helper.dart

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class _ArgPlaceHolder {
88
}
99

1010
/// Simulates spread arguments using named arguments.
11-
// TODO(sigmund): remove this class and simply use a closure with named
12-
// arguments (if still applicable).
1311
class _SpreadArgsHelper {
1412
final Function callback;
1513
final int minExpectedCalls;

pkg/unittest/lib/src/test_case.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TestCase {
120120
// is the first time the result is being set.
121121
void _setResult(String testResult, String messageText, StackTrace stack) {
122122
_message = messageText;
123-
_stackTrace = _getTrace(stack);
123+
_stackTrace = getTrace(stack, formatStacks, filterStacks);
124124
if (_stackTrace == null) _stackTrace = stack;
125125
if (result == null) {
126126
_result = testResult;

pkg/unittest/lib/src/utils.dart

+23-37
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,7 @@
44

55
library unittest.utils;
66

7-
/// Returns the name of the type of [x], or "Unknown" if the type name can't be
8-
/// determined.
9-
String typeName(x) {
10-
// dart2js blows up on some objects (e.g. window.navigator).
11-
// So we play safe here.
12-
try {
13-
if (x == null) return "null";
14-
var type = x.runtimeType.toString();
15-
// TODO(nweiz): if the object's type is private, find a public superclass to
16-
// display once there's a portable API to do that.
17-
return type.startsWith("_") ? "?" : type;
18-
} catch (e) {
19-
return "?";
20-
}
21-
}
22-
23-
/// Returns [source] with any control characters replaced by their escape
24-
/// sequences.
25-
///
26-
/// This doesn't add quotes to the string, but it does escape single quote
27-
/// characters so that single quotes can be applied externally.
28-
String escapeString(String source) =>
29-
source.split("").map(_escapeChar).join("");
30-
31-
/// Return the escaped form of a character [ch].
32-
String _escapeChar(String ch) {
33-
if (ch == "'")
34-
return "\\'";
35-
else if (ch == '\n')
36-
return '\\n';
37-
else if (ch == '\r')
38-
return '\\r';
39-
else if (ch == '\t')
40-
return '\\t';
41-
else
42-
return ch;
43-
}
7+
import 'package:stack_trace/stack_trace.dart';
448

459
/// Indent each line in [str] by two spaces.
4610
String indent(String str) =>
@@ -63,3 +27,25 @@ class Pair<E, F> {
6327
int get hashCode => first.hashCode ^ last.hashCode;
6428
}
6529

30+
/// Returns a Trace object from a StackTrace object or a String, or the
31+
/// unchanged input if formatStacks is false;
32+
Trace getTrace(stack, bool formatStacks, bool filterStacks) {
33+
Trace trace;
34+
if (stack == null || !formatStacks) return null;
35+
if (stack is String) {
36+
trace = new Trace.parse(stack);
37+
} else if (stack is StackTrace) {
38+
trace = new Trace.from(stack);
39+
} else {
40+
throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.');
41+
}
42+
43+
if (!filterStacks) return trace;
44+
45+
// Format the stack trace by removing everything above TestCase._runTest,
46+
// which is usually going to be irrelevant. Also fold together unittest and
47+
// core library calls so only the function the user called is visible.
48+
return new Trace(trace.frames.takeWhile((frame) {
49+
return frame.package != 'unittest' || frame.member != 'TestCase._runTest';
50+
})).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore);
51+
}

pkg/unittest/lib/unittest.dart

+4-111
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ library unittest;
137137
import 'dart:async';
138138
import 'dart:collection';
139139
import 'dart:isolate';
140-
import 'package:stack_trace/stack_trace.dart';
141140

142141
import 'package:matcher/matcher.dart' show DefaultFailureHandler,
143142
configureExpectFailureHandler, TestFailure, wrapAsync;
144143
export 'package:matcher/matcher.dart';
145144

146145
import 'src/utils.dart';
147146

148-
part 'src/configuration.dart';
149-
part 'src/group_context.dart';
147+
import 'src/configuration.dart';
148+
export 'src/configuration.dart';
149+
150150
part 'src/simple_configuration.dart';
151+
part 'src/group_context.dart';
151152
part 'src/spread_args_helper.dart';
152153
part 'src/test_case.dart';
153154

@@ -300,30 +301,6 @@ Function expectAsync(Function callback,
300301
{int count: 1, int max: 0, String id}) =>
301302
new _SpreadArgsHelper(callback, count, max, id).func;
302303

303-
/// *Deprecated*
304-
///
305-
/// Use [expectAsync] instead.
306-
@deprecated
307-
Function expectAsync0(Function callback,
308-
{int count: 1, int max: 0, String id}) =>
309-
expectAsync(callback, count: count, max: max, id: id);
310-
311-
/// *Deprecated*
312-
///
313-
/// Use [expectAsync] instead.
314-
@deprecated
315-
Function expectAsync1(Function callback,
316-
{int count: 1, int max: 0, String id}) =>
317-
expectAsync(callback, count: count, max: max, id: id);
318-
319-
/// *Deprecated*
320-
///
321-
/// Use [expectAsync] instead.
322-
@deprecated
323-
Function expectAsync2(Function callback,
324-
{int count: 1, int max: 0, String id}) =>
325-
expectAsync(callback, count: count, max: max, id: id);
326-
327304
/// Indicate that [callback] is expected to be called until [isDone] returns
328305
/// true. The unittest framework check [isDone] after each callback and only
329306
/// when it returns true will it continue with the following test. Using
@@ -335,57 +312,6 @@ Function expectAsync2(Function callback,
335312
Function expectAsyncUntil(Function callback, bool isDone(), {String id}) =>
336313
new _SpreadArgsHelper(callback, 0, -1, id, isDone: isDone).func;
337314

338-
/// *Deprecated*
339-
///
340-
/// Use [expectAsyncUntil] instead.
341-
@deprecated
342-
Function expectAsyncUntil0(Function callback, Function isDone, {String id}) =>
343-
expectAsyncUntil(callback, isDone, id: id);
344-
345-
/// *Deprecated*
346-
///
347-
/// Use [expectAsyncUntil] instead.
348-
@deprecated
349-
Function expectAsyncUntil1(Function callback, Function isDone, {String id}) =>
350-
expectAsyncUntil(callback, isDone, id: id);
351-
352-
/// *Deprecated*
353-
///
354-
/// Use [expectAsyncUntil] instead.
355-
@deprecated
356-
Function expectAsyncUntil2(Function callback, Function isDone, {String id}) =>
357-
expectAsyncUntil(callback, isDone, id: id);
358-
359-
/// *Deprecated*
360-
///
361-
/// All tests are now run an isolated [Zone].
362-
///
363-
/// You can safely remove calls to this method.
364-
@deprecated
365-
Function protectAsync0(Function callback, {String id}) {
366-
return callback;
367-
}
368-
369-
/// *Deprecated*
370-
///
371-
/// All tests are now run an isolated [Zone].
372-
///
373-
/// You can safely remove calls to this method.
374-
@deprecated
375-
Function protectAsync1(Function callback, {String id}) {
376-
return callback;
377-
}
378-
379-
/// *Deprecated*
380-
///
381-
/// All tests are now run an isolated [Zone].
382-
///
383-
/// You can safely remove calls to this method.
384-
@deprecated
385-
Function protectAsync2(Function callback, {String id}) {
386-
return callback;
387-
}
388-
389315
/// Creates a new named group of tests. Calls to group() or test() within the
390316
/// body of the function passed to this will inherit this group's description.
391317
void group(String description, void body()) {
@@ -488,16 +414,6 @@ void runTests() {
488414
_runTest();
489415
}
490416

491-
/// *Deprecated*
492-
///
493-
/// All tests are now run an isolated [Zone].
494-
///
495-
/// You can safely remove calls to this method.
496-
@deprecated
497-
guardAsync(Function tryBody) {
498-
return tryBody();
499-
}
500-
501417
/// Registers that an exception was caught for the current test.
502418
void registerException(e, [trace]) {
503419
_registerException(currentTestCase, e, trace);
@@ -646,26 +562,3 @@ void _requireNotRunning() {
646562
throw new StateError('Not allowed when tests are running.');
647563
}
648564
}
649-
650-
/// Returns a Trace object from a StackTrace object or a String, or the
651-
/// unchanged input if formatStacks is false;
652-
Trace _getTrace(stack) {
653-
Trace trace;
654-
if (stack == null || !formatStacks) return null;
655-
if (stack is String) {
656-
trace = new Trace.parse(stack);
657-
} else if (stack is StackTrace) {
658-
trace = new Trace.from(stack);
659-
} else {
660-
throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.');
661-
}
662-
663-
if (!filterStacks) return trace;
664-
665-
// Format the stack trace by removing everything above TestCase._runTest,
666-
// which is usually going to be irrelevant. Also fold together unittest and
667-
// core library calls so only the function the user called is visible.
668-
return new Trace(trace.frames.takeWhile((frame) {
669-
return frame.package != 'unittest' || frame.member != 'TestCase._runTest';
670-
})).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore);
671-
}

pkg/unittest/pubspec.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: unittest
2-
version: 0.10.1+2
2+
version: 0.11.0-dev
33
author: Dart Team <[email protected]>
44
description: A library for writing dart unit tests.
55
homepage: http://www.dartlang.org
@@ -8,5 +8,4 @@ environment:
88
documentation: http://api.dartlang.org/docs/pkg/unittest
99
dependencies:
1010
matcher: '>=0.10.0 <0.11.0'
11-
mock: '>=0.10.0 <0.11.0'
1211
stack_trace: '>=0.9.0 <0.10.0'

0 commit comments

Comments
 (0)