| 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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
| 6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
| 7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
| 8 /// tests like that. | 8 /// tests like that. |
| 9 library test_pub; | 9 library test_pub; |
| 10 | 10 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 Future cleanup() { | 453 Future cleanup() { |
| 454 return _runScheduled(createdSandboxDir, _scheduledCleanup).then((_) { | 454 return _runScheduled(createdSandboxDir, _scheduledCleanup).then((_) { |
| 455 _scheduled = null; | 455 _scheduled = null; |
| 456 _scheduledCleanup = null; | 456 _scheduledCleanup = null; |
| 457 _scheduledOnException = null; | 457 _scheduledOnException = null; |
| 458 if (createdSandboxDir != null) return deleteDir(createdSandboxDir); | 458 if (createdSandboxDir != null) return deleteDir(createdSandboxDir); |
| 459 return new Future.immediate(null); | 459 return new Future.immediate(null); |
| 460 }); | 460 }); |
| 461 } | 461 } |
| 462 | 462 |
| 463 final future = _setUpSandbox().then((sandboxDir) { | 463 timeout(_setUpSandbox().then((sandboxDir) { |
| 464 createdSandboxDir = sandboxDir; | 464 createdSandboxDir = sandboxDir; |
| 465 return _runScheduled(sandboxDir, _scheduled); | 465 return _runScheduled(sandboxDir, _scheduled); |
| 466 }); | 466 }).catchError((e) { |
| 467 | |
| 468 future.catchError((e) { | |
| 469 // If an error occurs during testing, delete the sandbox, throw the error so | 467 // If an error occurs during testing, delete the sandbox, throw the error so |
| 470 // that the test framework sees it, then finally call asyncDone so that the | 468 // that the test framework sees it, then finally call asyncDone so that the |
| 471 // test framework knows we're done doing asynchronous stuff. | 469 // test framework knows we're done doing asynchronous stuff. |
| 472 var subFuture = _runScheduled(createdSandboxDir, _scheduledOnException) | 470 return _runScheduled(createdSandboxDir, _scheduledOnException) |
| 473 .then((_) => cleanup()); | 471 .then((_) => registerException(e.error, e.stackTrace)).catchError((e) { |
| 474 subFuture.catchError((e) { | |
| 475 print("Exception while cleaning up: ${e.error}"); | 472 print("Exception while cleaning up: ${e.error}"); |
| 476 print(e.stackTrace); | 473 print(e.stackTrace); |
| 477 registerException(e.error, e.stackTrace); | 474 registerException(e.error, e.stackTrace); |
| 478 return true; | |
| 479 }); | 475 }); |
| 480 subFuture.then((_) => registerException(e.error, e.stackTrace)); | 476 }), _TIMEOUT, 'waiting for a test to complete') |
| 481 return true; | |
| 482 }); | |
| 483 | |
| 484 timeout(future, _TIMEOUT, 'waiting for a test to complete') | |
| 485 .then((_) => cleanup()) | 477 .then((_) => cleanup()) |
| 486 .then((_) => asyncDone()); | 478 .then((_) => asyncDone()); |
| 487 } | 479 } |
| 488 | 480 |
| 489 /// Get the path to the root "util/test/pub" directory containing the pub | 481 /// Get the path to the root "util/test/pub" directory containing the pub |
| 490 /// tests. | 482 /// tests. |
| 491 String get testDirectory { | 483 String get testDirectory { |
| 492 var dir = new Options().script; | 484 var dir = new Options().script; |
| 493 while (basename(dir) != 'pub') dir = dirname(dir); | 485 while (basename(dir) != 'pub') dir = dirname(dir); |
| 494 | 486 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 var error = new StringBuffer(); | 826 var error = new StringBuffer(); |
| 835 error.add("No files named $name in $dir were valid:\n"); | 827 error.add("No files named $name in $dir were valid:\n"); |
| 836 for (var failure in failures) { | 828 for (var failure in failures) { |
| 837 error.add(" $failure\n"); | 829 error.add(" $failure\n"); |
| 838 } | 830 } |
| 839 completer.completeError( | 831 completer.completeError( |
| 840 new ExpectException(error.toString()), stackTrace); | 832 new ExpectException(error.toString()), stackTrace); |
| 841 } | 833 } |
| 842 | 834 |
| 843 for (var match in matches) { | 835 for (var match in matches) { |
| 844 var future = validate(match); | 836 var future = validate(match).then((_) { |
| 845 | 837 successes++; |
| 846 future.catchError((e) { | 838 checkComplete(); |
| 839 }).catchError((e) { |
| 847 failures.add(e); | 840 failures.add(e); |
| 848 checkComplete(); | 841 checkComplete(); |
| 849 }); | 842 }); |
| 850 | |
| 851 future.then((_) { | |
| 852 successes++; | |
| 853 checkComplete(); | |
| 854 }).catchError((_) {}); | |
| 855 } | 843 } |
| 856 return completer.future; | 844 return completer.future; |
| 857 }); | 845 }); |
| 858 } | 846 } |
| 859 } | 847 } |
| 860 | 848 |
| 861 /// Describes a file. These are used both for setting up an expected directory | 849 /// Describes a file. These are used both for setting up an expected directory |
| 862 /// tree before running a test, and for validating that the file system matches | 850 /// tree before running a test, and for validating that the file system matches |
| 863 /// some expectations after running it. | 851 /// some expectations after running it. |
| 864 class FileDescriptor extends Descriptor { | 852 class FileDescriptor extends Descriptor { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 | 1101 |
| 1114 var sinkStream = new ListInputStream(); | 1102 var sinkStream = new ListInputStream(); |
| 1115 var tempDir; | 1103 var tempDir; |
| 1116 // TODO(rnystrom): Use withTempDir() here. | 1104 // TODO(rnystrom): Use withTempDir() here. |
| 1117 // TODO(nweiz): propagate any errors to the return value. See issue 3657. | 1105 // TODO(nweiz): propagate any errors to the return value. See issue 3657. |
| 1118 createTempDir().then((_tempDir) { | 1106 createTempDir().then((_tempDir) { |
| 1119 tempDir = _tempDir; | 1107 tempDir = _tempDir; |
| 1120 return create(tempDir); | 1108 return create(tempDir); |
| 1121 }).then((tar) { | 1109 }).then((tar) { |
| 1122 var sourceStream = tar.openInputStream(); | 1110 var sourceStream = tar.openInputStream(); |
| 1123 pipeInputToInput(sourceStream, sinkStream).then((_) { | 1111 return pipeInputToInput(sourceStream, sinkStream).then((_) { |
| 1124 tempDir.delete(recursive: true); | 1112 tempDir.delete(recursive: true); |
| 1125 }); | 1113 }); |
| 1126 }); | 1114 }); |
| 1127 return sinkStream; | 1115 return sinkStream; |
| 1128 } | 1116 } |
| 1129 } | 1117 } |
| 1130 | 1118 |
| 1131 /// A descriptor that validates that no file exists with the given name. | 1119 /// A descriptor that validates that no file exists with the given name. |
| 1132 class NothingDescriptor extends Descriptor { | 1120 class NothingDescriptor extends Descriptor { |
| 1133 NothingDescriptor(String name) : super(name); | 1121 NothingDescriptor(String name) : super(name); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 /// calling [completion] is unnecessary. | 1539 /// calling [completion] is unnecessary. |
| 1552 void expectLater(Future actual, matcher, {String reason, | 1540 void expectLater(Future actual, matcher, {String reason, |
| 1553 FailureHandler failureHandler, bool verbose: false}) { | 1541 FailureHandler failureHandler, bool verbose: false}) { |
| 1554 _schedule((_) { | 1542 _schedule((_) { |
| 1555 return actual.then((value) { | 1543 return actual.then((value) { |
| 1556 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1544 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
| 1557 verbose: false); | 1545 verbose: false); |
| 1558 }); | 1546 }); |
| 1559 }); | 1547 }); |
| 1560 } | 1548 } |
| OLD | NEW |