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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 return shelf_io.serve((request) { | 163 return shelf_io.serve((request) { |
164 currentSchedule.heartbeat(); | 164 currentSchedule.heartbeat(); |
165 var path = request.url.path.replaceFirst("/", ""); | 165 var path = request.url.path.replaceFirst("/", ""); |
166 _requestedPaths.add(path); | 166 _requestedPaths.add(path); |
167 | 167 |
168 return validateStream(baseDir.load(path)) | 168 return validateStream(baseDir.load(path)) |
169 .then((stream) => new shelf.Response.ok(stream)) | 169 .then((stream) => new shelf.Response.ok(stream)) |
170 .catchError((error) { | 170 .catchError((error) { |
171 return new shelf.Response.notFound('File "$path" not found.'); | 171 return new shelf.Response.notFound('File "$path" not found.'); |
172 }); | 172 }); |
173 }, '127.0.0.1', 0).then((server) { | 173 }, 'localhost', 0).then((server) { |
174 _server = server; | 174 _server = server; |
175 _portCompleter.complete(_server.port); | 175 _portCompleter.complete(_server.port); |
176 currentSchedule.onComplete.schedule(_closeServer); | 176 currentSchedule.onComplete.schedule(_closeServer); |
177 }); | 177 }); |
178 }); | 178 }); |
179 }, 'starting a server serving:\n${baseDir.describe()}'); | 179 }, 'starting a server serving:\n${baseDir.describe()}'); |
180 } | 180 } |
181 | 181 |
182 /// Closes [_server]. Returns a [Future] that will complete after the [_server] | 182 /// Closes [_server]. Returns a [Future] that will complete after the [_server] |
183 /// is closed. | 183 /// is closed. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 528 |
529 if (tokenEndpoint != null) { | 529 if (tokenEndpoint != null) { |
530 environment['_PUB_TEST_TOKEN_ENDPOINT'] = | 530 environment['_PUB_TEST_TOKEN_ENDPOINT'] = |
531 tokenEndpoint.toString(); | 531 tokenEndpoint.toString(); |
532 } | 532 } |
533 | 533 |
534 // If there is a server running, tell pub what its URL is so hosted | 534 // If there is a server running, tell pub what its URL is so hosted |
535 // dependencies will look there. | 535 // dependencies will look there. |
536 if (_hasServer) { | 536 if (_hasServer) { |
537 return port.then((p) { | 537 return port.then((p) { |
538 environment['PUB_HOSTED_URL'] = "http://127.0.0.1:$p"; | 538 environment['PUB_HOSTED_URL'] = "http://localhost:$p"; |
539 return environment; | 539 return environment; |
540 }); | 540 }); |
541 } | 541 } |
542 | 542 |
543 return environment; | 543 return environment; |
544 }); | 544 }); |
545 | 545 |
546 return new PubProcess.start(dartBin, dartArgs, environment: environmentFuture, | 546 return new PubProcess.start(dartBin, dartArgs, environment: environmentFuture, |
547 workingDirectory: pathInSandbox(appPath), | 547 workingDirectory: pathInSandbox(appPath), |
548 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 548 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 _lastMatcher.matches(item.last, matchState); | 909 _lastMatcher.matches(item.last, matchState); |
910 } | 910 } |
911 | 911 |
912 Description describe(Description description) { | 912 Description describe(Description description) { |
913 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 913 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
914 } | 914 } |
915 } | 915 } |
916 | 916 |
917 /// A [StreamMatcher] that matches multiple lines of output. | 917 /// A [StreamMatcher] that matches multiple lines of output. |
918 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 918 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |