Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1240)

Unified Diff: pkg/unittest/lib/unittest.dart

Issue 142023005: throw when group or test is called while unittest system is running (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nits Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/unittest/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/unittest.dart
diff --git a/pkg/unittest/lib/unittest.dart b/pkg/unittest/lib/unittest.dart
index eae5a13b65fdfc2c70f06d687d481a3eb6b1d9db..f85b136e4056f49cef4e26b1b7ecfe6fdac04102 100644
--- a/pkg/unittest/lib/unittest.dart
+++ b/pkg/unittest/lib/unittest.dart
@@ -279,7 +279,7 @@ class _GroupContext {
final _rootContext = new _GroupContext();
_GroupContext _currentContext = _rootContext;
-int _currentTestCaseIndex = 0;
+int _currentTestCaseIndex = -1;
Siggi Cherem (dart-lang) 2014/01/30 23:39:01 There is a lot of implicit state encoded in 'curre
kevmoo 2014/01/30 23:42:04 I introduced the currentIndex model a while back.
Siggi Cherem (dart-lang) 2014/01/30 23:46:33 I'm not convinced :), but lets at least add some d
kevmoo 2014/01/31 02:27:37 Done.
/** [TestCase] currently being executed. */
TestCase get currentTestCase =>
@@ -313,6 +313,7 @@ const ERROR = 'error';
* calls.
*/
void test(String spec, TestFunction body) {
+ _requireNotRunning();
ensureInitialized();
if (!_soloTestSeen || _soloNestingLevel > 0) {
var testcase = new TestCase._internal(testCases.length + 1, _fullSpec(spec),
@@ -341,6 +342,7 @@ void skip_test(String spec, TestFunction body){}
* fact that they are effectively no-ops.
*/
void solo_test(String spec, TestFunction body) {
+ _requireNotRunning();
ensureInitialized();
if (!_soloTestSeen) {
_soloTestSeen = true;
@@ -584,6 +586,7 @@ Function protectAsync2(Function callback, {String id}) {
*/
void group(String description, void body()) {
ensureInitialized();
+ _requireNotRunning();
_currentContext = new _GroupContext(_currentContext, description);
try {
body();
@@ -601,6 +604,7 @@ void skip_group(String description, void body()) {}
/** Like [solo_test], but for groups. */
void solo_group(String description, void body()) {
+ _requireNotRunning();
ensureInitialized();
if (!_soloTestSeen) {
_soloTestSeen = true;
@@ -623,6 +627,7 @@ void solo_group(String description, void body()) {
* case it must return a [Future].
*/
void setUp(Function setupTest) {
+ _requireNotRunning();
_currentContext.testSetup = setupTest;
}
@@ -635,6 +640,7 @@ void setUp(Function setupTest) {
* case it must return a [Future].
*/
void tearDown(Function teardownTest) {
+ _requireNotRunning();
_currentContext.testTeardown = teardownTest;
}
@@ -683,6 +689,7 @@ void filterTests(testFilter) {
/** Runs all queued tests, one at a time. */
void runTests() {
+ _requireNotRunning();
_ensureInitialized(false);
_currentTestCaseIndex = 0;
_config.onStart();
@@ -734,12 +741,14 @@ void _registerException(TestCase testCase, e, [trace]) {
*/
void _runTest() {
if (_currentTestCaseIndex >= testCases.length) {
+ assert(_currentTestCaseIndex == testCases.length);
_completeTests();
} else {
- final testCase = testCases[_currentTestCaseIndex];
- var f = _guardAsync(testCase._run, null, testCase);
+ var testCase = testCases[_currentTestCaseIndex];
+ Future f = _guardAsync(testCase._run, null, testCase);
Siggi Cherem (dart-lang) 2014/01/30 23:44:30 Future -> var
kevmoo 2014/01/31 02:27:37 This one is intentional. _guardAsync return dynami
+ var timeout = unittestConfiguration.timeout;
+
Timer timer;
- final Duration timeout = unittestConfiguration.timeout;
if (timeout != null) {
try {
timer = new Timer(timeout, () {
@@ -782,6 +791,7 @@ void _completeTests() {
_config.onDone(passed > 0 && failed == 0 && errors == 0 &&
_uncaughtErrorMessage == null);
_initialized = false;
+ _currentTestCaseIndex = -1;
}
String _fullSpec(String spec) {
@@ -858,6 +868,12 @@ bool formatStacks = true;
*/
bool filterStacks = true;
+void _requireNotRunning() {
+ if(_currentTestCaseIndex != -1) {
+ throw new StateError('Not allowed when tests are running.');
+ }
+}
+
/**
* Returns a Trace object from a StackTrace object or a String, or the
* unchanged input if formatStacks is false;
« no previous file with comments | « no previous file | pkg/unittest/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698