| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 /// exist only for the duration of the pub run. | 87 /// exist only for the duration of the pub run. |
| 88 /// | 88 /// |
| 89 /// Subsequent calls to [serve] will replace the previous server. | 89 /// Subsequent calls to [serve] will replace the previous server. |
| 90 void serve([List<d.Descriptor> contents]) { | 90 void serve([List<d.Descriptor> contents]) { |
| 91 var baseDir = d.dir("serve-dir", contents); | 91 var baseDir = d.dir("serve-dir", contents); |
| 92 | 92 |
| 93 _hasServer = true; | 93 _hasServer = true; |
| 94 | 94 |
| 95 schedule(() { | 95 schedule(() { |
| 96 return _closeServer().then((_) { | 96 return _closeServer().then((_) { |
| 97 return SafeHttpServer.bind("localhost", 0).then((server) { | 97 return SafeHttpServer.bind("127.0.0.1", 0).then((server) { |
| 98 _server = server; | 98 _server = server; |
| 99 server.listen((request) { | 99 server.listen((request) { |
| 100 currentSchedule.heartbeat(); | 100 currentSchedule.heartbeat(); |
| 101 var response = request.response; | 101 var response = request.response; |
| 102 try { | 102 try { |
| 103 var path = request.uri.path.replaceFirst("/", ""); | 103 var path = request.uri.path.replaceFirst("/", ""); |
| 104 _requestedPaths.add(path); | 104 _requestedPaths.add(path); |
| 105 | 105 |
| 106 response.persistentConnection = false; | 106 response.persistentConnection = false; |
| 107 var stream = baseDir.load(path); | 107 var stream = baseDir.load(path); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 environment['DART_SDK'] = pathInSandbox(sdkPath); | 478 environment['DART_SDK'] = pathInSandbox(sdkPath); |
| 479 if (tokenEndpoint != null) { | 479 if (tokenEndpoint != null) { |
| 480 environment['_PUB_TEST_TOKEN_ENDPOINT'] = | 480 environment['_PUB_TEST_TOKEN_ENDPOINT'] = |
| 481 tokenEndpoint.toString(); | 481 tokenEndpoint.toString(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 // If there is a server running, tell pub what its URL is so hosted | 484 // If there is a server running, tell pub what its URL is so hosted |
| 485 // dependencies will look there. | 485 // dependencies will look there. |
| 486 if (_hasServer) { | 486 if (_hasServer) { |
| 487 return port.then((p) { | 487 return port.then((p) { |
| 488 environment['PUB_HOSTED_URL'] = "http://localhost:$p"; | 488 environment['PUB_HOSTED_URL'] = "http://127.0.0.1:$p"; |
| 489 return environment; | 489 return environment; |
| 490 }); | 490 }); |
| 491 } | 491 } |
| 492 | 492 |
| 493 return environment; | 493 return environment; |
| 494 }); | 494 }); |
| 495 | 495 |
| 496 return new PubProcess.start(dartBin, dartArgs, environment: environmentFuture, | 496 return new PubProcess.start(dartBin, dartArgs, environment: environmentFuture, |
| 497 workingDirectory: pathInSandbox(appPath), | 497 workingDirectory: pathInSandbox(appPath), |
| 498 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 498 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 bool matches(item, Map matchState) { | 836 bool matches(item, Map matchState) { |
| 837 if (item is! Pair) return false; | 837 if (item is! Pair) return false; |
| 838 return _firstMatcher.matches(item.first, matchState) && | 838 return _firstMatcher.matches(item.first, matchState) && |
| 839 _lastMatcher.matches(item.last, matchState); | 839 _lastMatcher.matches(item.last, matchState); |
| 840 } | 840 } |
| 841 | 841 |
| 842 Description describe(Description description) { | 842 Description describe(Description description) { |
| 843 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 843 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 844 } | 844 } |
| 845 } | 845 } |
| OLD | NEW |