| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] | 6 * testcase.dart: this file is sourced by unittest.dart. It defines [TestCase] |
| 7 * and assumes unittest defines the type [TestFunction]. | 7 * and assumes unittest defines the type [TestFunction]. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** Summarizes information about a single test case. */ | 10 /** Summarizes information about a single test case. */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 /** The group (or groups) under which this test is running. */ | 50 /** The group (or groups) under which this test is running. */ |
| 51 final String currentGroup; | 51 final String currentGroup; |
| 52 | 52 |
| 53 Date startTime; | 53 Date startTime; |
| 54 | 54 |
| 55 Duration runningTime; | 55 Duration runningTime; |
| 56 | 56 |
| 57 bool enabled = true; | 57 bool enabled = true; |
| 58 | 58 |
| 59 bool running = false; |
| 60 |
| 59 bool _doneTeardown = false; | 61 bool _doneTeardown = false; |
| 60 | 62 |
| 61 TestCase(this.id, this.description, this.test, | 63 TestCase(this.id, this.description, this.test, |
| 62 this.callbackFunctionsOutstanding) | 64 this.callbackFunctionsOutstanding) |
| 63 : currentGroup = _currentGroup, | 65 : currentGroup = _currentGroup, |
| 64 _setUp = _testSetup, | 66 _setUp = _testSetup, |
| 65 _tearDown = _testTeardown; | 67 _tearDown = _testTeardown; |
| 66 | 68 |
| 67 bool get isComplete => !enabled || result != null; | 69 bool get isComplete => !enabled || result != null; |
| 68 | 70 |
| 69 void run() { | 71 void run() { |
| 70 if (enabled) { | 72 if (enabled) { |
| 73 running = true; |
| 71 result = stackTrace = null; | 74 result = stackTrace = null; |
| 72 message = ''; | 75 message = ''; |
| 73 _doneTeardown = false; | 76 _doneTeardown = false; |
| 74 if (_setUp != null) { | 77 if (_setUp != null) { |
| 75 _setUp(); | 78 _setUp(); |
| 76 } | 79 } |
| 77 _config.onTestStart(this); | 80 _config.onTestStart(this); |
| 78 startTime = new Date.now(); | 81 startTime = new Date.now(); |
| 79 runningTime = null; | 82 runningTime = null; |
| 80 test(); | 83 test(); |
| 81 } | 84 } |
| 82 } | 85 } |
| 83 | 86 |
| 84 void _complete() { | 87 void _complete() { |
| 85 if (runningTime == null) { | 88 if (runningTime == null) { |
| 86 // TODO(gram): currently the duration measurement code is blocked | 89 // TODO(gram): currently the duration measurement code is blocked |
| 87 // by issue 4437. When that is fixed replace the line below with: | 90 // by issue 4437. When that is fixed replace the line below with: |
| 88 // runningTime = new Date.now().difference(startTime); | 91 // runningTime = new Date.now().difference(startTime); |
| 89 runningTime = new Duration(milliseconds:0); | 92 runningTime = new Duration(milliseconds:0); |
| 90 } | 93 } |
| 91 if (!_doneTeardown) { | 94 if (!_doneTeardown) { |
| 92 if (_tearDown != null) { | 95 if (_tearDown != null) { |
| 93 _tearDown(); | 96 _tearDown(); |
| 94 } | 97 } |
| 95 _doneTeardown = true; | 98 _doneTeardown = true; |
| 96 } | 99 } |
| 100 running = false; |
| 97 _config.onTestResult(this); | 101 _config.onTestResult(this); |
| 98 } | 102 } |
| 99 | 103 |
| 100 void pass() { | 104 void pass() { |
| 101 result = _PASS; | 105 result = _PASS; |
| 102 _complete(); | 106 _complete(); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void fail(String messageText, String stack) { | 109 void fail(String messageText, String stack) { |
| 106 if (result != null) { | 110 if (result != null) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 117 } | 121 } |
| 118 } | 122 } |
| 119 | 123 |
| 120 void error(String messageText, String stack) { | 124 void error(String messageText, String stack) { |
| 121 result = _ERROR; | 125 result = _ERROR; |
| 122 message = messageText; | 126 message = messageText; |
| 123 stackTrace = stack; | 127 stackTrace = stack; |
| 124 _complete(); | 128 _complete(); |
| 125 } | 129 } |
| 126 } | 130 } |
| OLD | NEW |