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

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

Issue 10689169: Use environment variables to find the Dart SDK and the Pub cache directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years, 5 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
« no previous file with comments | « utils/tests/pub/pub_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 /** 195 /**
196 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and 196 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and
197 * validates that its results match [output], [error], and [exitCode]. 197 * validates that its results match [output], [error], and [exitCode].
198 */ 198 */
199 void schedulePub([List<String> args, Pattern output, Pattern error, 199 void schedulePub([List<String> args, Pattern output, Pattern error,
200 int exitCode = 0]) { 200 int exitCode = 0]) {
201 _schedule((sandboxDir) { 201 _schedule((sandboxDir) {
202 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); 202 String pathInSandbox(path) => join(getFullPath(sandboxDir), path);
203 203
204 return ensureDir(pathInSandbox(appPath)).chain((_) { 204 return ensureDir(pathInSandbox(appPath)).chain((_) {
205 // TODO(rnystrom): Hack in the cache directory path. Should pass this in 205 // Find a dart executable we can use to run pub. Uses the one that the
206 // using environment var once #752 is done. 206 // test infrastructure uses. We are not using new Options.executable here
207 args.insertRange(0, 1, '--cachedir=${pathInSandbox(cachePath)}'); 207 // because that gets confused if you invoked Dart through a shell script.
208 var scriptDir = new File(new Options().script).directorySync().path;
209 var platform = Platform.operatingSystem;
210 var dartBin = join(scriptDir, '../../../tools/testing/bin/$platform/dart') ;
208 211
209 // TODO(rnystrom): Hack in the SDK path. Should pass this in using 212 // Find the main pub entrypoint.
210 // environment var once #752 is done. 213 var pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart');
211 args.insertRange(0, 1, '--sdkdir=${pathInSandbox(sdkPath)}');
212 214
213 // If an error occurs in pub during testing, we want it to print the stack 215 var dartArgs =
214 // trace so it can be debugged. 216 ['--enable-type-checks', '--enable-asserts', pubPath, '--trace'];
215 args.insertRange(0, 1, '--trace'); 217 dartArgs.addAll(args);
216 218
217 return _runPub(args, pathInSandbox(appPath), pipeStdout: output == null, 219 var environment = new Map.from(Platform.environment);
220 environment['PUB_CACHE'] = pathInSandbox(cachePath);
221 environment['DART_SDK'] = pathInSandbox(sdkPath);
222
223 return runProcess(dartBin, dartArgs, workingDir: pathInSandbox(appPath),
224 environment: environment, pipeStdout: output == null,
218 pipeStderr: error == null); 225 pipeStderr: error == null);
219 }).transform((result) { 226 }).transform((result) {
220 _validateOutput(output, result.stdout); 227 _validateOutput(output, result.stdout);
221 _validateOutput(error, result.stderr); 228 _validateOutput(error, result.stderr);
222 229
223 Expect.equals(result.exitCode, exitCode, 230 Expect.equals(result.exitCode, exitCode,
224 'Pub returned exit code ${result.exitCode}, expected $exitCode.'); 231 'Pub returned exit code ${result.exitCode}, expected $exitCode.');
225 232
226 return null; 233 return null;
227 }); 234 });
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (future != null) { 278 if (future != null) {
272 return future.chain(runNextEvent); 279 return future.chain(runNextEvent);
273 } else { 280 } else {
274 return runNextEvent(); 281 return runNextEvent();
275 } 282 }
276 } 283 }
277 284
278 return runNextEvent(); 285 return runNextEvent();
279 } 286 }
280 287
281 Future<ProcessResult> _runPub(List<String> pubArgs, String workingDir,
282 [bool pipeStdout=false, bool pipeStderr=false]) {
283 // Find a dart executable we can use to run pub. Uses the one that the
284 // test infrastructure uses. We are not using new Options.executable here
285 // because that gets confused if you invoked Dart through a shell script.
286 final scriptDir = new File(new Options().script).directorySync().path;
287 final platform = Platform.operatingSystem;
288 final dartBin = join(scriptDir, '../../../tools/testing/bin/$platform/dart');
289
290 // Find the main pub entrypoint.
291 final pubPath = fs.joinPaths(scriptDir, '../../pub/pub.dart');
292
293 final args = ['--enable-type-checks', '--enable-asserts', pubPath];
294 args.addAll(pubArgs);
295
296 return runProcess(dartBin, args, workingDir, pipeStdout, pipeStderr);
297 }
298
299 /** 288 /**
300 * Compares the [actual] output from running pub with [expected]. For [String] 289 * Compares the [actual] output from running pub with [expected]. For [String]
301 * patterns, ignores leading and trailing whitespace differences and tries to 290 * patterns, ignores leading and trailing whitespace differences and tries to
302 * report the offending difference in a nice way. For other [Pattern]s, just 291 * report the offending difference in a nice way. For other [Pattern]s, just
303 * reports whether the output contained the pattern. 292 * reports whether the output contained the pattern.
304 */ 293 */
305 void _validateOutput(Pattern expected, List<String> actual) { 294 void _validateOutput(Pattern expected, List<String> actual) {
306 if (expected == null) return; 295 if (expected == null) return;
307 296
308 if (expected is String) return _validateOutputString(expected, actual); 297 if (expected is String) return _validateOutputString(expected, actual);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 711 }
723 712
724 /** 713 /**
725 * Schedules a callback to be called after Pub is run with [runPub], even if it 714 * Schedules a callback to be called after Pub is run with [runPub], even if it
726 * fails. 715 * fails.
727 */ 716 */
728 void _scheduleCleanup(_ScheduledEvent event) { 717 void _scheduleCleanup(_ScheduledEvent event) {
729 if (_scheduledCleanup == null) _scheduledCleanup = []; 718 if (_scheduledCleanup == null) _scheduledCleanup = [];
730 _scheduledCleanup.add(event); 719 _scheduledCleanup.add(event);
731 } 720 }
OLDNEW
« no previous file with comments | « utils/tests/pub/pub_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698