| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 var versions = _servedPackages[name].getKeys(); | 196 var versions = _servedPackages[name].getKeys(); |
| 197 _servedPackageDir.contents.addAll([ | 197 _servedPackageDir.contents.addAll([ |
| 198 file('$name.json', | 198 file('$name.json', |
| 199 JSON.stringify({'versions': versions})), | 199 JSON.stringify({'versions': versions})), |
| 200 dir(name, [ | 200 dir(name, [ |
| 201 dir('versions', flatten(versions.map((version) { | 201 dir('versions', flatten(versions.map((version) { |
| 202 return [ | 202 return [ |
| 203 file('$version.yaml', _servedPackages[name][version]), | 203 file('$version.yaml', _servedPackages[name][version]), |
| 204 tar('$version.tar.gz', [ | 204 tar('$version.tar.gz', [ |
| 205 file('pubspec.yaml', _servedPackages[name][version]), | 205 file('pubspec.yaml', _servedPackages[name][version]), |
| 206 file('$name.dart', 'main() => print("$name $version");') | 206 libDir(name, '$name $version') |
| 207 ]) | 207 ]) |
| 208 ]; | 208 ]; |
| 209 }))) | 209 }))) |
| 210 ]) | 210 ]) |
| 211 ]); | 211 ]); |
| 212 } | 212 } |
| 213 }); | 213 }); |
| 214 }); | 214 }); |
| 215 } | 215 } |
| 216 | 216 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 241 } | 241 } |
| 242 | 242 |
| 243 /** | 243 /** |
| 244 * Describes a file named `pubspec.yaml` for a library package with the given | 244 * Describes a file named `pubspec.yaml` for a library package with the given |
| 245 * [name], [version], and [dependencies]. | 245 * [name], [version], and [dependencies]. |
| 246 */ | 246 */ |
| 247 Descriptor libPubspec(String name, String version, [List dependencies]) => | 247 Descriptor libPubspec(String name, String version, [List dependencies]) => |
| 248 pubspec(package(name, version, dependencies)); | 248 pubspec(package(name, version, dependencies)); |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * Describes a directory named `lib` containing a single dart file named |
| 252 * `<name>.dart` that contains a line of Dart code. |
| 253 */ |
| 254 Descriptor libDir(String name, [String code]) { |
| 255 // Default to printing the name if no other code was given. |
| 256 if (code == null) { |
| 257 code = name; |
| 258 } |
| 259 |
| 260 return dir("lib", [ |
| 261 file("$name.dart", 'main() => "$code";') |
| 262 ]); |
| 263 } |
| 264 |
| 265 /** |
| 251 * Describes a map representing a library package with the given [name], | 266 * Describes a map representing a library package with the given [name], |
| 252 * [version], and [dependencies]. | 267 * [version], and [dependencies]. |
| 253 */ | 268 */ |
| 254 Map package(String name, String version, [List dependencies]) { | 269 Map package(String name, String version, [List dependencies]) { |
| 255 var package = {"name": name, "version": version}; | 270 var package = {"name": name, "version": version}; |
| 256 if (dependencies != null) { | 271 if (dependencies != null) { |
| 257 package["dependencies"] = _dependencyListToMap(dependencies); | 272 package["dependencies"] = _dependencyListToMap(dependencies); |
| 258 } | 273 } |
| 259 return package; | 274 return package; |
| 260 } | 275 } |
| 261 | 276 |
| 262 /** | 277 /** |
| 263 * Describes a map representing a dependency on a package in the package | 278 * Describes a map representing a dependency on a package in the package |
| 264 * repository. | 279 * repository. |
| 265 */ | 280 */ |
| 266 Map dependency(String name, [String versionConstraint]) { | 281 Map dependency(String name, [String versionConstraint]) { |
| 267 var url = port.transform((p) => "http://localhost:$p"); | 282 var url = port.transform((p) => "http://localhost:$p"); |
| 268 var dependency = {"hosted": {"name": name, "url": url}}; | 283 var dependency = {"hosted": {"name": name, "url": url}}; |
| 269 if (versionConstraint != null) dependency["version"] = versionConstraint; | 284 if (versionConstraint != null) dependency["version"] = versionConstraint; |
| 270 return dependency; | 285 return dependency; |
| 271 } | 286 } |
| 272 | 287 |
| 273 /** | 288 /** |
| 274 * Describes a directory for a package installed from the mock package repo. | |
| 275 * This directory is of the form found in the `packages/` directory. | |
| 276 */ | |
| 277 DirectoryDescriptor packageDir(String name, String version) { | |
| 278 return dir(name, [ | |
| 279 file("$name.dart", 'main() => print("$name $version");') | |
| 280 ]); | |
| 281 } | |
| 282 | |
| 283 /** | |
| 284 * Describes a directory for a package installed from the mock package server. | 289 * Describes a directory for a package installed from the mock package server. |
| 285 * This directory is of the form found in the global package cache. | 290 * This directory is of the form found in the global package cache. |
| 286 */ | 291 */ |
| 287 DirectoryDescriptor packageCacheDir(String name, String version) { | 292 DirectoryDescriptor packageCacheDir(String name, String version) { |
| 288 return dir("$name-$version", [ | 293 return dir("$name-$version", [ |
| 289 file("$name.dart", 'main() => print("$name $version");') | 294 libDir(name, '$name $version') |
| 290 ]); | 295 ]); |
| 291 } | 296 } |
| 292 | 297 |
| 293 /** | 298 /** |
| 294 * Describes a directory for a Git package. This directory is of the form found | 299 * Describes a directory for a Git package. This directory is of the form found |
| 295 * in the revision cache of the global package cache. | 300 * in the revision cache of the global package cache. |
| 296 */ | 301 */ |
| 297 DirectoryDescriptor gitPackageRevisionCacheDir(String name, [int modifier]) { | 302 DirectoryDescriptor gitPackageRevisionCacheDir(String name, [int modifier]) { |
| 298 var value = name; | 303 var value = name; |
| 299 if (modifier != null) value = "$name $modifier"; | 304 if (modifier != null) value = "$name $modifier"; |
| 300 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ | 305 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ |
| 301 file('$name.dart', 'main() => "$value";') | 306 libDir(name, value) |
| 302 ]); | 307 ]); |
| 303 } | 308 } |
| 304 | 309 |
| 305 /** | 310 /** |
| 306 * Describes a directory for a Git package. This directory is of the form found | 311 * Describes a directory for a Git package. This directory is of the form found |
| 307 * in the repo cache of the global package cache. | 312 * in the repo cache of the global package cache. |
| 308 */ | 313 */ |
| 309 DirectoryDescriptor gitPackageRepoCacheDir(String name) { | 314 DirectoryDescriptor gitPackageRepoCacheDir(String name) { |
| 310 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ | 315 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ |
| 311 dir('branches'), | 316 dir('branches'), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 322 * the format produced by the mock package server. | 327 * the format produced by the mock package server. |
| 323 * | 328 * |
| 324 * A package with a null version should not be installed. | 329 * A package with a null version should not be installed. |
| 325 */ | 330 */ |
| 326 DirectoryDescriptor packagesDir(Map<String, String> packages) { | 331 DirectoryDescriptor packagesDir(Map<String, String> packages) { |
| 327 var contents = <Descriptor>[]; | 332 var contents = <Descriptor>[]; |
| 328 packages.forEach((name, version) { | 333 packages.forEach((name, version) { |
| 329 if (version == null) { | 334 if (version == null) { |
| 330 contents.add(nothing(name)); | 335 contents.add(nothing(name)); |
| 331 } else { | 336 } else { |
| 332 contents.add(packageDir(name, version)); | 337 contents.add(dir(name, [ |
| 338 file("$name.dart", 'main() => "$name $version";') |
| 339 ])); |
| 333 } | 340 } |
| 334 }); | 341 }); |
| 335 return dir(packagesPath, contents); | 342 return dir(packagesPath, contents); |
| 336 } | 343 } |
| 337 | 344 |
| 338 /** | 345 /** |
| 339 * Describes the global package cache directory containing all the given | 346 * Describes the global package cache directory containing all the given |
| 340 * [packages], which should be name/version pairs. The packages will be | 347 * [packages], which should be name/version pairs. The packages will be |
| 341 * validated against the format produced by the mock package server. | 348 * validated against the format produced by the mock package server. |
| 342 * | 349 * |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 } | 1122 } |
| 1116 | 1123 |
| 1117 /** | 1124 /** |
| 1118 * Schedules a callback to be called after Pub is run with [runPub], even if it | 1125 * Schedules a callback to be called after Pub is run with [runPub], even if it |
| 1119 * fails. | 1126 * fails. |
| 1120 */ | 1127 */ |
| 1121 void _scheduleCleanup(_ScheduledEvent event) { | 1128 void _scheduleCleanup(_ScheduledEvent event) { |
| 1122 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1129 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 1123 _scheduledCleanup.add(event); | 1130 _scheduledCleanup.add(event); |
| 1124 } | 1131 } |
| OLD | NEW |