OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 14 matching lines...) Expand all Loading... |
25 import '../../pub/entrypoint.dart'; | 25 import '../../pub/entrypoint.dart'; |
26 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides | 26 // TODO(rnystrom): Using "gitlib" as the prefix here is ugly, but "git" collides |
27 // with the git descriptor method. Maybe we should try to clean up the top level | 27 // with the git descriptor method. Maybe we should try to clean up the top level |
28 // scope a bit? | 28 // scope a bit? |
29 import '../../pub/git.dart' as gitlib; | 29 import '../../pub/git.dart' as gitlib; |
30 import '../../pub/git_source.dart'; | 30 import '../../pub/git_source.dart'; |
31 import '../../pub/hosted_source.dart'; | 31 import '../../pub/hosted_source.dart'; |
32 import '../../pub/http.dart'; | 32 import '../../pub/http.dart'; |
33 import '../../pub/io.dart'; | 33 import '../../pub/io.dart'; |
34 import '../../pub/path_source.dart'; | 34 import '../../pub/path_source.dart'; |
| 35 import '../../pub/safe_http_server.dart'; |
35 import '../../pub/sdk_source.dart'; | 36 import '../../pub/sdk_source.dart'; |
36 import '../../pub/system_cache.dart'; | 37 import '../../pub/system_cache.dart'; |
37 import '../../pub/utils.dart'; | 38 import '../../pub/utils.dart'; |
38 import '../../pub/validator.dart'; | 39 import '../../pub/validator.dart'; |
39 import 'command_line_config.dart'; | 40 import 'command_line_config.dart'; |
40 | 41 |
41 /// This should be called at the top of a test file to set up an appropriate | 42 /// This should be called at the top of a test file to set up an appropriate |
42 /// test configuration for the machine running the tests. | 43 /// test configuration for the machine running the tests. |
43 initConfig() { | 44 initConfig() { |
44 // If we aren't running on the bots, use the human-friendly config. | 45 // If we aren't running on the bots, use the human-friendly config. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 96 |
96 /// Creates an HTTP server to serve [contents] as static files. This server will | 97 /// Creates an HTTP server to serve [contents] as static files. This server will |
97 /// exist only for the duration of the pub run. | 98 /// exist only for the duration of the pub run. |
98 /// | 99 /// |
99 /// Subsequent calls to [serve] will replace the previous server. | 100 /// Subsequent calls to [serve] will replace the previous server. |
100 void serve([List<Descriptor> contents]) { | 101 void serve([List<Descriptor> contents]) { |
101 var baseDir = dir("serve-dir", contents); | 102 var baseDir = dir("serve-dir", contents); |
102 | 103 |
103 _schedule((_) { | 104 _schedule((_) { |
104 return _closeServer().then((_) { | 105 return _closeServer().then((_) { |
105 return HttpServer.bind("127.0.0.1", 0).then((server) { | 106 return SafeHttpServer.bind("127.0.0.1", 0).then((server) { |
106 _server = server; | 107 _server = server; |
107 server.listen((request) { | 108 server.listen((request) { |
108 var response = request.response; | 109 var response = request.response; |
109 var path = request.uri.path.replaceFirst("/", "").split("/"); | 110 var path = request.uri.path.replaceFirst("/", "").split("/"); |
110 response.persistentConnection = false; | 111 response.persistentConnection = false; |
111 var stream; | 112 var stream; |
112 try { | 113 try { |
113 stream = baseDir.load(path); | 114 stream = baseDir.load(path); |
114 } catch (e) { | 115 } catch (e) { |
115 response.statusCode = 404; | 116 response.statusCode = 404; |
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1503 /// The requests to be ignored. | 1504 /// The requests to be ignored. |
1504 final _ignored = new Set<Pair<String, String>>(); | 1505 final _ignored = new Set<Pair<String, String>>(); |
1505 | 1506 |
1506 ScheduledServer._(this._server); | 1507 ScheduledServer._(this._server); |
1507 | 1508 |
1508 /// Creates a new server listening on an automatically-allocated port on | 1509 /// Creates a new server listening on an automatically-allocated port on |
1509 /// localhost. | 1510 /// localhost. |
1510 factory ScheduledServer() { | 1511 factory ScheduledServer() { |
1511 var scheduledServer; | 1512 var scheduledServer; |
1512 scheduledServer = new ScheduledServer._(_scheduleValue((_) { | 1513 scheduledServer = new ScheduledServer._(_scheduleValue((_) { |
1513 return HttpServer.bind("127.0.0.1", 0).then((server) { | 1514 return SafeHttpServer.bind("127.0.0.1", 0).then((server) { |
1514 server.listen(scheduledServer._awaitHandle); | 1515 server.listen(scheduledServer._awaitHandle); |
1515 _scheduleCleanup((_) => server.close()); | 1516 _scheduleCleanup((_) => server.close()); |
1516 return server; | 1517 return server; |
1517 }); | 1518 }); |
1518 })); | 1519 })); |
1519 return scheduledServer; | 1520 return scheduledServer; |
1520 } | 1521 } |
1521 | 1522 |
1522 /// The port on which the server is listening. | 1523 /// The port on which the server is listening. |
1523 Future<int> get port => _server.then((s) => s.port); | 1524 Future<int> get port => _server.then((s) => s.port); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 /// calling [completion] is unnecessary. | 1635 /// calling [completion] is unnecessary. |
1635 void expectLater(Future actual, matcher, {String reason, | 1636 void expectLater(Future actual, matcher, {String reason, |
1636 FailureHandler failureHandler, bool verbose: false}) { | 1637 FailureHandler failureHandler, bool verbose: false}) { |
1637 _schedule((_) { | 1638 _schedule((_) { |
1638 return actual.then((value) { | 1639 return actual.then((value) { |
1639 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1640 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
1640 verbose: false); | 1641 verbose: false); |
1641 }); | 1642 }); |
1642 }); | 1643 }); |
1643 } | 1644 } |
OLD | NEW |