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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 /** | 240 /** |
241 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and | 241 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and |
242 * validates that its results match [output], [error], and [exitCode]. | 242 * validates that its results match [output], [error], and [exitCode]. |
243 */ | 243 */ |
244 void schedulePub([List<String> args, Pattern output, Pattern error, | 244 void schedulePub([List<String> args, Pattern output, Pattern error, |
245 int exitCode = 0]) { | 245 int exitCode = 0]) { |
246 _schedule((sandboxDir) { | 246 _schedule((sandboxDir) { |
247 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); | 247 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); |
248 | 248 |
249 return ensureDir(pathInSandbox(appPath)).chain((_) { | 249 return ensureDir(pathInSandbox(appPath)).chain((_) { |
250 // Find a dart executable we can use to run pub. Uses the one that the | 250 // Find a Dart executable we can use to spawn. Use the same one that was |
251 // test infrastructure uses. We are not using new Options.executable here | 251 // used to run this script itself. |
252 // because that gets confused if you invoked Dart through a shell script. | 252 var dartBin = new Options().executable; |
| 253 |
| 254 // If the executable looks like a path, get its full path. That way we |
| 255 // can still find it when we spawn it with a different working directory. |
| 256 if (dartBin.contains(Platform.pathSeparator)) { |
| 257 dartBin = new File(dartBin).fullPathSync(); |
| 258 } |
| 259 |
253 var scriptDir = new File(new Options().script).directorySync().path; | 260 var scriptDir = new File(new Options().script).directorySync().path; |
254 var platform = Platform.operatingSystem; | |
255 var dartBin = join(scriptDir, '../../../tools/testing/bin/$platform/dart')
; | |
256 | |
257 if (platform == 'windows') dartBin = '$dartBin.exe'; | |
258 | 261 |
259 // Find the main pub entrypoint. | 262 // Find the main pub entrypoint. |
260 var pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); | 263 var pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart'); |
261 | 264 |
262 var dartArgs = | 265 var dartArgs = |
263 ['--enable-type-checks', '--enable-asserts', pubPath, '--trace']; | 266 ['--enable-type-checks', '--enable-asserts', pubPath, '--trace']; |
264 dartArgs.addAll(args); | 267 dartArgs.addAll(args); |
265 | 268 |
266 var environment = new Map.from(Platform.environment); | 269 var environment = new Map.from(Platform.environment); |
267 environment['PUB_CACHE'] = pathInSandbox(cachePath); | 270 environment['PUB_CACHE'] = pathInSandbox(cachePath); |
268 environment['DART_SDK'] = pathInSandbox(sdkPath); | 271 environment['DART_SDK'] = pathInSandbox(sdkPath); |
269 | 272 |
270 return runProcess(dartBin, dartArgs, workingDir: pathInSandbox(appPath), | 273 return runProcess(dartBin, dartArgs, workingDir: pathInSandbox(appPath), |
271 environment: environment, pipeStdout: output == null, | 274 environment: environment, pipeStdout: output == null, |
272 pipeStderr: error == null); | 275 pipeStderr: error == null); |
273 }).transform((result) { | 276 }).transform((result) { |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 } | 811 } |
809 | 812 |
810 /** | 813 /** |
811 * 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 |
812 * fails. | 815 * fails. |
813 */ | 816 */ |
814 void _scheduleCleanup(_ScheduledEvent event) { | 817 void _scheduleCleanup(_ScheduledEvent event) { |
815 if (_scheduledCleanup == null) _scheduledCleanup = []; | 818 if (_scheduledCleanup == null) _scheduledCleanup = []; |
816 _scheduledCleanup.add(event); | 819 _scheduledCleanup.add(event); |
817 } | 820 } |
OLD | NEW |