OLD | NEW |
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 /** | 5 /** |
6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub | 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub |
7 * tests are integration tests that stage some stuff on the file system, run | 7 * tests are integration tests that stage some stuff on the file system, run |
8 * pub, and then validate the results. This library provides an API to build | 8 * pub, and then validate the results. This library provides an API to build |
9 * tests like that. | 9 * tests like that. |
10 */ | 10 */ |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 // that the test framework sees it, then finally call asyncDone so that the | 519 // that the test framework sees it, then finally call asyncDone so that the |
520 // test framework knows we're done doing asynchronous stuff. | 520 // test framework knows we're done doing asynchronous stuff. |
521 var future = _runScheduled(createdSandboxDir, _scheduledOnException) | 521 var future = _runScheduled(createdSandboxDir, _scheduledOnException) |
522 .chain((_) => cleanup()); | 522 .chain((_) => cleanup()); |
523 future.handleException((e) { | 523 future.handleException((e) { |
524 print("Exception while cleaning up: $e"); | 524 print("Exception while cleaning up: $e"); |
525 print(future.stackTrace); | 525 print(future.stackTrace); |
526 registerException(error, future.stackTrace); | 526 registerException(error, future.stackTrace); |
527 return true; | 527 return true; |
528 }); | 528 }); |
529 future.then((_) => registerException(error, future.stackTrace)); | 529 future.then((_) { |
| 530 print("Registering exception"); |
| 531 registerException(error, future.stackTrace); |
| 532 }); |
530 return true; | 533 return true; |
531 }); | 534 }); |
532 | 535 |
533 future.chain((_) => cleanup()).then((_) { | 536 future.chain((_) => cleanup()).then((_) { |
534 asyncDone(); | 537 asyncDone(); |
535 }); | 538 }); |
536 } | 539 } |
537 | 540 |
538 /// Get the path to the root "util/test/pub" directory containing the pub tests. | 541 /// Get the path to the root "util/test/pub" directory containing the pub tests. |
539 String get testDirectory { | 542 String get testDirectory { |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 }); | 1455 }); |
1453 return timeout(requestCompleteCompleter.future, | 1456 return timeout(requestCompleteCompleter.future, |
1454 5000, "waiting for $method $path"); | 1457 5000, "waiting for $method $path"); |
1455 }); | 1458 }); |
1456 _handlers.add(handlerCompleter.future); | 1459 _handlers.add(handlerCompleter.future); |
1457 } | 1460 } |
1458 | 1461 |
1459 /// Raises an error complaining of an unexpected request. | 1462 /// Raises an error complaining of an unexpected request. |
1460 void _awaitHandle(HttpRequest request, HttpResponse response) { | 1463 void _awaitHandle(HttpRequest request, HttpResponse response) { |
1461 var future = timeout(new Future.immediate(null).chain((_) { | 1464 var future = timeout(new Future.immediate(null).chain((_) { |
1462 var handlerFuture = _handlers.removeFirst(); | 1465 if (_handlers.isEmpty) { |
1463 if (handlerFuture == null) { | |
1464 fail('Unexpected ${request.method} request to ${request.path}.'); | 1466 fail('Unexpected ${request.method} request to ${request.path}.'); |
1465 } | 1467 } |
1466 return handlerFuture; | 1468 return _handlers.removeFirst(); |
1467 }).transform((handler) { | 1469 }).transform((handler) { |
1468 handler(request, response); | 1470 handler(request, response); |
1469 }), 5000, "waiting for a handler for ${request.method} ${request.path}"); | 1471 }), 5000, "waiting for a handler for ${request.method} ${request.path}"); |
1470 expect(future, completes); | 1472 expect(future, completes); |
1471 } | 1473 } |
1472 } | 1474 } |
1473 | 1475 |
1474 /** | 1476 /** |
1475 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, | 1477 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, |
1476 * and [Future]s) and recursively resolves all the [Future]s contained within. | 1478 * and [Future]s) and recursively resolves all the [Future]s contained within. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 /// calling [completion] is unnecessary. | 1539 /// calling [completion] is unnecessary. |
1538 void expectLater(Future actual, matcher, {String reason, | 1540 void expectLater(Future actual, matcher, {String reason, |
1539 FailureHandler failureHandler, bool verbose: false}) { | 1541 FailureHandler failureHandler, bool verbose: false}) { |
1540 _schedule((_) { | 1542 _schedule((_) { |
1541 return actual.transform((value) { | 1543 return actual.transform((value) { |
1542 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1544 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
1543 verbose: false); | 1545 verbose: false); |
1544 }); | 1546 }); |
1545 }); | 1547 }); |
1546 } | 1548 } |
OLD | NEW |