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

Side by Side Diff: tests/lib/unittest/unittest_test.dart

Issue 10832058: Improved the way we generate mismatch descriptions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/unittest/matchers_test.dart ('k') | utils/tests/pub/version_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // TODO(gram): 5 // TODO(gram):
6 // Unfortunately I can't seem to test anything that involves timeouts, e.g. 6 // Unfortunately I can't seem to test anything that involves timeouts, e.g.
7 // insufficient callbacks, because the timeout is controlled externally 7 // insufficient callbacks, because the timeout is controlled externally
8 // (test.dart?), and we would need to use a shorter timeout for the inner tests 8 // (test.dart?), and we would need to use a shorter timeout for the inner tests
9 // so the outer timeout doesn't fire. So I removed all such tests. 9 // so the outer timeout doesn't fire. So I removed all such tests.
10 // I'd like to revisit this at some point. 10 // I'd like to revisit this at some point.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 TestConfiguration(this._port); 65 TestConfiguration(this._port);
66 66
67 void onDone(int passed, int failed, int errors, List<TestCase> results, 67 void onDone(int passed, int failed, int errors, List<TestCase> results,
68 String uncaughtError) { 68 String uncaughtError) {
69 var result = buildStatusString(passed, failed, errors, results, count, 69 var result = buildStatusString(passed, failed, errors, results, count,
70 setup, teardown, uncaughtError); 70 setup, teardown, uncaughtError);
71 _port.send(result); 71 _port.send(result);
72 } 72 }
73 } 73 }
74
75 class MockList extends Mock implements List {
76 }
77
78 class Foo {
79 sum(a, b, c) => a + b + c;
80 }
81
82 class FooSpy extends Mock implements Foo {
83 Foo real;
84 FooSpy() {
85 real = new Foo();
86 this.when(callsTo('sum')).alwaysCall(real.sum);
87 }
88 }
89
90 makeTestLogEntry(String methodName, List args, int time,
91 [String mockName]) {
92 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE);
93 e.time = new Date.fromMillisecondsSinceEpoch(time, true);
94 return e;
95 }
96
97 makeTestLog() {
98 LogEntryList log = new LogEntryList('test');
99 List args = new List();
100 log.add(makeTestLogEntry('a', args, 1000));
101 log.add(makeTestLogEntry('b', args, 2000));
102 log.add(makeTestLogEntry('c', args, 3000));
103 return log;
104 }
105
106 runTest() { 74 runTest() {
107 port.receive((testName, sendport) { 75 port.receive((testName, sendport) {
108 configure(_testconfig = new TestConfiguration(sendport)); 76 configure(_testconfig = new TestConfiguration(sendport));
109 if (testName == 'single correct test') { 77 if (testName == 'single correct test') {
110 test(testName, () => expect(2 + 3, equals(5))); 78 test(testName, () => expect(2 + 3, equals(5)));
111 } else if (testName == 'single failing test') { 79 } else if (testName == 'single failing test') {
112 test(testName, () => expect(2 + 2, equals(5))); 80 test(testName, () => expect(2 + 2, equals(5)));
113 } else if (testName == 'exception test') { 81 } else if (testName == 'exception test') {
114 test(testName, () { throw new Exception('Fail.'); }); 82 test(testName, () { throw new Exception('Fail.'); });
115 } else if (testName == 'group name test') { 83 } else if (testName == 'group name test') {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 test(testName, () { 116 test(testName, () {
149 var _callback; 117 var _callback;
150 _callback = expectAsyncUntil0(() { 118 _callback = expectAsyncUntil0(() {
151 if (++_testconfig.count < 10) { 119 if (++_testconfig.count < 10) {
152 _defer(_callback); 120 _defer(_callback);
153 } 121 }
154 }, 122 },
155 () => (_testconfig.count == 10)); 123 () => (_testconfig.count == 10));
156 _defer(_callback); 124 _defer(_callback);
157 }); 125 });
158 } else if (testName.startsWith('mock test 1 ')) {
159 test(testName, () {
160 var m = new Mock();
161 print(m.length);
162 m.getLogs(callsTo('get length')).verify(happenedOnce);
163
164 m.when(callsTo('foo', 1, 2)).thenReturn('A').thenReturn('B');
165 m.when(callsTo('foo', 1, 1)).thenReturn('C');
166 m.when(callsTo('foo', 9, anything)).thenReturn('D');
167 m.when(callsTo('bar', anything, anything)).thenReturn('E');
168 m.when(callsTo('foobar')).thenReturn('F');
169
170 var s = '${m.foo(1,2)}${m.foo(1,1)}${m.foo(9,10)}'
171 '${m.bar(1,1)}${m.foo(1,2)}';
172 m.getLogs(callsTo('foo', anything, anything)).
173 verify(happenedExactly(4));
174 m.getLogs(callsTo('foo', 1, anything)).verify(happenedExactly(3));
175 m.getLogs(callsTo('foo', 9, anything)).verify(happenedOnce);
176 m.getLogs(callsTo('foo', anything, 2)).verify(happenedExactly(2));
177 m.getLogs(callsTo('foobar')).verify(neverHappened);
178 m.getLogs(callsTo('foo', 10, anything)).verify(neverHappened);
179 m.getLogs(callsTo('foo'), returning(anyOf('A', 'C'))).
180 verify(happenedExactly(2));
181 expect(s, 'ACDEB');
182 });
183 } else if (testName.startsWith('mock test 2 ')) {
184 test(testName, () {
185 var l = new MockList();
186 l.when(callsTo('get length')).thenReturn(1);
187 l.when(callsTo('add', anything)).alwaysReturn(0);
188 l.add('foo');
189 expect(l.length, 1);
190
191 var m = new MockList();
192 m.when(callsTo('add', anything)).alwaysReturn(0);
193
194 m.add('foo');
195 m.add('bar');
196
197 m.getLogs(callsTo('add')).verify(happenedExactly(2));
198 m.getLogs(callsTo('add', 'foo')).verify(happenedOnce);
199 });
200 } else if (testName.startsWith('mock test 3 ')) {
201 test(testName, () {
202 var p = new FooSpy();
203 p.sum(1, 2, 3);
204 p.getLogs(callsTo('sum')).verify(happenedOnce);
205 p.sum(2, 2, 2);
206 p.getLogs(callsTo('sum')).verify(happenedExactly(2));
207 p.getLogs(callsTo('sum')).verify(sometimeReturned(6));
208 p.getLogs(callsTo('sum')).verify(alwaysReturned(6));
209 p.getLogs(callsTo('sum')).verify(neverReturned(5));
210 p.sum(2, 2, 1);
211 p.getLogs(callsTo('sum')).verify(sometimeReturned(5));
212 });
213 } else if (testName.startsWith('mock test 4 ')) {
214 test(testName, () {
215 var m = new Mock();
216 m.when(callsTo('foo')).alwaysReturn(null);
217 m.foo();
218 m.foo();
219 m.getLogs(callsTo('foo')).verify(happenedOnce);
220 });
221 } else if (testName.startsWith('mock test 5 ')) {
222 test(testName, () {
223 var m = new Mock();
224 m.when(callsTo('foo')).thenReturn(null);
225 m.foo();
226 m.foo();
227 });
228 } else if (testName.startsWith('mock test 6 ')) {
229 test(testName, () {
230 var p = new FooSpy();
231 p.sum(1, 2, 3);
232 p.getLogs(callsTo('sum')).verify(sometimeReturned(0));
233 });
234 } else if (testName.startsWith('mock test 7 ')) {
235 test(testName, () {
236 var m = new Mock.custom(throwIfNoBehavior:true);
237 m.when(callsTo('foo')).thenReturn(null);
238 m.foo();
239 m.bar();
240 });
241 } else if (testName.startsWith('mock test 8 ')) {
242 test(testName, () {
243 var log = new LogEntryList();
244 var m1 = new Mock.custom(name:'m1', log:log);
245 var m2 = new Mock.custom(name:'m2', log:log);
246 m1.foo();
247 m2.foo();
248 m1.bar();
249 m2.bar();
250 expect(log.logs.length, 4);
251 log.getMatches(anything, callsTo('foo')).verify(happenedExactly(2));
252 log.getMatches('m1', callsTo('foo')).verify(happenedOnce);
253 log.getMatches('m1', callsTo('bar')).verify(happenedOnce);
254 m2.getLogs(callsTo('foo')).verify(happenedOnce);
255 m2.getLogs(callsTo('bar')).verify(happenedOnce);
256 });
257 } else if (testName.startsWith('mock test 9 ')) {
258 test(testName, () {
259 var m = new Mock();
260 m.when(callsTo(null, 1)).alwaysReturn(2);
261 m.when(callsTo(null, 2)).alwaysReturn(4);
262 expect(m.foo(1), 2);
263 expect(m.foo(2), 4);
264 expect(m.bar(1), 2);
265 expect(m.bar(2), 4);
266 m.getLogs(callsTo()).verify(happenedExactly(4));
267 m.getLogs(callsTo(null, 1)).verify(happenedExactly(2));
268 m.getLogs(callsTo(null, 2)).verify(happenedExactly(2));
269 m.getLogs(null, returning(1)).verify(neverHappened);
270 m.getLogs(null, returning(2)).verify(happenedExactly(2));
271 m.getLogs(null, returning(4)).verify(happenedExactly(2));
272 });
273 } else if (testName.startsWith('mock test 10 ')) {
274 test(testName, () {
275 var m = new Mock();
276 m.when(callsTo(matches('^[A-Z]'))).
277 alwaysThrow('Method names must start with lower case.');
278 m.test();
279 });
280 } else if (testName.startsWith('mock test 11 ')) {
281 test(testName, () {
282 var m = new Mock();
283 m.when(callsTo(matches('^[A-Z]'))).
284 alwaysThrow('Method names must start with lower case.');
285 m.Test();
286 });
287 } else if (testName.startsWith('mock test 12 ')) {
288 test(testName, () {
289 var m = new Mock.custom(enableLogging:false);
290 m.Test();
291 print(m.getLogs(callsTo('Test')).toString());
292 });
293 } else if (testName.startsWith('mock test 13 ')) {
294 test(testName, () {
295 LogEntryList log = makeTestLog();
296 // Basic behavior, with call matcher.
297 expect(log.findLogEntry(callsTo('a')), 0);
298 expect(log.findLogEntry(callsTo('b')), 1);
299 expect(log.findLogEntry(callsTo('c')), 2);
300 expect(log.findLogEntry(callsTo('d')), -1);
301 // Find using predicate.
302 expect(log.findLogEntry((le) => le.methodName == 'a'), 0);
303 expect(log.findLogEntry((le) => le.methodName == 'b'), 1);
304 expect(log.findLogEntry((le) => le.methodName == 'c'), 2);
305 // Test explicit return value.
306 expect(log.findLogEntry((le) => le.methodName == 'd', 0, 3), 3);
307 // Find from start of log.
308 expect(log.findLogEntry(callsTo('a'), 0), 0);
309 expect(log.findLogEntry(callsTo('b'), 0), 1);
310 expect(log.findLogEntry(callsTo('c'), 0), 2);
311 // Find from second entry in log.
312 expect(log.findLogEntry(callsTo('a'), 1), -1);
313 expect(log.findLogEntry(callsTo('b'), 1), 1);
314 expect(log.findLogEntry(callsTo('c'), 1), 2);
315 // Find from last entry in log.
316 expect(log.findLogEntry(callsTo('a'), 2), -1);
317 expect(log.findLogEntry(callsTo('b'), 2), -1);
318 expect(log.findLogEntry(callsTo('c'), 2), 2);
319 // Find from start position passed end of log.
320 expect(log.findLogEntry(callsTo('a'), 3), -1);
321 expect(log.findLogEntry(callsTo('b'), 3), -1);
322 expect(log.findLogEntry(callsTo('c'), 3), -1);
323 // No restriction on entry.
324 expect(log.findLogEntry(null, 0), 0);
325 expect(log.findLogEntry(null, 1), 1);
326 expect(log.findLogEntry(null, 2), 2);
327 expect(log.findLogEntry(null, 3), -1);
328 });
329 } else if (testName.startsWith('mock test 14 ')) {
330 test(testName, () {
331 LogEntryList log = makeTestLog();
332 LogEntryList log2;
333 Date t0 = new Date.fromMillisecondsSinceEpoch(0, true);
334 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, true);
335 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, true);
336 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, true);
337 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, true);
338
339 log2 = log.before(t0);
340 expect(log2.logs, hasLength(0));
341 expect(log2.filter, 'test before 1970-01-01 00:00:00.000Z');
342 log2 = log.until(t0);
343 expect(log2.logs, hasLength(0));
344 expect(log2.filter, 'test until 1970-01-01 00:00:00.000Z');
345 log2 = log.from(t0);
346 expect(log2.logs, hasLength(3));
347 expect(log2.first.methodName, 'a');
348 expect(log2.last.methodName, 'c');
349 expect(log2.filter, 'test from 1970-01-01 00:00:00.000Z');
350 log2 = log.after(t0);
351 expect(log2.logs, hasLength(3));
352 expect(log2.first.methodName, 'a');
353 expect(log2.last.methodName, 'c');
354 expect(log2.filter, 'test after 1970-01-01 00:00:00.000Z');
355
356 log2 = log.before(t1000);
357 expect(log2.logs, hasLength(0));
358 log2 = log.until(t1000);
359 expect(log2.logs, hasLength(1));
360 expect(log2.first.methodName, 'a');
361 expect(log2.last.methodName, 'a');
362 log2 = log.from(t1000);
363 expect(log2.logs, hasLength(3));
364 expect(log2.first.methodName, 'a');
365 expect(log2.last.methodName, 'c');
366 log2 = log.after(t1000);
367 expect(log2.logs, hasLength(2));
368 expect(log2.first.methodName, 'b');
369 expect(log2.last.methodName, 'c');
370
371 log2 = log.before(t2000);
372 expect(log2.logs, hasLength(1));
373 expect(log2.first.methodName, 'a');
374 expect(log2.last.methodName, 'a');
375 log2 = log.until(t2000);
376 expect(log2.logs, hasLength(2));
377 expect(log2.first.methodName, 'a');
378 expect(log2.last.methodName, 'b');
379 log2 = log.from(t2000);
380 expect(log2.logs, hasLength(2));
381 expect(log2.first.methodName, 'b');
382 expect(log2.last.methodName, 'c');
383 log2 = log.after(t2000);
384 expect(log2.logs, hasLength(1));
385 expect(log2.first.methodName, 'c');
386 expect(log2.last.methodName, 'c');
387
388 log2 = log.before(t3000);
389 expect(log2.logs, hasLength(2));
390 expect(log2.first.methodName, 'a');
391 expect(log2.last.methodName, 'b');
392 log2 = log.until(t3000);
393 expect(log2.logs, hasLength(3));
394 expect(log2.first.methodName, 'a');
395 expect(log2.last.methodName, 'c');
396
397 log2 = log.from(t3000);
398 expect(log2.logs, hasLength(1));
399 expect(log2.first.methodName, 'c');
400 expect(log2.last.methodName, 'c');
401 log2 = log.after(t3000);
402 expect(log2.logs, hasLength(0));
403
404 log2 = log.before(t4000);
405 expect(log2.logs, hasLength(3));
406 expect(log2.first.methodName, 'a');
407 expect(log2.last.methodName, 'c');
408 log2 = log.until(t4000);
409 expect(log2.logs, hasLength(3));
410 expect(log2.first.methodName, 'a');
411 expect(log2.last.methodName, 'c');
412 log2 = log.from(t4000);
413 expect(log2.logs, hasLength(0));
414 log2 = log.after(t4000);
415 expect(log2.logs, hasLength(0));
416 });
417 } else if (testName.startsWith('mock test 15 ')) {
418 test(testName, () {
419 Date t0 = new Date.fromMillisecondsSinceEpoch(0, true);
420 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, true);
421 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, true);
422 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, true);
423 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, true);
424
425 LogEntryList log = makeTestLog().before(t0, true);
426 expect(log.logs, hasLength(0));
427 expect(log.filter, 'test before 1970-01-01 00:00:00.000Z');
428 log = makeTestLog().until(t0, true);
429 expect(log.logs, hasLength(0));
430 expect(log.filter, 'test until 1970-01-01 00:00:00.000Z');
431 log = makeTestLog().from(t0, true);
432 expect(log.logs, hasLength(3));
433 expect(log.first.methodName, 'a');
434 expect(log.last.methodName, 'c');
435 expect(log.filter, 'test from 1970-01-01 00:00:00.000Z');
436 log = makeTestLog().after(t0, true);
437 expect(log.logs, hasLength(3));
438 expect(log.first.methodName, 'a');
439 expect(log.last.methodName, 'c');
440 expect(log.filter, 'test after 1970-01-01 00:00:00.000Z');
441
442 log = makeTestLog().before(t1000, true);
443 expect(log.logs, hasLength(0));
444 log = makeTestLog().until(t1000, true);
445 expect(log.logs, hasLength(1));
446 expect(log.first.methodName, 'a');
447 expect(log.last.methodName, 'a');
448 log = makeTestLog().from(t1000, true);
449 expect(log.logs, hasLength(3));
450 expect(log.first.methodName, 'a');
451 expect(log.last.methodName, 'c');
452 log = makeTestLog().after(t1000, true);
453 expect(log.logs, hasLength(2));
454 expect(log.first.methodName, 'b');
455 expect(log.last.methodName, 'c');
456
457 log = makeTestLog().before(t2000, true);
458 expect(log.logs, hasLength(1));
459 expect(log.first.methodName, 'a');
460 expect(log.last.methodName, 'a');
461 log = makeTestLog().until(t2000, true);
462 expect(log.logs, hasLength(2));
463 expect(log.first.methodName, 'a');
464 expect(log.last.methodName, 'b');
465 log = makeTestLog().from(t2000, true);
466 expect(log.logs, hasLength(2));
467 expect(log.first.methodName, 'b');
468 expect(log.last.methodName, 'c');
469 log = makeTestLog().after(t2000, true);
470 expect(log.logs, hasLength(1));
471 expect(log.first.methodName, 'c');
472 expect(log.last.methodName, 'c');
473
474 log = makeTestLog().before(t3000, true);
475 expect(log.logs, hasLength(2));
476 expect(log.first.methodName, 'a');
477 expect(log.last.methodName, 'b');
478 log = makeTestLog().until(t3000, true);
479 expect(log.logs, hasLength(3));
480 expect(log.first.methodName, 'a');
481 expect(log.last.methodName, 'c');
482 log = makeTestLog().from(t3000, true);
483 expect(log.logs, hasLength(1));
484 expect(log.first.methodName, 'c');
485 expect(log.last.methodName, 'c');
486 log = makeTestLog().after(t3000);
487 expect(log.logs, hasLength(0));
488
489 log = makeTestLog().before(t4000, true);
490 expect(log.logs, hasLength(3));
491 expect(log.first.methodName, 'a');
492 expect(log.last.methodName, 'c');
493 log = makeTestLog().until(t4000, true);
494 expect(log.logs, hasLength(3));
495 expect(log.first.methodName, 'a');
496 expect(log.last.methodName, 'c');
497 log = makeTestLog().from(t4000, true);
498 expect(log.logs, hasLength(0));
499 log = makeTestLog().after(t4000, true);
500 expect(log.logs, hasLength(0));
501 });
502 } else if (testName.startsWith('mock test 16 ')) {
503 test(testName, () {
504 LogEntryList log = new LogEntryList('test');
505 List args0 = new List();
506 List args1 = new List();
507 args1.add('test');
508 LogEntry e0 = makeTestLogEntry('foo', args0, 1000);
509 log.add(e0);
510 LogEntry e1 = makeTestLogEntry('bar1', args0, 2000, 'a');
511 log.add(e1);
512 LogEntry e2 = makeTestLogEntry('bar1', args1, 3000, 'b');
513 log.add(e2);
514 LogEntry e3 = makeTestLogEntry('foo', args0, 4000);
515 log.add(e3);
516 LogEntry e4 = makeTestLogEntry('hello', args0, 4500);
517 log.add(e4);
518 LogEntry e5 = makeTestLogEntry('bar2', args0, 5000, 'a');
519 log.add(e5);
520 LogEntry e6 = makeTestLogEntry('bar2', args1, 6000, 'b');
521 log.add(e6);
522 LogEntry e7 = makeTestLogEntry('foo', args0, 7000);
523 log.add(e7);
524 LogEntry e8 = makeTestLogEntry('bar3', args0, 8000, 'a');
525 log.add(e8);
526 LogEntry e9 = makeTestLogEntry('bar3', args1, 9000, 'b');
527 log.add(e9);
528 LogEntry e10 = makeTestLogEntry('foo', args0, 10000);
529 log.add(e10);
530
531 LogEntryList keyList = new LogEntryList('keys');
532
533 // Test with empty key list.
534
535 LogEntryList result;
536 result = log.preceding(keyList);
537 expect(result.logs, hasLength(0));
538
539 result = log.preceding(keyList, includeKeys:true);
540 expect(result.logs, hasLength(0));
541
542 // Single key, distance 1, no restrictions.
543
544 keyList.add(e3);
545 result = log.preceding(keyList);
546 expect(result.logs, orderedEquals([e2]));
547
548 result = log.following(keyList);
549 expect(result.logs, orderedEquals([e4]));
550
551 // Single key, distance 2, no restrictions.
552
553 result = log.preceding(keyList, distance:2);
554 expect(result.logs, orderedEquals([e1, e2]));
555
556 result = log.following(keyList, distance:2);
557 expect(result.logs, orderedEquals([e4, e5]));
558
559 // Single key, distance 3, no restrictions.
560
561 result = log.preceding(keyList, distance:3);
562 expect(result.logs, orderedEquals([e0, e1, e2]));
563
564 result = log.following(keyList, distance:3);
565 expect(result.logs, orderedEquals([e4, e5, e6]));
566
567 // Include keys in result
568
569 result = log.preceding(keyList, distance:3, includeKeys:true);
570 expect(result.logs, orderedEquals([e0, e1, e2, e3]));
571
572 result = log.following(keyList, distance:3, includeKeys:true);
573 expect(result.logs, orderedEquals([e3, e4, e5, e6]));
574
575 // Restrict the matches
576
577 result = log.preceding(keyList, logFilter:callsTo(startsWith('bar')),
578 distance:3);
579 expect(result.logs, orderedEquals([e1, e2]));
580
581 result = log.preceding(keyList, logFilter:callsTo(startsWith('bar')),
582 distance:3, includeKeys:true);
583 expect(result.logs, orderedEquals([e1, e2, e3]));
584
585 result = log.preceding(keyList, equals('a'), callsTo(startsWith('bar')),
586 distance:3);
587 expect(result.logs, orderedEquals([e1]));
588
589 result = log.preceding(keyList, equals('a'), callsTo(startsWith('bar')),
590 distance:3, includeKeys:true);
591 expect(result.logs, orderedEquals([e1, e3]));
592
593 keyList.logs.clear();
594 keyList.add(e0);
595 keyList.add(e3);
596 keyList.add(e7);
597
598 result = log.preceding(keyList);
599 expect(result.logs, orderedEquals([e2, e6]));
600
601 result = log.following(keyList);
602 expect(result.logs, orderedEquals([e1, e4, e8]));
603
604 result = log.preceding(keyList, includeKeys:true);
605 expect(result.logs, orderedEquals([e0, e2, e3, e6, e7]));
606
607 result = log.following(keyList, includeKeys:true);
608 expect(result.logs, orderedEquals([e0, e1, e3, e4, e7, e8]));
609
610 keyList.logs.clear();
611 keyList.add(e3);
612 keyList.add(e7);
613 keyList.add(e10);
614
615 result = log.preceding(keyList);
616 expect(result.logs, orderedEquals([e2, e6, e9]));
617
618 result = log.following(keyList);
619 expect(result.logs, orderedEquals([e4, e8]));
620
621 result = log.preceding(keyList, includeKeys:true);
622 expect(result.logs, orderedEquals([e2, e3, e6, e7, e9, e10]));
623
624 result = log.following(keyList, includeKeys:true);
625 expect(result.logs, orderedEquals([e3, e4, e7, e8, e10]));
626
627 keyList.logs.clear();
628 keyList.add(e0);
629 keyList.add(e3);
630 keyList.add(e7);
631 keyList.add(e10);
632
633 result = log.preceding(keyList);
634 expect(result.logs, orderedEquals([e2, e6, e9]));
635
636 result = log.following(keyList);
637 expect(result.logs, orderedEquals([e1, e4, e8]));
638
639 result = log.preceding(keyList, includeKeys:true);
640 expect(result.logs, orderedEquals([e0, e2, e3, e6, e7, e9, e10]));
641
642 result = log.following(keyList, includeKeys:true);
643 expect(result.logs, orderedEquals([e0, e1, e3, e4, e7, e8, e10]));
644
645 keyList.logs.clear();
646 keyList.add(e0);
647 keyList.add(e3);
648 keyList.add(e7);
649
650 result = log.preceding(keyList, distance:3);
651 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6]));
652
653 result = log.following(keyList, distance:3);
654 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6, e8, e9, e10]));
655
656 result = log.preceding(keyList, distance:3, includeKeys:true);
657 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6, e7]));
658
659 result = log.following(keyList, distance:3, includeKeys:true);
660 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
661 e7, e8, e9, e10]));
662
663 keyList.logs.clear();
664 keyList.add(e3);
665 keyList.add(e7);
666 keyList.add(e10);
667
668 result = log.preceding(keyList, distance:3);
669 expect(result.logs, orderedEquals([e0, e1, e2, e4, e5, e6, e8, e9]));
670
671 result = log.following(keyList, distance:3);
672 expect(result.logs, orderedEquals([e4, e5, e6, e8, e9]));
673
674 result = log.preceding(keyList, distance:3, includeKeys:true);
675 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
676 e7, e8, e9, e10]));
677
678 result = log.following(keyList, distance:3, includeKeys:true);
679 expect(result.logs, orderedEquals([e3, e4, e5, e6, e7, e8, e9, e10]));
680
681 keyList.logs.clear();
682 keyList.add(e0);
683 keyList.add(e3);
684 keyList.add(e7);
685 keyList.add(e10);
686
687 result = log.preceding(keyList, distance:3);
688 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6, e8, e9]));
689
690 result = log.following(keyList, distance:3);
691 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6, e8, e9]));
692
693 result = log.preceding(keyList, distance:3, includeKeys:true);
694 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
695 e7, e8, e9, e10]));
696
697 result = log.following(keyList, distance:3, includeKeys:true);
698 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
699 e7, e8, e9, e10]));
700 });
701 } 126 }
702 }); 127 });
703 } 128 }
704 129
705 void nextTest(int testNum) { 130 void nextTest(int testNum) {
706 SendPort sport = spawnFunction(runTest); 131 SendPort sport = spawnFunction(runTest);
707 sport.call(tests[testNum]).then((msg) { 132 sport.call(tests[testNum]).then((msg) {
708 actual.add(msg); 133 actual.add(msg);
709 if (actual.length == expected.length) { 134 if (actual.length == expected.length) {
710 for (var i = 0; i < tests.length; i++) { 135 for (var i = 0; i < tests.length; i++) {
711 test(tests[i], () => expect(actual[i].trim(), equals(expected[i]))); 136 test(tests[i], () => expect(actual[i].trim(), equals(expected[i])));
712 } 137 }
713 } else { 138 } else {
714 nextTest(testNum+1); 139 nextTest(testNum+1);
715 } 140 }
716 }); 141 });
717 } 142 }
718 143
719 main() { 144 main() {
720 tests = [ 145 tests = [
721 'single correct test', 146 'single correct test',
722 'single failing test', 147 'single failing test',
723 'exception test', 148 'exception test',
724 'group name test', 149 'group name test',
725 'setup test', 150 'setup test',
726 'teardown test', 151 'teardown test',
727 'setup and teardown test', 152 'setup and teardown test',
728 'correct callback test', 153 'correct callback test',
729 'excess callback test', 154 'excess callback test',
730 'completion test', 155 'completion test'
731 'mock test 1 (Mock)',
732 'mock test 2 (MockList)',
733 'mock test 3 (Spy)',
734 'mock test 4 (Excess calls)',
735 'mock test 5 (No action)',
736 'mock test 6 (No matching return)',
737 'mock test 7 (No behavior)',
738 'mock test 8 (Shared log)',
739 'mock test 9 (Null CallMatcher)',
740 'mock test 10 (RegExp CallMatcher Good)',
741 'mock test 11 (RegExp CallMatcher Bad)',
742 'mock test 12 (No logging)',
743 'mock test 13 (find log entry)',
744 'mock test 14 (from,after,before,until)',
745 'mock test 15 (inplace from,after,before,until)',
746 'mock test 16 (neighbors)'
747 ]; 156 ];
748 157
749 expected = [ 158 expected = [
750 buildStatusString(1, 0, 0, tests[0]), 159 buildStatusString(1, 0, 0, tests[0]),
751 buildStatusString(0, 1, 0, tests[1], 160 buildStatusString(0, 1, 0, tests[1],
752 message: 'Expected: <5> but: was <4>.'), 161 message: 'Expected: <5> but: was <4>.'),
753 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'), 162 buildStatusString(0, 1, 0, tests[2], message: 'Caught Exception: Fail.'),
754 buildStatusString(2, 0, 0, 'a a::a b b'), 163 buildStatusString(2, 0, 0, 'a a::a b b'),
755 buildStatusString(1, 0, 0, 'a ${tests[4]}', 0, 'setup'), 164 buildStatusString(1, 0, 0, 'a ${tests[4]}', 0, 'setup'),
756 buildStatusString(1, 0, 0, 'a ${tests[5]}', 0, '', 'teardown'), 165 buildStatusString(1, 0, 0, 'a ${tests[5]}', 0, '', 'teardown'),
757 buildStatusString(1, 0, 0, 'a ${tests[6]}', 0, 166 buildStatusString(1, 0, 0, 'a ${tests[6]}', 0,
758 'setup', 'teardown'), 167 'setup', 'teardown'),
759 buildStatusString(1, 0, 0, tests[7], 1), 168 buildStatusString(1, 0, 0, tests[7], 1),
760 buildStatusString(0, 0, 1, tests[8], 1, 169 buildStatusString(0, 0, 1, tests[8], 1,
761 message: 'Callback called more times than expected (2 > 1).'), 170 message: 'Callback called more times than expected (2 > 1).'),
762 buildStatusString(1, 0, 0, tests[9], 10), 171 buildStatusString(1, 0, 0, tests[9], 10)
763 buildStatusString(1, 0, 0, tests[10]),
764 buildStatusString(1, 0, 0, tests[11]),
765 buildStatusString(1, 0, 0, tests[12]),
766 buildStatusString(0, 1, 0, tests[13],
767 message: "Expected foo() to be called 1 times but:"
768 " was called 2 times."),
769 buildStatusString(0, 1, 0, tests[14],
770 message: 'Caught Exception: No more actions for method foo.'),
771 buildStatusString(0, 1, 0, tests[15], message:
772 "Expected sum() to sometimes return <0> but: never did."),
773 buildStatusString(0, 1, 0, tests[16],
774 message: 'Caught Exception: No behavior specified for method bar.'),
775 buildStatusString(1, 0, 0, tests[17]),
776 buildStatusString(1, 0, 0, tests[18]),
777 buildStatusString(1, 0, 0, tests[19]),
778 buildStatusString(0, 1, 0, tests[20],
779 message:'Caught Method names must start with lower case.'),
780 buildStatusString(0, 1, 0, tests[21], message:
781 "Caught Exception: Can't retrieve logs when logging was never enabled."),
782 buildStatusString(1, 0, 0, tests[22]),
783 buildStatusString(1, 0, 0, tests[23]),
784 buildStatusString(1, 0, 0, tests[24]),
785 buildStatusString(1, 0, 0, tests[25])
786 ]; 172 ];
787 173
788 actual = []; 174 actual = [];
789 175
790 nextTest(0); 176 nextTest(0);
791 } 177 }
792 178
OLDNEW
« no previous file with comments | « tests/lib/unittest/matchers_test.dart ('k') | utils/tests/pub/version_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698