| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub | 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub |
| 7 * tests are integration tests that stage some stuff on the file system, run | 7 * tests are integration tests that stage some stuff on the file system, run |
| 8 * pub, and then validate the results. This library provides an API to build | 8 * pub, and then validate the results. This library provides an API to build |
| 9 * tests like that. | 9 * tests like that. |
| 10 */ | 10 */ |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // putting this at 10ms to be safe. | 119 // putting this at 10ms to be safe. |
| 120 return sleep(10); | 120 return sleep(10); |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Creates an HTTP server that replicates the structure of pub.dartlang.org. | 124 * Creates an HTTP server that replicates the structure of pub.dartlang.org. |
| 125 * [pubspecs] is a list of YAML-format pubspecs representing the packages to | 125 * [pubspecs] is a list of YAML-format pubspecs representing the packages to |
| 126 * serve. | 126 * serve. |
| 127 */ | 127 */ |
| 128 void servePackages(String host, int port, List<String> pubspecs) { | 128 void servePackages(String host, int port, List<String> pubspecs) { |
| 129 var packages = <Map<String, String>>{}; | 129 var packages = <String, Map<String, String>>{}; |
| 130 pubspecs.forEach((spec) { | 130 pubspecs.forEach((spec) { |
| 131 var parsed = loadYaml(spec); | 131 var parsed = loadYaml(spec); |
| 132 var name = parsed['name']; | 132 var name = parsed['name']; |
| 133 var version = parsed['version']; | 133 var version = parsed['version']; |
| 134 packages.putIfAbsent(name, () => <String>{})[version] = spec; | 134 packages.putIfAbsent(name, () => <String, String>{})[version] = spec; |
| 135 }); | 135 }); |
| 136 | 136 |
| 137 serve(host, port, [ | 137 serve(host, port, [ |
| 138 dir('packages', flatten(packages.getKeys().map((name) { | 138 dir('packages', flatten(packages.getKeys().map((name) { |
| 139 return [ | 139 return [ |
| 140 file('$name.json', | 140 file('$name.json', |
| 141 JSON.stringify({'versions': packages[name].getKeys()})), | 141 JSON.stringify({'versions': packages[name].getKeys()})), |
| 142 dir(name, [ | 142 dir(name, [ |
| 143 dir('versions', flatten(packages[name].getKeys().map((version) { | 143 dir('versions', flatten(packages[name].getKeys().map((version) { |
| 144 return [ | 144 return [ |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 } | 811 } |
| 812 | 812 |
| 813 /** | 813 /** |
| 814 * Schedules a callback to be called after Pub is run with [runPub], even if it | 814 * Schedules a callback to be called after Pub is run with [runPub], even if it |
| 815 * fails. | 815 * fails. |
| 816 */ | 816 */ |
| 817 void _scheduleCleanup(_ScheduledEvent event) { | 817 void _scheduleCleanup(_ScheduledEvent event) { |
| 818 if (_scheduledCleanup == null) _scheduledCleanup = []; | 818 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 819 _scheduledCleanup.add(event); | 819 _scheduledCleanup.add(event); |
| 820 } | 820 } |
| OLD | NEW |