| 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 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 * Describes a Git repository and its contents. | 985 * Describes a Git repository and its contents. |
| 986 */ | 986 */ |
| 987 class GitRepoDescriptor extends DirectoryDescriptor { | 987 class GitRepoDescriptor extends DirectoryDescriptor { |
| 988 GitRepoDescriptor(Pattern name, List<Descriptor> contents) | 988 GitRepoDescriptor(Pattern name, List<Descriptor> contents) |
| 989 : super(name, contents); | 989 : super(name, contents); |
| 990 | 990 |
| 991 /** | 991 /** |
| 992 * Creates the Git repository and commits the contents. | 992 * Creates the Git repository and commits the contents. |
| 993 */ | 993 */ |
| 994 Future<Directory> create(parentDir) { | 994 Future<Directory> create(parentDir) { |
| 995 var workingDir; | 995 return _runGitCommands(parentDir, [ |
| 996 Future runGit(List<String> args) => _runGit(args, workingDir); | 996 ['init'], |
| 997 | 997 ['add', '.'], |
| 998 return super.create(parentDir).chain((rootDir) { | 998 ['commit', '-m', 'initial commit'] |
| 999 workingDir = rootDir; | 999 ]); |
| 1000 return runGit(['init']); | |
| 1001 }).chain((_) => runGit(['add', '.'])) | |
| 1002 .chain((_) => runGit(['commit', '-m', 'initial commit', | |
| 1003 '--author="Pub Test <pub@dartlang.org>"'])) | |
| 1004 .transform((_) => workingDir); | |
| 1005 } | 1000 } |
| 1006 | 1001 |
| 1007 /** | 1002 /** |
| 1008 * Commits any changes to the Git repository. | 1003 * Commits any changes to the Git repository. |
| 1009 */ | 1004 */ |
| 1010 Future commit(parentDir) { | 1005 Future commit(parentDir) { |
| 1011 var workingDir; | 1006 return _runGitCommands(parentDir, [ |
| 1012 Future runGit(List<String> args) => _runGit(args, workingDir); | 1007 ['add', '.'], |
| 1013 | 1008 ['commit', '-m', 'update'] |
| 1014 return super.create(parentDir).chain((rootDir) { | 1009 ]); |
| 1015 workingDir = rootDir; | |
| 1016 return runGit(['add', '.']); | |
| 1017 }).chain((_) => runGit(['commit', '-m', 'update', | |
| 1018 '--author="Pub Test <pub@dartlang.org>"'])); | |
| 1019 } | 1010 } |
| 1020 | 1011 |
| 1021 /** | 1012 /** |
| 1022 * Schedules changes to be committed to the Git repository. | 1013 * Schedules changes to be committed to the Git repository. |
| 1023 */ | 1014 */ |
| 1024 void scheduleCommit() => _schedule((dir) => this.commit(dir)); | 1015 void scheduleCommit() => _schedule((dir) => this.commit(dir)); |
| 1025 | 1016 |
| 1026 /** | 1017 /** |
| 1027 * Return a Future that completes to the commit in the git repository referred | 1018 * Return a Future that completes to the commit in the git repository referred |
| 1028 * to by [ref] at the current point in the scheduled test run. | 1019 * to by [ref] at the current point in the scheduled test run. |
| 1029 */ | 1020 */ |
| 1030 Future<String> revParse(String ref) { | 1021 Future<String> revParse(String ref) { |
| 1031 var completer = new Completer<String>(); | 1022 var completer = new Completer<String>(); |
| 1032 // TODO(nweiz): inline this once issue 3197 is fixed | |
| 1033 var superCreate = super.create; | |
| 1034 _schedule((parentDir) { | 1023 _schedule((parentDir) { |
| 1035 return superCreate(parentDir).chain((rootDir) { | 1024 return super.create(parentDir).chain((rootDir) { |
| 1036 return _runGit(['rev-parse', ref], rootDir); | 1025 return _runGit(['rev-parse', ref], rootDir); |
| 1037 }).transform((output) { | 1026 }).transform((output) { |
| 1038 completer.complete(output[0]); | 1027 completer.complete(output[0]); |
| 1039 return null; | 1028 return null; |
| 1040 }); | 1029 }); |
| 1041 }); | 1030 }); |
| 1042 return completer.future; | 1031 return completer.future; |
| 1043 } | 1032 } |
| 1044 | 1033 |
| 1045 /// Schedule a Git command to run in this repository. | 1034 /// Schedule a Git command to run in this repository. |
| 1046 void scheduleGit(List<String> args) { | 1035 void scheduleGit(List<String> args) { |
| 1047 _schedule((parentDir) { | 1036 _schedule((parentDir) { |
| 1048 var gitDir = new Directory(join(parentDir, name)); | 1037 var gitDir = new Directory(join(parentDir, name)); |
| 1049 return _runGit(args, gitDir); | 1038 return _runGit(args, gitDir); |
| 1050 }); | 1039 }); |
| 1051 } | 1040 } |
| 1052 | 1041 |
| 1042 Future _runGitCommands(String parentDir, List<List<String>> commands) { |
| 1043 var workingDir; |
| 1044 |
| 1045 Future runGitStep(_) { |
| 1046 if (commands.isEmpty) return new Future.immediate(workingDir); |
| 1047 var command = commands.removeAt(0); |
| 1048 return _runGit(command, workingDir).chain(runGitStep); |
| 1049 } |
| 1050 |
| 1051 return super.create(parentDir).chain((rootDir) { |
| 1052 workingDir = rootDir; |
| 1053 return writeTextFile(join(parentDir, '.gitconfig'), ''' |
| 1054 [user] |
| 1055 name = Test Pub |
| 1056 email = pub@dartlang.org |
| 1057 '''); |
| 1058 }).chain(runGitStep); |
| 1059 } |
| 1060 |
| 1053 Future<String> _runGit(List<String> args, Directory workingDir) { | 1061 Future<String> _runGit(List<String> args, Directory workingDir) { |
| 1054 return runGit(args, workingDir: workingDir.path).transform((result) { | 1062 return runGit(args, workingDir: workingDir.path).transform((result) { |
| 1055 if (!result.success) { | 1063 if (!result.success) { |
| 1056 throw "Error running: git ${Strings.join(args, ' ')}\n" | 1064 throw "Error running: git ${Strings.join(args, ' ')}\n" |
| 1057 "${Strings.join(result.stderr, '\n')}"; | 1065 "${Strings.join(result.stderr, '\n')}"; |
| 1058 } | 1066 } |
| 1059 | 1067 |
| 1060 return result.stdout; | 1068 return result.stdout; |
| 1061 }); | 1069 }); |
| 1062 } | 1070 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 } | 1215 } |
| 1208 | 1216 |
| 1209 /** | 1217 /** |
| 1210 * Schedules a callback to be called after Pub is run with [runPub], even if it | 1218 * Schedules a callback to be called after Pub is run with [runPub], even if it |
| 1211 * fails. | 1219 * fails. |
| 1212 */ | 1220 */ |
| 1213 void _scheduleCleanup(_ScheduledEvent event) { | 1221 void _scheduleCleanup(_ScheduledEvent event) { |
| 1214 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1222 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 1215 _scheduledCleanup.add(event); | 1223 _scheduledCleanup.add(event); |
| 1216 } | 1224 } |
| OLD | NEW |