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 4ec073d794e5b6cf8bbade6c1134c10e45e067a2..26b7d1fd6abc2f82f7ede5a1fa3afc6cb4920c1b 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; |
| @@ -30,31 +29,36 @@ class TestCase { |
| set tearDown(Function value) => _tearDown = value; |
|
gram
2013/03/13 16:35:58
I think I have been guilty of this myself, but acc
Siggi Cherem (dart-lang)
2013/03/13 16:46:04
yep - if you expose both read and write access, it
|
| /** The body of the test case. */ |
| - TestFunction test; |
| + TestFunction testFunction; |
| /** |
| * 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; |
| @@ -62,8 +66,7 @@ class TestCase { |
| Completer _testComplete; |
| - TestCase(this.id, this.description, this.test, |
| - this.callbackFunctionsOutstanding) |
| + TestCase._internal(this.id, this.description, this.testFunction) |
| : currentGroup = _currentGroup, |
| _setUp = _testSetup, |
| _tearDown = _testTeardown; |
| @@ -72,8 +75,8 @@ class TestCase { |
| void _prepTest() { |
| _config.onTestStart(this); |
| - startTime = new DateTime.now(); |
| - runningTime = null; |
| + _startTime = new DateTime.now(); |
| + _runningTime = null; |
| } |
| Future _runTest() { |
| @@ -81,9 +84,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 = testFunction(); |
| + --_callbackFunctionsOutstanding; |
| if (f is Future) { |
| f.then((_) => _finishTest()) |
| .catchError((e) => fail("${e.error}")); |
| @@ -95,22 +98,22 @@ class TestCase { |
| } |
| void _finishTest() { |
| - if (result == null && callbackFunctionsOutstanding == 0) { |
| + 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) { |
| @@ -147,13 +150,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); |
| } |
| } |
| @@ -162,7 +165,7 @@ class TestCase { |
| [String messageText = '', |
| String stack = '']) { |
| if (runningTime == null) { |
| - runningTime = new DateTime.now().difference(startTime); |
| + _runningTime = new DateTime.now().difference(startTime); |
| } |
| _setResult(testResult, messageText, stack); |
| if (!_doneTeardown) { |
| @@ -207,8 +210,8 @@ class TestCase { |
| _complete(ERROR, messageText, stack); |
| } |
| - void markCallbackComplete() { |
| - if (--callbackFunctionsOutstanding == 0 && !isComplete) { |
| + void _markCallbackComplete() { |
| + if (--_callbackFunctionsOutstanding == 0 && !isComplete) { |
| pass(); |
| } |
| } |