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. | 5 /// Test infrastructure for testing pub. |
6 /// | 6 /// |
7 /// Unlike typical unit tests, most pub tests are integration tests that stage | 7 /// Unlike typical unit tests, most pub tests are integration tests that stage |
8 /// some stuff on the file system, run pub, and then validate the results. This | 8 /// some stuff on the file system, run pub, and then validate the results. This |
9 /// library provides an API to build tests like that. | 9 /// library provides an API to build tests like that. |
10 library test_pub; | 10 library test_pub; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 }); | 211 }); |
212 }, 'localhost', 0).then((server) { | 212 }, 'localhost', 0).then((server) { |
213 _server = server; | 213 _server = server; |
214 _portCompleter.complete(_server.port); | 214 _portCompleter.complete(_server.port); |
215 currentSchedule.onComplete.schedule(_closeServer); | 215 currentSchedule.onComplete.schedule(_closeServer); |
216 }); | 216 }); |
217 }); | 217 }); |
218 }, 'starting a server serving:\n${baseDir.describe()}'); | 218 }, 'starting a server serving:\n${baseDir.describe()}'); |
219 } | 219 } |
220 | 220 |
| 221 /// Like [serve], but reports an error if a request ever comes in to the server. |
| 222 void serveErrors() { |
| 223 _hasServer = true; |
| 224 |
| 225 schedule(() async { |
| 226 await _closeServer(); |
| 227 |
| 228 _server = await shelf_io.serve((request) { |
| 229 fail("The HTTP server received an unexpected request:\n" |
| 230 "${request.method} ${request.requestedUri}"); |
| 231 return new shelf.Response.forbidden(null); |
| 232 }, 'localhost', 0); |
| 233 |
| 234 _portCompleter.complete(_server.port); |
| 235 currentSchedule.onComplete.schedule(_closeServer); |
| 236 }); |
| 237 } |
| 238 |
221 /// Closes [_server]. | 239 /// Closes [_server]. |
222 /// | 240 /// |
223 /// Returns a [Future] that completes after the [_server] is closed. | 241 /// Returns a [Future] that completes after the [_server] is closed. |
224 Future _closeServer() { | 242 Future _closeServer() { |
225 if (_server == null) return new Future.value(); | 243 if (_server == null) return new Future.value(); |
226 var future = _server.close(); | 244 var future = _server.close(); |
227 _server = null; | 245 _server = null; |
228 _hasServer = false; | 246 _hasServer = false; |
229 _portCompleterCache = null; | 247 _portCompleterCache = null; |
230 return future; | 248 return future; |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 _lastMatcher.matches(item.last, matchState); | 991 _lastMatcher.matches(item.last, matchState); |
974 } | 992 } |
975 | 993 |
976 Description describe(Description description) { | 994 Description describe(Description description) { |
977 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 995 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
978 } | 996 } |
979 } | 997 } |
980 | 998 |
981 /// A [StreamMatcher] that matches multiple lines of output. | 999 /// A [StreamMatcher] that matches multiple lines of output. |
982 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1000 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |