mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:10:22 +00:00
starting to work on unit test config interface
R=gram@google.com Review URL: https://codereview.chromium.org//22883008 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26215 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
4247f504cc
commit
179c810f8a
|
@ -200,7 +200,7 @@ final _singleton = new _MetaConfiguration();
|
|||
|
||||
/// Special test configuration for use within the child isolates. This hides all
|
||||
/// output and reports data back to the parent isolate.
|
||||
class _MetaConfiguration extends Configuration {
|
||||
class _MetaConfiguration extends SimpleConfiguration {
|
||||
final name = "MetaConfiguration";
|
||||
|
||||
void logTestCaseMesssage(TestCase testCase, String message) {}
|
||||
|
|
|
@ -95,7 +95,7 @@ String _htmlEscape(String string) {
|
|||
.replaceAll('>','>');
|
||||
}
|
||||
|
||||
class HtmlConfiguration extends Configuration {
|
||||
class HtmlConfiguration extends SimpleConfiguration {
|
||||
/** Whether this is run within dartium layout tests. */
|
||||
final bool _isLayoutTest;
|
||||
HtmlConfiguration(this._isLayoutTest);
|
||||
|
|
|
@ -15,7 +15,7 @@ import 'dart:collection' show LinkedHashMap;
|
|||
import 'dart:html';
|
||||
import 'unittest.dart';
|
||||
|
||||
class HtmlEnhancedConfiguration extends Configuration {
|
||||
class HtmlEnhancedConfiguration extends SimpleConfiguration {
|
||||
/** Whether this is run within dartium layout tests. */
|
||||
final bool _isLayoutTest;
|
||||
HtmlEnhancedConfiguration(this._isLayoutTest);
|
||||
|
|
|
@ -64,7 +64,7 @@ class _Message {
|
|||
}
|
||||
|
||||
|
||||
class HtmlConfiguration extends Configuration {
|
||||
class HtmlConfiguration extends SimpleConfiguration {
|
||||
StreamSubscription _errorSubscription;
|
||||
|
||||
void _installErrorHandler() {
|
||||
|
|
76
pkg/unittest/lib/src/configuration.dart
Normal file
76
pkg/unittest/lib/src/configuration.dart
Normal file
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2011, 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.
|
||||
|
||||
part of unittest;
|
||||
|
||||
/**
|
||||
* Describes the interface used by the unit test system for communicating the
|
||||
* results of a test run.
|
||||
*/
|
||||
abstract class Configuration {
|
||||
|
||||
/**
|
||||
* Creates an instance of [SimpleConfiguration].
|
||||
*/
|
||||
factory Configuration() => new SimpleConfiguration();
|
||||
|
||||
/**
|
||||
* If [true], tests are started automatically. Otherwise [runTests]
|
||||
* must be called explicitly after tests are set up.
|
||||
*/
|
||||
bool get autoStart;
|
||||
|
||||
/**
|
||||
* Called as soon as the unittest framework becomes initialized. This is done
|
||||
* even before tests are added to the test framework. It might be used to
|
||||
* determine/debug errors that occur before the test harness starts executing.
|
||||
* It is also used to tell the vm or browser that tests are going to be run
|
||||
* asynchronously and that the process should wait until they are done.
|
||||
*/
|
||||
void onInit();
|
||||
|
||||
/** Called as soon as the unittest framework starts running. */
|
||||
void onStart() {}
|
||||
|
||||
/**
|
||||
* Called when each test starts. Useful to show intermediate progress on
|
||||
* a test suite.
|
||||
*/
|
||||
void onTestStart(TestCase testCase);
|
||||
|
||||
/**
|
||||
* Called when each test is first completed. Useful to show intermediate
|
||||
* progress on a test suite.
|
||||
*/
|
||||
void onTestResult(TestCase testCase);
|
||||
|
||||
/**
|
||||
* Called when an already completed test changes state. For example: a test
|
||||
* that was marked as passing may later be marked as being in error because
|
||||
* it still had callbacks being invoked.
|
||||
*/
|
||||
void onTestResultChanged(TestCase testCase);
|
||||
|
||||
/**
|
||||
* Handles the logging of messages by a test case.
|
||||
*/
|
||||
void onLogMessage(TestCase testCase, String message);
|
||||
|
||||
/**
|
||||
* Called when the unittest framework is done running. [success] indicates
|
||||
* whether all tests passed successfully.
|
||||
*/
|
||||
void onDone(bool success);
|
||||
|
||||
/**
|
||||
* Called with the result of all test cases. Browser tests commonly override
|
||||
* this to reformat the output.
|
||||
*
|
||||
* When [uncaughtError] is not null, it contains an error that occured outside
|
||||
* of tests (e.g. setting up the test).
|
||||
*/
|
||||
void onSummary(int passed, int failed, int errors, List<TestCase> results,
|
||||
String uncaughtError);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// 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.
|
||||
|
||||
|
@ -7,9 +7,9 @@ part of unittest;
|
|||
// A custom failure handler for [expect] that routes expect failures
|
||||
// to the config.
|
||||
class _ExpectFailureHandler extends DefaultFailureHandler {
|
||||
Configuration _config;
|
||||
final SimpleConfiguration _config;
|
||||
|
||||
_ExpectFailureHandler(this._config) : super();
|
||||
_ExpectFailureHandler(this._config);
|
||||
|
||||
void fail(String reason) {
|
||||
_config.onExpectFailure(reason);
|
||||
|
@ -22,8 +22,7 @@ class _ExpectFailureHandler extends DefaultFailureHandler {
|
|||
* advantage of the platform can create a subclass and override methods from
|
||||
* this class.
|
||||
*/
|
||||
|
||||
class Configuration {
|
||||
class SimpleConfiguration implements Configuration {
|
||||
// The VM won't shut down if a receive port is open. Use this to make sure
|
||||
// we correctly wait for asynchronous tests.
|
||||
ReceivePort _receivePort;
|
||||
|
@ -35,11 +34,7 @@ class Configuration {
|
|||
*/
|
||||
final String name = 'Configuration';
|
||||
|
||||
/**
|
||||
* If true, then tests are started automatically (otherwise [runTests]
|
||||
* must be called explicitly after the tests are set up.
|
||||
*/
|
||||
final bool autoStart = true;
|
||||
bool get autoStart => true;
|
||||
|
||||
/**
|
||||
* If true (the default), throw an exception at the end if any tests failed.
|
||||
|
@ -61,22 +56,15 @@ class Configuration {
|
|||
* The constructor sets up a failure handler for [expect] that redirects
|
||||
* [expect] failures to [onExpectFailure].
|
||||
*/
|
||||
Configuration() {
|
||||
SimpleConfiguration() {
|
||||
configureExpectFailureHandler(new _ExpectFailureHandler(this));
|
||||
}
|
||||
/**
|
||||
* Called as soon as the unittest framework becomes initialized. This is done
|
||||
* even before tests are added to the test framework. It might be used to
|
||||
* determine/debug errors that occur before the test harness starts executing.
|
||||
* It is also used to tell the vm or browser that tests are going to be run
|
||||
* asynchronously and that the process should wait until they are done.
|
||||
*/
|
||||
|
||||
void onInit() {
|
||||
_receivePort = new ReceivePort();
|
||||
_postMessage('unittest-suite-wait-for-done');
|
||||
}
|
||||
|
||||
/** Called as soon as the unittest framework starts running. */
|
||||
void onStart() {}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +79,7 @@ class Configuration {
|
|||
|
||||
/**
|
||||
* Called when each test is first completed. Useful to show intermediate
|
||||
* progress on a test suite. Derived classes should call this first
|
||||
* progress on a test suite. Derived classes should call this first
|
||||
* before their own override code.
|
||||
*/
|
||||
void onTestResult(TestCase testCase) {
|
||||
|
@ -112,25 +100,20 @@ class Configuration {
|
|||
if (testCase.result == PASS) {
|
||||
testCase._result = FAIL;
|
||||
testCase._message = reason.toString();
|
||||
// Use the last stack as the overall failure stack.
|
||||
// Use the last stack as the overall failure stack.
|
||||
testCase._stackTrace = lastReasonAndTrace.last;
|
||||
} else {
|
||||
// Add the last stack to the message; we have a further stack
|
||||
// caused by some other failure.
|
||||
reason.write(lastReasonAndTrace.last);
|
||||
reason.write('\n');
|
||||
// Add the existing reason to the end of the expect log to
|
||||
// Add the existing reason to the end of the expect log to
|
||||
// create the final message.
|
||||
testCase._message = '${reason.toString()}\n${testCase._message}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an already completed test changes state; for example a test
|
||||
* that was marked as passing may later be marked as being in error because
|
||||
* it still had callbacks being invoked.
|
||||
*/
|
||||
void onTestResultChanged(TestCase testCase) {
|
||||
assert(testCase != null);
|
||||
}
|
||||
|
@ -159,7 +142,7 @@ class Configuration {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a test result.
|
||||
*/
|
||||
|
@ -213,10 +196,6 @@ class Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the unittest framework is done running. [success] indicates
|
||||
* whether all tests passed successfully.
|
||||
*/
|
||||
void onDone(bool success) {
|
||||
if (success) {
|
||||
_postMessage('unittest-suite-success');
|
||||
|
@ -229,13 +208,7 @@ class Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
/** Handle errors that happen outside the tests. */
|
||||
// TODO(vsm): figure out how to expose the stack trace here
|
||||
// Currently e.message works in dartium, but not in dartc.
|
||||
void handleExternalError(e, String message, [stack]) =>
|
||||
_reportTestError('$message\nCaught $e', stack);
|
||||
|
||||
_postMessage(String message) {
|
||||
void _postMessage(String message) {
|
||||
// In dart2js browser tests, the JavaScript-based test controller
|
||||
// intercepts calls to print and listens for "secret" messages.
|
||||
print(message);
|
|
@ -146,13 +146,15 @@ library unittest;
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:isolate';
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'matcher.dart';
|
||||
export 'matcher.dart';
|
||||
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'src/utils.dart';
|
||||
part 'src/config.dart';
|
||||
|
||||
part 'src/configuration.dart';
|
||||
part 'src/simple_configuration.dart';
|
||||
part 'src/test_case.dart';
|
||||
|
||||
Configuration _config;
|
||||
|
@ -656,16 +658,16 @@ void _nextTestCase() {
|
|||
_runTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function that can be used to notify the test framework that an
|
||||
* error was caught outside of this library.
|
||||
*/
|
||||
void _reportTestError(String msg, trace) {
|
||||
if (_currentTestCaseIndex < testCases.length) {
|
||||
final testCase = testCases[_currentTestCaseIndex];
|
||||
testCase.error(msg, trace);
|
||||
/** Handle errors that happen outside the tests. */
|
||||
// TODO(vsm): figure out how to expose the stack trace here
|
||||
// Currently e.message works in dartium, but not in dartc.
|
||||
void handleExternalError(e, String message, [stack]) {
|
||||
var msg = '$message\nCaught $e';
|
||||
|
||||
if (currentTestCase != null) {
|
||||
currentTestCase.error(msg, stack);
|
||||
} else {
|
||||
_uncaughtErrorMessage = "$msg: $trace";
|
||||
_uncaughtErrorMessage = "$msg: $stack";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import 'dart:async';
|
|||
import 'dart:io';
|
||||
import 'unittest.dart';
|
||||
|
||||
class VMConfiguration extends Configuration {
|
||||
class VMConfiguration extends SimpleConfiguration {
|
||||
// Color constants used for generating messages.
|
||||
final String GREEN_COLOR = '\u001b[32m';
|
||||
final String RED_COLOR = '\u001b[31m';
|
||||
|
|
|
@ -33,7 +33,7 @@ String buildStatusString(int passed, int failed, int errors,
|
|||
'$setup:$teardown:$uncaughtError$testDetails';
|
||||
}
|
||||
|
||||
class TestConfiguration extends Configuration {
|
||||
class TestConfiguration extends SimpleConfiguration {
|
||||
|
||||
// Some test state that is captured.
|
||||
int count = 0; // A count of callbacks.
|
||||
|
|
|
@ -41,7 +41,7 @@ Function action;
|
|||
/**
|
||||
* A special marker string used to separate group names and
|
||||
* identify non-debug output.
|
||||
*/
|
||||
*/
|
||||
final marker = '###';
|
||||
|
||||
class Macros {
|
||||
|
@ -53,7 +53,7 @@ class Macros {
|
|||
static const String testStacktrace = '<STACK>';
|
||||
}
|
||||
|
||||
class TestRunnerConfiguration extends Configuration {
|
||||
class TestRunnerConfiguration extends SimpleConfiguration {
|
||||
get name => 'Minimal test runner configuration';
|
||||
get autoStart => false;
|
||||
|
||||
|
@ -191,7 +191,7 @@ listTests() {
|
|||
|
||||
// Support for running in isolates.
|
||||
|
||||
class TestRunnerChildConfiguration extends Configuration {
|
||||
class TestRunnerChildConfiguration extends SimpleConfiguration {
|
||||
get name => 'Test runner child configuration';
|
||||
get autoStart => false;
|
||||
|
||||
|
|
Loading…
Reference in a new issue