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 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 /// Whether the user has scheduled the end of this process by calling either | 1327 /// Whether the user has scheduled the end of this process by calling either |
1328 /// [shouldExit] or [kill]. | 1328 /// [shouldExit] or [kill]. |
1329 bool _endScheduled = false; | 1329 bool _endScheduled = false; |
1330 | 1330 |
1331 /// Whether the process is expected to terminate at this point. | 1331 /// Whether the process is expected to terminate at this point. |
1332 bool _endExpected = false; | 1332 bool _endExpected = false; |
1333 | 1333 |
1334 /// Wraps a [Process] [Future] in a scheduled process. | 1334 /// Wraps a [Process] [Future] in a scheduled process. |
1335 ScheduledProcess(this.name, Future<Process> process) | 1335 ScheduledProcess(this.name, Future<Process> process) |
1336 : _process = process, | 1336 : _process = process, |
1337 _stdout = process.transform((p) => _wrapStream(p.stdout)), | 1337 _stdout = process.transform((p) => new StringInputStream(p.stdout)), |
1338 _stderr = process.transform((p) => _wrapStream(p.stderr)) { | 1338 _stderr = process.transform((p) => new StringInputStream(p.stderr)) { |
1339 | 1339 |
1340 _schedule((_) { | 1340 _schedule((_) { |
1341 if (!_endScheduled) { | 1341 if (!_endScheduled) { |
1342 throw new StateError("Scheduled process $name must have shouldExit() " | 1342 throw new StateError("Scheduled process $name must have shouldExit() " |
1343 "or kill() called before the test is run."); | 1343 "or kill() called before the test is run."); |
1344 } | 1344 } |
1345 | 1345 |
1346 return _process.transform((p) { | 1346 return _process.transform((p) { |
1347 p.onExit = (c) { | 1347 p.onExit = (c) { |
1348 if (_endExpected) { | 1348 if (_endExpected) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 _endExpected = true; | 1459 _endExpected = true; |
1460 return timeout(_exitCode, _SCHEDULE_TIMEOUT, | 1460 return timeout(_exitCode, _SCHEDULE_TIMEOUT, |
1461 "waiting for process $name to exit").transform((exitCode) { | 1461 "waiting for process $name to exit").transform((exitCode) { |
1462 if (expectedExitCode != null) { | 1462 if (expectedExitCode != null) { |
1463 expect(exitCode, equals(expectedExitCode)); | 1463 expect(exitCode, equals(expectedExitCode)); |
1464 } | 1464 } |
1465 }); | 1465 }); |
1466 }); | 1466 }); |
1467 } | 1467 } |
1468 | 1468 |
1469 /// Wraps [source] and ensures it gets eagerly drained. We do this to make | |
1470 /// sure a process will exit even if we don't care about its output. | |
1471 static StringInputStream _wrapStream(InputStream source) { | |
1472 return new StringInputStream(wrapInputStream(source)); | |
1473 } | |
1474 | |
1475 /// Prints the remaining data in the process's stdout and stderr streams. | 1469 /// Prints the remaining data in the process's stdout and stderr streams. |
1476 /// Prints nothing if the straems are empty. | 1470 /// Prints nothing if the straems are empty. |
1477 Future _printStreams() { | 1471 Future _printStreams() { |
1478 Future printStream(String streamName, StringInputStream stream) { | 1472 Future printStream(String streamName, StringInputStream stream) { |
1479 return consumeStringInputStream(stream).transform((output) { | 1473 return consumeStringInputStream(stream).transform((output) { |
1480 if (output.isEmpty) return; | 1474 if (output.isEmpty) return; |
1481 | 1475 |
1482 print('\nProcess $name $streamName:'); | 1476 print('\nProcess $name $streamName:'); |
1483 for (var line in output.trim().split("\n")) { | 1477 for (var line in output.trim().split("\n")) { |
1484 print('| $line'); | 1478 print('| $line'); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 /// calling [completion] is unnecessary. | 1631 /// calling [completion] is unnecessary. |
1638 void expectLater(Future actual, matcher, {String reason, | 1632 void expectLater(Future actual, matcher, {String reason, |
1639 FailureHandler failureHandler, bool verbose: false}) { | 1633 FailureHandler failureHandler, bool verbose: false}) { |
1640 _schedule((_) { | 1634 _schedule((_) { |
1641 return actual.transform((value) { | 1635 return actual.transform((value) { |
1642 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1636 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
1643 verbose: false); | 1637 verbose: false); |
1644 }); | 1638 }); |
1645 }); | 1639 }); |
1646 } | 1640 } |
OLD | NEW |