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

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

Issue 11475046: Add Bob's path library to pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years 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/path/path_windows_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 */
11 library test_pub; 11 library test_pub;
12 12
13 import 'dart:io'; 13 import 'dart:io';
14 import 'dart:isolate'; 14 import 'dart:isolate';
15 import 'dart:json'; 15 import 'dart:json';
16 import 'dart:math'; 16 import 'dart:math';
17 import 'dart:uri'; 17 import 'dart:uri';
18 18
19 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2; 19 import '../../../pkg/oauth2/lib/oauth2.dart' as oauth2;
20 import '../../../pkg/unittest/lib/unittest.dart'; 20 import '../../../pkg/unittest/lib/unittest.dart';
21 import '../../lib/file_system.dart' as fs; 21 import '../../lib/file_system.dart' as fs;
22 import '../../pub/entrypoint.dart'; 22 import '../../pub/entrypoint.dart';
23 import '../../pub/git_source.dart'; 23 import '../../pub/git_source.dart';
24 import '../../pub/hosted_source.dart'; 24 import '../../pub/hosted_source.dart';
25 import '../../pub/io.dart'; 25 import '../../pub/io.dart';
26 import '../../pub/path.dart' as path;
26 import '../../pub/sdk_source.dart'; 27 import '../../pub/sdk_source.dart';
27 import '../../pub/system_cache.dart'; 28 import '../../pub/system_cache.dart';
28 import '../../pub/utils.dart'; 29 import '../../pub/utils.dart';
29 import '../../pub/validator.dart'; 30 import '../../pub/validator.dart';
30 import '../../pub/yaml/yaml.dart'; 31 import '../../pub/yaml/yaml.dart';
31 32
32 /** 33 /**
33 * Creates a new [FileDescriptor] with [name] and [contents]. 34 * Creates a new [FileDescriptor] with [name] and [contents].
34 */ 35 */
35 FileDescriptor file(Pattern name, String contents) => 36 FileDescriptor file(Pattern name, String contents) =>
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 521
521 final future = _setUpSandbox().chain((sandboxDir) { 522 final future = _setUpSandbox().chain((sandboxDir) {
522 createdSandboxDir = sandboxDir; 523 createdSandboxDir = sandboxDir;
523 return _runScheduled(sandboxDir, _scheduled); 524 return _runScheduled(sandboxDir, _scheduled);
524 }); 525 });
525 526
526 future.handleException((error) { 527 future.handleException((error) {
527 // If an error occurs during testing, delete the sandbox, throw the error so 528 // If an error occurs during testing, delete the sandbox, throw the error so
528 // that the test framework sees it, then finally call asyncDone so that the 529 // that the test framework sees it, then finally call asyncDone so that the
529 // test framework knows we're done doing asynchronous stuff. 530 // test framework knows we're done doing asynchronous stuff.
530 var future = _runScheduled(createdSandboxDir, _scheduledOnException) 531 var subFuture = _runScheduled(createdSandboxDir, _scheduledOnException)
531 .chain((_) => cleanup()); 532 .chain((_) => cleanup());
532 future.handleException((e) { 533 subFuture.handleException((e) {
533 print("Exception while cleaning up: $e"); 534 print("Exception while cleaning up: $e");
534 print(future.stackTrace); 535 print(subFuture.stackTrace);
535 registerException(error, future.stackTrace); 536 registerException(error, subFuture.stackTrace);
536 return true; 537 return true;
537 }); 538 });
538 future.then((_) => registerException(error, future.stackTrace)); 539 subFuture.then((_) => registerException(error, future.stackTrace));
539 return true; 540 return true;
540 }); 541 });
541 542
542 future.chain((_) => cleanup()).then((_) { 543 future.chain((_) => cleanup()).then((_) {
543 asyncDone(); 544 asyncDone();
544 }); 545 });
545 } 546 }
546 547
547 /// Get the path to the root "util/test/pub" directory containing the pub tests. 548 /// Get the path to the root "util/test/pub" directory containing the pub tests.
548 String get testDirectory { 549 String get testDirectory {
549 var dir = new Path.fromNative(new Options().script); 550 var dir = new Options().script;
550 while (dir.filename != 'pub') dir = dir.directoryPath; 551 while (basename(dir) != 'pub') dir = dirname(dir);
551 552
552 return new File(dir.toNativePath()).fullPathSync(); 553 return getFullPath(dir);
553 } 554 }
554 555
555 /** 556 /**
556 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and 557 * Schedules a call to the Pub command-line utility. Runs Pub with [args] and
557 * validates that its results match [output], [error], and [exitCode]. 558 * validates that its results match [output], [error], and [exitCode].
558 */ 559 */
559 void schedulePub({List<String> args, Pattern output, Pattern error, 560 void schedulePub({List<String> args, Pattern output, Pattern error,
560 Future<Uri> tokenEndpoint, int exitCode: 0}) { 561 Future<Uri> tokenEndpoint, int exitCode: 0}) {
561 _schedule((sandboxDir) { 562 _schedule((sandboxDir) {
562 return _doPub(runProcess, sandboxDir, args, tokenEndpoint) 563 return _doPub(runProcess, sandboxDir, args, tokenEndpoint)
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 /// calling [completion] is unnecessary. 1632 /// calling [completion] is unnecessary.
1632 void expectLater(Future actual, matcher, {String reason, 1633 void expectLater(Future actual, matcher, {String reason,
1633 FailureHandler failureHandler, bool verbose: false}) { 1634 FailureHandler failureHandler, bool verbose: false}) {
1634 _schedule((_) { 1635 _schedule((_) {
1635 return actual.transform((value) { 1636 return actual.transform((value) {
1636 expect(value, matcher, reason: reason, failureHandler: failureHandler, 1637 expect(value, matcher, reason: reason, failureHandler: failureHandler,
1637 verbose: false); 1638 verbose: false);
1638 }); 1639 });
1639 }); 1640 });
1640 } 1641 }
OLDNEW
« no previous file with comments | « utils/tests/pub/path/path_windows_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698