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

Unified Diff: pkg/scheduled_test/test/scheduled_test_test.dart

Issue 12209073: Add a scheduled test library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make everything play nicely with the outside world. Created 7 years, 10 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
Index: pkg/scheduled_test/test/scheduled_test_test.dart
diff --git a/pkg/scheduled_test/test/scheduled_test_test.dart b/pkg/scheduled_test/test/scheduled_test_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..690319c613382ee020e402af6eb1591674c65f04
--- /dev/null
+++ b/pkg/scheduled_test/test/scheduled_test_test.dart
@@ -0,0 +1,644 @@
+// 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.
+
+library scheduled_test_test;
+
+import 'dart:async';
+
+import 'package:scheduled_test/scheduled_test.dart';
+import 'package:scheduled_test/src/utils.dart';
+import 'metatest.dart';
+
+void main() {
+ expectTestsPass('a scheduled test with a correct synchronous expectation '
+ 'should pass', () {
+ test('test', () {
+ expect('foo', equals('foo'));
+ });
+ });
+
+ expectTestsFail('a scheduled test with an incorrect synchronous expectation '
+ 'should fail', () {
+ test('test', () {
+ expect('foo', equals('bar'));
+ });
+ });
+
+ expectTestsPass('a scheduled test with a correct asynchronous expectation '
+ 'should pass', () {
+ test('test', () {
+ expect(new Future.immediate('foo'), completion(equals('foo')));
+ });
+ });
+
+ expectTestsFail('a scheduled test with an incorrect asynchronous expectation '
+ 'should fail', () {
+ test('test', () {
+ expect(new Future.immediate('foo'), completion(equals('bar')));
+ });
+ });
+
+ expectTestsPass('a passing scheduled synchronous expect should register', () {
+ test('test', () {
+ schedule(() => expect('foo', equals('foo')));
+ });
+ });
+
+ expectTestsFail('a failing scheduled synchronous expect should register', () {
+ test('test', () {
+ schedule(() => expect('foo', equals('bar')));
+ });
+ });
+
+ expectTestsPass('a passing scheduled asynchronous expect should '
+ 'register', () {
+ test('test', () {
+ schedule(() =>
+ expect(new Future.immediate('foo'), completion(equals('foo'))));
+ });
+ });
+
+ expectTestsFail('a failing scheduled synchronous expect should '
+ 'register', () {
+ test('test', () {
+ schedule(() =>
+ expect(new Future.immediate('foo'), completion(equals('bar'))));
+ });
+ });
+
+ expectTestsPass('scheduled blocks should be run in order after the '
+ 'synchronous setup', () {
+ test('test', () {
+ var list = [1];
+ schedule(() => list.add(2));
+ list.add(3);
+ schedule(() => expect(list, equals([1, 3, 4, 2])));
+ list.add(4);
+ });
+ });
+
+ expectTestsPass('scheduled blocks should forward their return values as '
+ 'Futures', () {
+ test('synchronous value', () {
+ var future = schedule(() => 'value');
+ expect(future, completion(equals('value')));
+ });
+
+ test('asynchronous value', () {
+ var future = schedule(() => new Future.immediate('value'));
+ expect(future, completion(equals('value')));
+ });
+ });
+
+ expectTestsPass('scheduled blocks should wait for their Future return values '
+ 'to complete before proceeding', () {
+ test('test', () {
+ var value = 'unset';
+ schedule(() => sleep(500).then((_) {
+ value = 'set';
+ }));
+ schedule(() => expect(value, equals('set')));
+ });
+ });
+
+ expectTestsFail('a test failure in a chained future in a scheduled block '
+ 'should be registered', () {
+ test('test', () {
+ schedule(() => new Future.immediate('foo')
+ .then((v) => expect(v, equals('bar'))));
+ });
+ });
+
+ expectTestsFail('an error in a chained future in a scheduled block should be '
+ 'registered', () {
+ test('test', () {
+ schedule(() => new Future.immediate(null).then((_) {
+ throw 'error';
+ }));
+ });
+ });
+
+ expectTestsFail('an out-of-band failure in wrapAsync is handled', () {
+ test('test', () {
+ schedule(() {
+ sleep(10).then(wrapAsync((_) => expect('foo', equals('bar'))));
+ });
+ schedule(() => sleep(50));
+ });
+ });
+
+ expectTestsFail('an out-of-band failure in wrapAsync that finishes after the '
+ 'schedule is handled', () {
+ test('test', () {
+ schedule(() {
+ sleep(50).then(wrapAsync((_) => expect('foo', equals('bar'))));
+ });
+ schedule(() => sleep(10));
+ });
+ });
+
+ expectTestsFail('an out-of-band error reported via signalError is '
+ 'handled', () {
+ test('test', () {
+ schedule(() {
+ sleep(10).then((_) => currentSchedule.signalError('bad'));
+ });
+ schedule(() => sleep(50));
+ });
+ });
+
+ expectTestsFail('an out-of-band error reported via signalError that finished '
+ 'after the schedule is handled', () {
+ test('test', () {
+ schedule(() {
+ var done = wrapAsync((_) {});
+ sleep(50).then((_) {
+ currentSchedule.signalError('bad');
+ done(null);
+ });
+ });
+ schedule(() => sleep(10));
+ });
+ });
+
+ expectTestsFail('a synchronous error reported via signalError is handled', () {
+ test('test', () {
+ currentSchedule.signalError('bad');
+ });
+ });
+
+ expectTestsPass('the onComplete queue is run if a test is successful', () {
+ var onCompleteRun = false;
+ test('test 1', () {
+ currentSchedule.onComplete.schedule(() {
+ onCompleteRun = true;
+ });
+
+ schedule(() => expect('foo', equals('foo')));
+ });
+
+ test('test 2', () {
+ expect(onCompleteRun, isTrue);
+ });
+ });
+
+ expectTestsPass('the onComplete queue is run after an out-of-band callback',
+ () {
+ var outOfBandRun = false;
+ test('test1', () {
+ currentSchedule.onComplete.schedule(() {
+ expect(outOfBandRun, isTrue);
+ });
+
+ sleep(50).then(wrapAsync((_) {
+ outOfBandRun = true;
+ }));
+ });
+ });
+
+ expectTestsPass('the onComplete queue is run after an out-of-band callback '
+ 'and waits for another out-of-band callback', () {
+ var outOfBand1Run = false;
+ var outOfBand2Run = false;
+ test('test1', () {
+ currentSchedule.onComplete.schedule(() {
+ expect(outOfBand1Run, isTrue);
+
+ sleep(50).then(wrapAsync((_) {
+ outOfBand2Run = true;
+ }));
+ });
+
+ sleep(50).then(wrapAsync((_) {
+ outOfBand1Run = true;
+ }));
+ });
+
+ test('test2', () => expect(outOfBand2Run, isTrue));
+ });
+
+ expectTestsFail('an out-of-band callback in the onComplete queue blocks the '
+ 'test', () {
+ var outOfBandRun = false;
+ test('test', () {
+ currentSchedule.onComplete.schedule(() {
+ sleep(50).then(wrapAsync((_) => expect('foo', equals('bar'))));
+ });
+ });
+ });
+
+ expectTestsPass('an out-of-band callback blocks onComplete even with an '
+ 'unrelated error', () {
+ var outOfBandRun = false;
+ var outOfBandSetInOnComplete = false;
+ test('test 1', () {
+ currentSchedule.onComplete.schedule(() {
+ outOfBandSetInOnComplete = outOfBandRun;
+ });
+
+ sleep(50).then(wrapAsync((_) {
+ outOfBandRun = true;
+ }));
+
+ schedule(() => expect('foo', equals('bar')));
+ });
+
+ test('test 2', () => expect(outOfBandSetInOnComplete, isTrue));
+ }, passing: ['test 2']);
+
+ expectTestsPass('the onComplete queue is run after an asynchronous error',
+ () {
+ var onCompleteRun = false;
+ test('test 1', () {
+ currentSchedule.onComplete.schedule(() {
+ onCompleteRun = true;
+ });
+
+ schedule(() => expect('foo', equals('bar')));
+ });
+
+ test('test 2', () {
+ expect(onCompleteRun, isTrue);
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('the onComplete queue is run after a synchronous error', () {
+ var onCompleteRun = false;
+ test('test 1', () {
+ currentSchedule.onComplete.schedule(() {
+ onCompleteRun = true;
+ });
+
+ throw 'error';
+ });
+
+ test('test 2', () {
+ expect(onCompleteRun, isTrue);
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('the onComplete queue is run after an out-of-band error', () {
+ var onCompleteRun = false;
+ test('test 1', () {
+ currentSchedule.onComplete.schedule(() {
+ onCompleteRun = true;
+ });
+
+ sleep(50).then(wrapAsync((_) => expect('foo', equals('bar'))));
+ });
+
+ test('test 2', () {
+ expect(onCompleteRun, isTrue);
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('currentSchedule.error contains the error in the onComplete '
+ 'queue', () {
+ var error;
+ test('test 1', () {
+ currentSchedule.onComplete.schedule(() {
+ error = currentSchedule.error;
+ });
+
+ throw 'error';
+ });
+
+ test('test 2', () {
+ expect(error, new isInstanceOf<ScheduleError>());
+ expect(error.error, equals('error'));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('onComplete tasks can be scheduled during normal tasks', () {
+ var onCompleteRun = false;
+ test('test 1', () {
+ schedule(() {
+ currentSchedule.onComplete.schedule(() {
+ onCompleteRun = true;
+ });
+ });
+ });
+
+ test('test 2', () {
+ expect(onCompleteRun, isTrue);
+ });
+ });
+
+ expectTestsFail('failures in onComplete cause test failures', () {
+ test('test', () {
+ currentSchedule.onComplete.schedule(() {
+ expect('foo', equals('bar'));
+ });
+ });
+ });
+
+ expectTestsPass('the onException queue is not run if a test is successful',
+ () {
+ var onExceptionRun = false;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ onExceptionRun = true;
+ });
+
+ schedule(() => expect('foo', equals('foo')));
+ });
+
+ test('test 2', () {
+ expect(onExceptionRun, isFalse);
+ });
+ });
+
+ expectTestsPass('the onException queue is run after an asynchronous error',
+ () {
+ var onExceptionRun = false;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ onExceptionRun = true;
+ });
+
+ schedule(() => expect('foo', equals('bar')));
+ });
+
+ test('test 2', () {
+ expect(onExceptionRun, isTrue);
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('the onException queue is run after a synchronous error', () {
+ var onExceptionRun = false;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ onExceptionRun = true;
+ });
+
+ throw 'error';
+ });
+
+ test('test 2', () {
+ expect(onExceptionRun, isTrue);
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('the onException queue is run after an out-of-band error', () {
+ var onExceptionRun = false;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ onExceptionRun = true;
+ });
+
+ sleep(50).then(wrapAsync((_) => expect('foo', equals('bar'))));
+ });
+
+ test('test 2', () {
+ expect(onExceptionRun, isTrue);
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('currentSchedule.error contains the error in the onException '
+ 'queue', () {
+ var error;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ error = currentSchedule.error;
+ });
+
+ throw 'error';
+ });
+
+ test('test 2', () {
+ expect(error, new isInstanceOf<ScheduleError>());
+ expect(error.error, equals('error'));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('currentSchedule.error contains an error passed into '
+ 'signalError synchronously', () {
+ var error;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ error = currentSchedule.error;
+ });
+
+ currentSchedule.signalError('error');
+ });
+
+ test('test 2', () {
+ expect(error, new isInstanceOf<ScheduleError>());
+ expect(error.error, equals('error'));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('currentSchedule.error contains an error passed into '
+ 'signalError asynchronously', () {
+ var error;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ error = currentSchedule.error;
+ });
+
+ schedule(() => currentSchedule.signalError('error'));
+ });
+
+ test('test 2', () {
+ expect(error, new isInstanceOf<ScheduleError>());
+ expect(error.error, equals('error'));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('currentSchedule.error contains an error passed into '
+ 'signalError out-of-band', () {
+ var error;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ error = currentSchedule.error;
+ });
+
+ sleep(50).then(wrapAsync((_) => currentSchedule.signalError('error')));
+ });
+
+ test('test 2', () {
+ expect(error, new isInstanceOf<ScheduleError>());
+ expect(error.error, equals('error'));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass('currentSchedule.currentTask returns the current task while '
+ 'executing a task', () {
+ test('test', () {
+ schedule(() => expect('foo', equals('foo')), 'task 1');
+
+ schedule(() {
+ expect(currentSchedule.currentTask.description, equals('task 2'));
+ }, 'task 2');
+
+ schedule(() => expect('bar', equals('bar')), 'task 3');
+ });
+ });
+
+ expectTestsPass('currentSchedule.currentTask is null before the schedule has '
+ 'started', () {
+ test('test', () {
+ schedule(() => expect('foo', equals('foo')));
+
+ expect(currentSchedule.currentTask, isNull);
+ });
+ });
+
+ expectTestsPass('currentSchedule.currentTask is null after the schedule has '
+ 'completed', () {
+ test('test', () {
+ expect(sleep(50).then((_) {
+ expect(currentSchedule.currentTask, isNull);
+ }), completes);
+
+ schedule(() => expect('foo', equals('foo')));
+ });
+ });
+
+ expectTestsPass('currentSchedule.currentQueue returns the current queue while '
+ 'executing a task', () {
+ test('test', () {
+ schedule(() {
+ expect(currentSchedule.currentQueue.name, equals('tasks'));
+ });
+ });
+ });
+
+ expectTestsPass('currentSchedule.currentQueue is null before the schedule has '
+ 'started', () {
+ test('test', () {
+ schedule(() => expect('foo', equals('foo')));
+
+ expect(currentSchedule.currentQueue, isNull);
+ });
+ });
+
+ expectTestsPass('setUp is run before each test', () {
+ var setUpRun = false;
+ setUp(() {
+ setUpRun = true;
+ });
+
+ test('test 1', () {
+ expect(setUpRun, isTrue);
+ setUpRun = false;
+ });
+
+ test('test 2', () {
+ expect(setUpRun, isTrue);
+ setUpRun = false;
+ });
+ });
+
+ expectTestsPass('setUp can schedule events', () {
+ var setUpRun = false;
+ setUp(() {
+ schedule(() {
+ setUpRun = true;
+ });
+ currentSchedule.onComplete.schedule(() {
+ setUpRun = false;
+ });
+ });
+
+ test('test 1', () {
+ expect(setUpRun, isFalse);
+ schedule(() => expect(setUpRun, isTrue));
+ });
+
+ test('test 2', () {
+ expect(setUpRun, isFalse);
+ schedule(() => expect(setUpRun, isTrue));
+ });
+ });
+
+ expectTestsFail('synchronous errors in setUp will cause tests to fail', () {
+ setUp(() => expect('foo', equals('bar')));
+ test('test 1', () => expect('foo', equals('foo')));
+ test('test 2', () => expect('foo', equals('foo')));
+ });
+
+ expectTestsFail('scheduled errors in setUp will cause tests to fail', () {
+ setUp(() => schedule(() => expect('foo', equals('bar'))));
+ test('test 1', () => expect('foo', equals('foo')));
+ test('test 2', () => expect('foo', equals('foo')));
+ });
+
+ expectTestsPass('synchronous errors in setUp will cause onException to run',
+ () {
+ var onExceptionRun = false;
+ setUp(() {
+ currentSchedule.onException.schedule(() {
+ onExceptionRun = true;
+ });
+
+ if (!onExceptionRun) expect('foo', equals('bar'));
+ });
+
+ test('test 1', () => expect('foo', equals('foo')));
+ test('test 2', () => expect(onExceptionRun, isTrue));
+ }, passing: ['test 2']);
+
+ expectTestsPass("setUp doesn't apply to child groups", () {
+ var setUpRun = false;
+ setUp(() {
+ setUpRun = true;
+ currentSchedule.onComplete.schedule(() {
+ setUpRun = false;
+ });
+ });
+
+ test('outer', () {
+ expect(setUpRun, isTrue);
+ });
+
+ group('group', () {
+ test('inner', () {
+ expect(setUpRun, isFalse);
+ });
+ });
+ });
+
+ expectTestsPass("setUp doesn't apply to parent groups", () {
+ var setUpRun = false;
+ group('group', () {
+ setUp(() {
+ setUpRun = true;
+ currentSchedule.onComplete.schedule(() {
+ setUpRun = false;
+ });
+ });
+
+ test('inner', () {
+ expect(setUpRun, isTrue);
+ });
+ });
+
+ test('outer', () {
+ expect(setUpRun, isFalse);
+ });
+ });
+
+ expectTestsPass("setUp doesn't apply to sibling groups", () {
+ var setUpRun = false;
+ group('group 1', () {
+ setUp(() {
+ setUpRun = true;
+ currentSchedule.onComplete.schedule(() {
+ setUpRun = false;
+ });
+ });
+
+ test('test 1', () {
+ expect(setUpRun, isTrue);
+ });
+ });
+
+ group('group 2', () {
+ test('test 2', () {
+ expect(setUpRun, isFalse);
+ });
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698