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

Side by Side Diff: utils/tests/pub/test_pub.dart

Issue 11434118: Add validation infrastructure for "pub lish". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix a chain/transform bug Created 8 years 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
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 /** 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 return dir("lib", [ 261 return dir("lib", [
262 file("$name.dart", 'main() => "$code";') 262 file("$name.dart", 'main() => "$code";')
263 ]); 263 ]);
264 } 264 }
265 265
266 /** 266 /**
267 * Describes a map representing a library package with the given [name], 267 * Describes a map representing a library package with the given [name],
268 * [version], and [dependencies]. 268 * [version], and [dependencies].
269 */ 269 */
270 Map package(String name, String version, [List dependencies]) { 270 Map package(String name, String version, [List dependencies]) {
271 var package = {"name": name, "version": version}; 271 var package = {
272 "name": name,
273 "version": version,
274 "author": "Nathan Weizenbaum <nweiz@google.com>",
275 "homepage": "http://pub.dartlang.org"
276 };
272 if (dependencies != null) { 277 if (dependencies != null) {
273 package["dependencies"] = _dependencyListToMap(dependencies); 278 package["dependencies"] = _dependencyListToMap(dependencies);
274 } 279 }
275 return package; 280 return package;
276 } 281 }
277 282
278 /** 283 /**
279 * Describes a map representing a dependency on a package in the package 284 * Describes a map representing a dependency on a package in the package
280 * repository. 285 * repository.
281 */ 286 */
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 } 1347 }
1343 1348
1344 /// Reads the next line of stderr from the process. 1349 /// Reads the next line of stderr from the process.
1345 Future<String> nextErrLine() { 1350 Future<String> nextErrLine() {
1346 return _scheduleValue((_) { 1351 return _scheduleValue((_) {
1347 return timeout(_stderr.chain(readLine), 5000, 1352 return timeout(_stderr.chain(readLine), 5000,
1348 "waiting for the next stderr line from process $name"); 1353 "waiting for the next stderr line from process $name");
1349 }); 1354 });
1350 } 1355 }
1351 1356
1357 /// Reads the remaining stdout from the process. This should only be called
1358 /// after kill() or shouldExit().
1359 Future<String> remainingStdout() {
1360 if (!_endScheduled) {
1361 throw new StateError("remainingStdout() should only be called after "
1362 "kill() or shouldExit().");
1363 }
1364
1365 return _scheduleValue((_) {
1366 return timeout(_stdout.chain(consumeStringInputStream), 5000,
Bob Nystrom 2012/12/05 18:57:40 Make a constant for all of these "5000"s, please.
nweiz 2012/12/05 21:59:59 Done.
1367 "waiting for the last stdout line from process $name");
1368 });
1369 }
1370
1371 /// Reads the remaining stderr from the process. This should only be called
1372 /// after kill() or shouldExit().
1373 Future<String> remainingStderr() {
1374 if (!_endScheduled) {
1375 throw new StateError("remainingStderr() should only be called after "
1376 "kill() or shouldExit().");
1377 }
1378
1379 return _scheduleValue((_) {
1380 return timeout(_stderr.chain(consumeStringInputStream), 5000,
1381 "waiting for the last stderr line from process $name");
1382 });
1383 }
1384
1352 /// Writes [line] to the process as stdin. 1385 /// Writes [line] to the process as stdin.
1353 void writeLine(String line) { 1386 void writeLine(String line) {
1354 _schedule((_) => _process.transform((p) => p.stdin.writeString('$line\n'))); 1387 _schedule((_) => _process.transform((p) => p.stdin.writeString('$line\n')));
1355 } 1388 }
1356 1389
1357 /// Kills the process, and waits until it's dead. 1390 /// Kills the process, and waits until it's dead.
1358 void kill() { 1391 void kill() {
1359 _endScheduled = true; 1392 _endScheduled = true;
1360 _schedule((_) { 1393 _schedule((_) {
1361 _endExpected = true; 1394 _endExpected = true;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 /// A class representing an [HttpServer] that's scheduled to run in the course 1437 /// A class representing an [HttpServer] that's scheduled to run in the course
1405 /// of the test. This class allows the server's request handling to be scheduled 1438 /// of the test. This class allows the server's request handling to be scheduled
1406 /// synchronously. All operations on this class are scheduled. 1439 /// synchronously. All operations on this class are scheduled.
1407 class ScheduledServer { 1440 class ScheduledServer {
1408 /// The wrapped server. 1441 /// The wrapped server.
1409 final Future<HttpServer> _server; 1442 final Future<HttpServer> _server;
1410 1443
1411 /// The queue of handlers to run for upcoming requests. 1444 /// The queue of handlers to run for upcoming requests.
1412 final _handlers = new Queue<Future>(); 1445 final _handlers = new Queue<Future>();
1413 1446
1447 /// The requests to be ignored.
1448 final _ignored = new Set<Pair<String, String>>();
1449
1414 ScheduledServer._(this._server); 1450 ScheduledServer._(this._server);
1415 1451
1416 /// Creates a new server listening on an automatically-allocated port on 1452 /// Creates a new server listening on an automatically-allocated port on
1417 /// localhost. 1453 /// localhost.
1418 factory ScheduledServer() { 1454 factory ScheduledServer() {
1419 var scheduledServer; 1455 var scheduledServer;
1420 scheduledServer = new ScheduledServer._(_scheduleValue((_) { 1456 scheduledServer = new ScheduledServer._(_scheduleValue((_) {
1421 var server = new HttpServer(); 1457 var server = new HttpServer();
1422 server.defaultRequestHandler = scheduledServer._awaitHandle; 1458 server.defaultRequestHandler = scheduledServer._awaitHandle;
1423 server.listen("127.0.0.1", 0); 1459 server.listen("127.0.0.1", 0);
(...skipping 25 matching lines...) Expand all
1449 var future = handler(request, response); 1485 var future = handler(request, response);
1450 if (future == null) future = new Future.immediate(null); 1486 if (future == null) future = new Future.immediate(null);
1451 chainToCompleter(future, requestCompleteCompleter); 1487 chainToCompleter(future, requestCompleteCompleter);
1452 }); 1488 });
1453 return timeout(requestCompleteCompleter.future, 1489 return timeout(requestCompleteCompleter.future,
1454 5000, "waiting for $method $path"); 1490 5000, "waiting for $method $path");
1455 }); 1491 });
1456 _handlers.add(handlerCompleter.future); 1492 _handlers.add(handlerCompleter.future);
1457 } 1493 }
1458 1494
1495 /// Ignore all requests with the given [method] and [path]. If one is
1496 /// received, don't respond to it.
1497 void ignore(String method, String path) =>
1498 _ignored.add(new Pair(method, path));
1499
1459 /// Raises an error complaining of an unexpected request. 1500 /// Raises an error complaining of an unexpected request.
1460 void _awaitHandle(HttpRequest request, HttpResponse response) { 1501 void _awaitHandle(HttpRequest request, HttpResponse response) {
1502 if (_ignored.contains(new Pair(request.method, request.path))) return;
1461 var future = timeout(new Future.immediate(null).chain((_) { 1503 var future = timeout(new Future.immediate(null).chain((_) {
1462 var handlerFuture = _handlers.removeFirst(); 1504 if (_handlers.isEmpty) {
1463 if (handlerFuture == null) {
1464 fail('Unexpected ${request.method} request to ${request.path}.'); 1505 fail('Unexpected ${request.method} request to ${request.path}.');
1465 } 1506 }
1466 return handlerFuture; 1507 return _handlers.removeFirst();
1467 }).transform((handler) { 1508 }).transform((handler) {
1468 handler(request, response); 1509 handler(request, response);
1469 }), 5000, "waiting for a handler for ${request.method} ${request.path}"); 1510 }), 5000, "waiting for a handler for ${request.method} ${request.path}");
1470 expect(future, completes); 1511 expect(future, completes);
1471 } 1512 }
1472 } 1513 }
1473 1514
1474 /** 1515 /**
1475 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, 1516 * 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. 1517 * and [Future]s) and recursively resolves all the [Future]s contained within.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 /// calling [completion] is unnecessary. 1578 /// calling [completion] is unnecessary.
1538 void expectLater(Future actual, matcher, {String reason, 1579 void expectLater(Future actual, matcher, {String reason,
1539 FailureHandler failureHandler, bool verbose: false}) { 1580 FailureHandler failureHandler, bool verbose: false}) {
1540 _schedule((_) { 1581 _schedule((_) {
1541 return actual.transform((value) { 1582 return actual.transform((value) {
1542 expect(value, matcher, reason: reason, failureHandler: failureHandler, 1583 expect(value, matcher, reason: reason, failureHandler: failureHandler,
1543 verbose: false); 1584 verbose: false);
1544 }); 1585 });
1545 }); 1586 });
1546 } 1587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698