Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Side by Side Diff: utils/tests/pub/test_pub.dart

Issue 10913077: Use a bare git repository for the repo cache. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 * This directory is of the form found in the global package cache. 285 * This directory is of the form found in the global package cache.
286 */ 286 */
287 DirectoryDescriptor packageCacheDir(String name, String version) { 287 DirectoryDescriptor packageCacheDir(String name, String version) {
288 return dir("$name-$version", [ 288 return dir("$name-$version", [
289 file("$name.dart", 'main() => print("$name $version");') 289 file("$name.dart", 'main() => print("$name $version");')
290 ]); 290 ]);
291 } 291 }
292 292
293 /** 293 /**
294 * Describes a directory for a Git package. This directory is of the form found 294 * Describes a directory for a Git package. This directory is of the form found
295 * in the global package cache. 295 * in the revision cache of the global package cache.
296 */ 296 */
297 DirectoryDescriptor gitPackageCacheDir(String name, [int modifier]) { 297 DirectoryDescriptor gitPackageRevisionCacheDir(String name, [int modifier]) {
298 var value = name; 298 var value = name;
299 if (modifier != null) value = "$name $modifier"; 299 if (modifier != null) value = "$name $modifier";
300 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [ 300 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [
301 file('$name.dart', 'main() => "$value";') 301 file('$name.dart', 'main() => "$value";')
302 ]); 302 ]);
303 } 303 }
304 304
305 /** 305 /**
306 * Describes a directory for a Git package. This directory is of the form found
307 * in the repo cache of the global package cache.
308 */
309 DirectoryDescriptor gitPackageRepoCacheDir(String name) {
310 return dir(new RegExp("$name${@'-[a-f0-9]+'}"), [
311 dir('branches'),
312 dir('hooks'),
313 dir('info'),
314 dir('objects'),
315 dir('refs')
316 ]);
317 }
318
319 /**
306 * Describes the `packages/` directory containing all the given [packages], 320 * Describes the `packages/` directory containing all the given [packages],
307 * which should be name/version pairs. The packages will be validated against 321 * which should be name/version pairs. The packages will be validated against
308 * the format produced by the mock package server. 322 * the format produced by the mock package server.
309 * 323 *
310 * A package with a null version should not be installed. 324 * A package with a null version should not be installed.
311 */ 325 */
312 DirectoryDescriptor packagesDir(Map<String, String> packages) { 326 DirectoryDescriptor packagesDir(Map<String, String> packages) {
313 var contents = <Descriptor>[]; 327 var contents = <Descriptor>[];
314 packages.forEach((name, version) { 328 packages.forEach((name, version) {
315 if (version == null) { 329 if (version == null) {
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 * Describes a directory and its contents. These are used both for setting up 822 * Describes a directory and its contents. These are used both for setting up
809 * an expected directory tree before running a test, and for validating that 823 * an expected directory tree before running a test, and for validating that
810 * the file system matches some expectations after running it. 824 * the file system matches some expectations after running it.
811 */ 825 */
812 class DirectoryDescriptor extends Descriptor { 826 class DirectoryDescriptor extends Descriptor {
813 /** 827 /**
814 * The files and directories contained in this directory. 828 * The files and directories contained in this directory.
815 */ 829 */
816 final List<Descriptor> contents; 830 final List<Descriptor> contents;
817 831
818 DirectoryDescriptor(Pattern name, this.contents) : super(name); 832 DirectoryDescriptor(Pattern name, List<Descriptor> contents)
833 : this.contents = contents == null ? <Descriptor>[] : contents,
834 super(name);
819 835
820 /** 836 /**
821 * Creates the file within [dir]. Returns a [Future] that is completed after 837 * Creates the file within [dir]. Returns a [Future] that is completed after
822 * the creation is done. 838 * the creation is done.
823 */ 839 */
824 Future<Directory> create(parentDir) { 840 Future<Directory> create(parentDir) {
825 // Create the directory. 841 // Create the directory.
826 return ensureDir(join(parentDir, _stringName)).chain((dir) { 842 return ensureDir(join(parentDir, _stringName)).chain((dir) {
827 if (contents == null) return new Future<Directory>.immediate(dir); 843 if (contents == null) return new Future<Directory>.immediate(dir);
828 844
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 return superCreate(parentDir).chain((rootDir) { 967 return superCreate(parentDir).chain((rootDir) {
952 return _runGit(['rev-parse', ref], rootDir); 968 return _runGit(['rev-parse', ref], rootDir);
953 }).transform((output) { 969 }).transform((output) {
954 completer.complete(output[0]); 970 completer.complete(output[0]);
955 return null; 971 return null;
956 }); 972 });
957 }); 973 });
958 return completer.future; 974 return completer.future;
959 } 975 }
960 976
977 /// Schedule a Git command to run in this repository.
978 void scheduleGit(List<String> args) {
979 _schedule((parentDir) {
980 var gitDir = new Directory(join(parentDir, name));
981 return _runGit(args, gitDir);
982 });
983 }
984
961 Future<String> _runGit(List<String> args, Directory workingDir) { 985 Future<String> _runGit(List<String> args, Directory workingDir) {
962 return runProcess('git', args, workingDir: workingDir.path). 986 return runProcess('git', args, workingDir: workingDir.path).
963 transform((result) { 987 transform((result) {
964 if (!result.success) throw "Error running git: ${result.stderr}"; 988 if (!result.success) throw "Error running git: ${result.stderr}";
965 return result.stdout; 989 return result.stdout;
966 }); 990 });
967 } 991 }
968 } 992 }
969 993
970 /** 994 /**
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 } 1115 }
1092 1116
1093 /** 1117 /**
1094 * Schedules a callback to be called after Pub is run with [runPub], even if it 1118 * Schedules a callback to be called after Pub is run with [runPub], even if it
1095 * fails. 1119 * fails.
1096 */ 1120 */
1097 void _scheduleCleanup(_ScheduledEvent event) { 1121 void _scheduleCleanup(_ScheduledEvent event) {
1098 if (_scheduledCleanup == null) _scheduledCleanup = []; 1122 if (_scheduledCleanup == null) _scheduledCleanup = [];
1099 _scheduledCleanup.add(event); 1123 _scheduledCleanup.add(event);
1100 } 1124 }
OLDNEW
« utils/pub/git_source.dart ('K') | « utils/tests/pub/pub_install_git_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698