| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 var baseDir = d.dir("serve-dir", contents); | 96 var baseDir = d.dir("serve-dir", contents); |
| 97 | 97 |
| 98 schedule(() { | 98 schedule(() { |
| 99 return _closeServer().then((_) { | 99 return _closeServer().then((_) { |
| 100 return SafeHttpServer.bind("localhost", 0).then((server) { | 100 return SafeHttpServer.bind("localhost", 0).then((server) { |
| 101 _server = server; | 101 _server = server; |
| 102 server.listen((request) { | 102 server.listen((request) { |
| 103 var response = request.response; | 103 var response = request.response; |
| 104 try { | 104 try { |
| 105 var path = request.uri.path.replaceFirst("/", ""); | 105 var path = request.uri.path.replaceFirst("/", ""); |
| 106 currentSchedule.addDebugInfo("[$path] got request"); |
| 106 | 107 |
| 107 if (_requestedPaths == null) _requestedPaths = <String>[]; | 108 if (_requestedPaths == null) _requestedPaths = <String>[]; |
| 108 _requestedPaths.add(path); | 109 _requestedPaths.add(path); |
| 109 | 110 |
| 110 response.persistentConnection = false; | 111 response.persistentConnection = false; |
| 111 var stream = baseDir.load(path); | 112 var stream = baseDir.load(path); |
| 112 | 113 |
| 113 new ByteStream(stream).toBytes().then((data) { | 114 new ByteStream(stream).toBytes().then((data) { |
| 115 currentSchedule.addDebugInfo("[$path] sending response:\n" |
| 116 "${new String.fromCharCodes(data)}"); |
| 114 response.statusCode = 200; | 117 response.statusCode = 200; |
| 115 response.contentLength = data.length; | 118 response.contentLength = data.length; |
| 116 response.add(data); | 119 response.add(data); |
| 117 response.close(); | 120 response.close(); |
| 118 }).catchError((e) { | 121 }).catchError((e) { |
| 122 currentSchedule.addDebugInfo("[$path] got load error: $e"); |
| 119 response.statusCode = 404; | 123 response.statusCode = 404; |
| 120 response.contentLength = 0; | 124 response.contentLength = 0; |
| 121 response.close(); | 125 response.close(); |
| 122 }); | 126 }); |
| 123 } catch (e) { | 127 } catch (e) { |
| 128 currentSchedule.addDebugInfo("[$path] got error: $e"); |
| 124 currentSchedule.signalError(e); | 129 currentSchedule.signalError(e); |
| 125 response.statusCode = 500; | 130 response.statusCode = 500; |
| 126 response.close(); | 131 response.close(); |
| 127 return; | 132 return; |
| 128 } | 133 } |
| 129 }); | 134 }); |
| 130 _portCompleter.complete(_server.port); | 135 _portCompleter.complete(_server.port); |
| 131 currentSchedule.onComplete.schedule(_closeServer); | 136 currentSchedule.onComplete.schedule(_closeServer); |
| 132 return null; | 137 return null; |
| 133 }); | 138 }); |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 bool matches(item, MatchState matchState) { | 699 bool matches(item, MatchState matchState) { |
| 695 if (item is! Pair) return false; | 700 if (item is! Pair) return false; |
| 696 return _firstMatcher.matches(item.first, matchState) && | 701 return _firstMatcher.matches(item.first, matchState) && |
| 697 _lastMatcher.matches(item.last, matchState); | 702 _lastMatcher.matches(item.last, matchState); |
| 698 } | 703 } |
| 699 | 704 |
| 700 Description describe(Description description) { | 705 Description describe(Description description) { |
| 701 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 706 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 702 } | 707 } |
| 703 } | 708 } |
| OLD | NEW |