| 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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 dartBin = new File(dartBin).fullPathSync(); | 529 dartBin = new File(dartBin).fullPathSync(); |
| 530 } | 530 } |
| 531 | 531 |
| 532 // Find the main pub entrypoint. | 532 // Find the main pub entrypoint. |
| 533 var pubPath = fs.joinPaths(testDirectory, '../../pub/pub.dart'); | 533 var pubPath = fs.joinPaths(testDirectory, '../../pub/pub.dart'); |
| 534 | 534 |
| 535 var dartArgs = | 535 var dartArgs = |
| 536 ['--enable-type-checks', '--enable-asserts', pubPath, '--trace']; | 536 ['--enable-type-checks', '--enable-asserts', pubPath, '--trace']; |
| 537 dartArgs.addAll(args); | 537 dartArgs.addAll(args); |
| 538 | 538 |
| 539 var environment = { | 539 var environment = new Map.from(Platform.environment); |
| 540 'PUB_CACHE': pathInSandbox(cachePath), | 540 environment['PUB_CACHE'] = pathInSandbox(cachePath); |
| 541 'DART_SDK': pathInSandbox(sdkPath) | 541 environment['DART_SDK'] = pathInSandbox(sdkPath); |
| 542 }; | |
| 543 | 542 |
| 544 return runProcess(dartBin, dartArgs, workingDir: pathInSandbox(appPath), | 543 return runProcess(dartBin, dartArgs, workingDir: pathInSandbox(appPath), |
| 545 environment: environment); | 544 environment: environment); |
| 546 }).transform((result) { | 545 }).transform((result) { |
| 547 var failures = []; | 546 var failures = []; |
| 548 | 547 |
| 549 _validateOutput(failures, 'stdout', output, result.stdout); | 548 _validateOutput(failures, 'stdout', output, result.stdout); |
| 550 _validateOutput(failures, 'stderr', error, result.stderr); | 549 _validateOutput(failures, 'stderr', error, result.stderr); |
| 551 | 550 |
| 552 if (result.exitCode != exitCode) { | 551 if (result.exitCode != exitCode) { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 var workingDir; | 1043 var workingDir; |
| 1045 | 1044 |
| 1046 Future runGitStep(_) { | 1045 Future runGitStep(_) { |
| 1047 if (commands.isEmpty) return new Future.immediate(workingDir); | 1046 if (commands.isEmpty) return new Future.immediate(workingDir); |
| 1048 var command = commands.removeAt(0); | 1047 var command = commands.removeAt(0); |
| 1049 return _runGit(command, workingDir).chain(runGitStep); | 1048 return _runGit(command, workingDir).chain(runGitStep); |
| 1050 } | 1049 } |
| 1051 | 1050 |
| 1052 return super.create(parentDir).chain((rootDir) { | 1051 return super.create(parentDir).chain((rootDir) { |
| 1053 workingDir = rootDir; | 1052 workingDir = rootDir; |
| 1054 return runGitStep(null); | 1053 return writeTextFile(join(parentDir, '.gitconfig'), ''' |
| 1055 }); | 1054 [user] |
| 1055 name = Test Pub |
| 1056 email = pub@dartlang.org |
| 1057 '''); |
| 1058 }).chain(runGitStep); |
| 1056 } | 1059 } |
| 1057 | 1060 |
| 1058 Future<String> _runGit(List<String> args, Directory workingDir) { | 1061 Future<String> _runGit(List<String> args, Directory workingDir) { |
| 1059 // Explicitly specify the committer information. Git needs this to commit | 1062 return runGit(args, workingDir: workingDir.path).transform((result) { |
| 1060 // and we don't want to rely on the buildbots having this already set up. | |
| 1061 var environment = { | |
| 1062 'GIT_COMMITTER_NAME': 'Pub Test', | |
| 1063 'GIT_COMMITTER_EMAIL': 'pub@dartlang.org' | |
| 1064 }; | |
| 1065 | |
| 1066 return runGit(args, workingDir: workingDir.path, | |
| 1067 environment: environment).transform((result) { | |
| 1068 if (!result.success) { | 1063 if (!result.success) { |
| 1069 throw "Error running: git ${Strings.join(args, ' ')}\n" | 1064 throw "Error running: git ${Strings.join(args, ' ')}\n" |
| 1070 "${Strings.join(result.stderr, '\n')}"; | 1065 "${Strings.join(result.stderr, '\n')}"; |
| 1071 } | 1066 } |
| 1072 | 1067 |
| 1073 return result.stdout; | 1068 return result.stdout; |
| 1074 }); | 1069 }); |
| 1075 } | 1070 } |
| 1076 } | 1071 } |
| 1077 | 1072 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 } | 1215 } |
| 1221 | 1216 |
| 1222 /** | 1217 /** |
| 1223 * 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 |
| 1224 * fails. | 1219 * fails. |
| 1225 */ | 1220 */ |
| 1226 void _scheduleCleanup(_ScheduledEvent event) { | 1221 void _scheduleCleanup(_ScheduledEvent event) { |
| 1227 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1222 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 1228 _scheduledCleanup.add(event); | 1223 _scheduledCleanup.add(event); |
| 1229 } | 1224 } |
| OLD | NEW |