Chromium Code Reviews| Index: pkg/unittest/lib/src/test_case.dart |
| diff --git a/pkg/unittest/lib/src/test_case.dart b/pkg/unittest/lib/src/test_case.dart |
| index da85f80aace195c3b9bfd7772a3f09a3b9a634be..bfe59b43c4f8ddf44e6b0196b00f9e905131f4d7 100644 |
| --- a/pkg/unittest/lib/src/test_case.dart |
| +++ b/pkg/unittest/lib/src/test_case.dart |
| @@ -1,15 +1,14 @@ |
| -// 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. |
| part of unittest; |
| /** |
| - * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] |
| - * and assumes unittest defines the type [TestFunction]. |
| + * Represents the state for an individual unit test. |
| + * |
| + * Create by calling [test] or [solo_test]. |
| */ |
| - |
| -/** Summarizes information about a single test case. */ |
| class TestCase { |
| /** Identifier for this test. */ |
| final int id; |
| @@ -18,52 +17,51 @@ class TestCase { |
| final String description; |
| /** The setup function to call before the test, if any. */ |
| - Function _setUp; |
| - |
| - Function get setUp => _setUp; |
| - set setUp(Function value) => _setUp = value; |
| + final Function _setUp; |
| /** The teardown function to call after the test, if any. */ |
| - Function _tearDown; |
| - |
| - Function get tearDown => _tearDown; |
| - set tearDown(Function value) => _tearDown = value; |
| + final Function _tearDown; |
| /** The body of the test case. */ |
| - TestFunction test; |
| + final TestFunction _test; |
| /** |
| * Remaining number of callbacks functions that must reach a 'done' state |
| * to wait for before the test completes. |
| */ |
| - int callbackFunctionsOutstanding; |
| + int _callbackFunctionsOutstanding = 0; |
| + String _message = ''; |
| /** Error or failure message. */ |
| - String message = ''; |
| + String get message => _message; |
| + String _result; |
| /** |
| * One of [PASS], [FAIL], [ERROR], or [null] if the test hasn't run yet. |
| */ |
| - String result; |
| + String get result => _result; |
| - /** Stack trace associated with this test, or null if it succeeded. */ |
| - String stackTrace; |
| + String _stackTrace; |
| + /** Stack trace associated with this test, or [null] if it succeeded. */ |
| + String get stackTrace => _stackTrace; |
| /** The group (or groups) under which this test is running. */ |
| final String currentGroup; |
| - DateTime startTime; |
| + DateTime _startTime; |
| + DateTime get startTime => _startTime; |
| - Duration runningTime; |
| + Duration _runningTime; |
| + Duration get runningTime => _runningTime; |
| - bool enabled = true; |
| + bool _enabled = true; |
| + bool get enabled => _enabled; |
| bool _doneTeardown = false; |
| Completer _testComplete; |
| - TestCase(this.id, this.description, this.test, |
| - this.callbackFunctionsOutstanding) |
| + TestCase._internal(this.id, this.description, this._test) |
| : currentGroup = _currentGroup, |
| _setUp = _testSetup, |
| _tearDown = _testTeardown; |
| @@ -72,8 +70,8 @@ class TestCase { |
| void _prepTest() { |
| _config.onTestStart(this); |
| - startTime = new DateTime.now(); |
| - runningTime = null; |
| + _startTime = new DateTime.now(); |
| + _runningTime = null; |
| } |
| Future _runTest() { |
| @@ -81,9 +79,9 @@ class TestCase { |
| // Increment/decrement callbackFunctionsOutstanding to prevent |
| // synchronous 'async' callbacks from causing the test to be |
| // marked as complete before the body is completely executed. |
| - ++callbackFunctionsOutstanding; |
| - var f = test(); |
| - --callbackFunctionsOutstanding; |
| + ++_callbackFunctionsOutstanding; |
| + var f = _test(); |
| + --_callbackFunctionsOutstanding; |
| if (f is Future) { |
| f.then((_) => _finishTest()) |
| .catchError((e) => fail("${e.error}")); |
| @@ -95,22 +93,22 @@ class TestCase { |
| } |
| void _finishTest() { |
| - if (result == null && callbackFunctionsOutstanding == 0) { |
| - pass(); |
| + if (result == null && _callbackFunctionsOutstanding == 0) { |
| + _pass(); |
| } |
| } |
| /** |
| - * Perform any associated [setUp] function and run the test. Returns |
| + * Perform any associated [_setUp] function and run the test. Returns |
| * a [Future] that can be used to schedule the next test. If the test runs |
| - * to completion synchronously, or is disabled, we return null, to |
| + * to completion synchronously, or is disabled, null is returned, to |
| * tell unittest to schedule the next test immediately. |
| */ |
| - Future run() { |
| + Future _run() { |
| if (!enabled) return null; |
| - result = stackTrace = null; |
| - message = ''; |
| + _result = _stackTrace = null; |
| + _message = ''; |
| _doneTeardown = false; |
| var rtn = _setUp == null ? null : _setUp(); |
| if (rtn is Future) { |
| @@ -120,9 +118,9 @@ class TestCase { |
| // Calling error() will result in the tearDown being done. |
| // One could debate whether tearDown should be done after |
| // a failed setUp. There is no right answer, but doing it |
| - // seems to be the more conservative approach, because |
| + // seems to be the more conservative approach, because |
| // unittest will not stop at a test failure. |
| - error("$description: Test setup failed: ${e.error}"); |
| + _error("$description: Test setup failed: ${e.error}"); |
| }); |
| } else { |
| var f = _runTest(); |
| @@ -147,13 +145,13 @@ class TestCase { |
| // Set the results, notify the config, and return true if this |
| // is the first time the result is being set. |
| void _setResult(String testResult, String messageText, String stack) { |
| - message = messageText; |
| - stackTrace = stack; |
| + _message = messageText; |
| + _stackTrace = stack; |
| if (result == null) { |
| - result = testResult; |
| + _result = testResult; |
| _config.onTestResult(this); |
| } else { |
| - result = testResult; |
| + _result = testResult; |
| _config.onTestResultChanged(this); |
| } |
| } |
| @@ -164,8 +162,8 @@ class TestCase { |
| if (runningTime == null) { |
| // TODO(gram): currently the duration measurement code is blocked |
| // by issue 4437. When that is fixed replace the line below with: |
| - // runningTime = new DateTime.now().difference(startTime); |
| - runningTime = new Duration(milliseconds: 0); |
| + // runningTime = |
| + _runningTime = new Duration(milliseconds: 0); |
| } |
| _setResult(testResult, messageText, stack); |
| if (!_doneTeardown) { |
| @@ -190,11 +188,11 @@ class TestCase { |
| _notifyComplete(); |
| } |
| - void pass() { |
| + void _pass() { |
| _complete(PASS); |
| } |
| - void fail(String messageText, [String stack = '']) { |
| + void _fail(String messageText, [String stack = '']) { |
| if (result != null) { |
|
gram
2013/03/05 18:07:41
I know that somewhere I have seen code like curren
|
| String newMessage = (result == PASS) |
| ? 'Test failed after initially passing: $messageText' |
| @@ -206,13 +204,13 @@ class TestCase { |
| } |
| } |
| - void error(String messageText, [String stack = '']) { |
| + void _error(String messageText, [String stack = '']) { |
| _complete(ERROR, messageText, stack); |
| } |
| - void markCallbackComplete() { |
| - if (--callbackFunctionsOutstanding == 0 && !isComplete) { |
| - pass(); |
| + void _markCallbackComplete() { |
| + if (--_callbackFunctionsOutstanding == 0 && !isComplete) { |
| + _pass(); |
| } |
| } |
| } |