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

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

Issue 12255016: Get rid of old redundant methods in io.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise and update to latest. Created 7 years, 10 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/pub/validator/name.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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub
6 /// tests are integration tests that stage some stuff on the file system, run 6 /// tests are integration tests that stage some stuff on the file system, run
7 /// pub, and then validate the results. This library provides an API to build 7 /// pub, and then validate the results. This library provides an API to build
8 /// tests like that. 8 /// tests like that.
9 library test_pub; 9 library test_pub;
10 10
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return result; 420 return result;
421 }); 421 });
422 } 422 }
423 423
424 /// Return the name for the package described by [description] and from 424 /// Return the name for the package described by [description] and from
425 /// [sourceName]. 425 /// [sourceName].
426 String _packageName(String sourceName, description) { 426 String _packageName(String sourceName, description) {
427 switch (sourceName) { 427 switch (sourceName) {
428 case "git": 428 case "git":
429 var url = description is String ? description : description['url']; 429 var url = description is String ? description : description['url'];
430 return basename(url.replaceFirst(new RegExp(r"(\.git)?/?$"), "")); 430 // TODO(rnystrom): Using path.basename on a URL is hacky. If we add URL
431 // support to pkg/path, should use an explicit builder for that.
432 return path.basename(url.replaceFirst(new RegExp(r"(\.git)?/?$"), ""));
431 case "hosted": 433 case "hosted":
432 if (description is String) return description; 434 if (description is String) return description;
433 return description['name']; 435 return description['name'];
434 case "path": 436 case "path":
435 return basename(description); 437 return path.basename(description);
436 case "sdk": 438 case "sdk":
437 return description; 439 return description;
438 default: 440 default:
439 return description; 441 return description;
440 } 442 }
441 } 443 }
442 444
443 /// The full path to the created sandbox directory for an integration test. 445 /// The full path to the created sandbox directory for an integration test.
444 String get sandboxDir => _sandboxDir.path; 446 String get sandboxDir => _sandboxDir;
445 Directory _sandboxDir; 447 String _sandboxDir;
446 448
447 /// The path of the package cache directory used for tests. Relative to the 449 /// The path of the package cache directory used for tests. Relative to the
448 /// sandbox directory. 450 /// sandbox directory.
449 final String cachePath = "cache"; 451 final String cachePath = "cache";
450 452
451 /// The path of the mock SDK directory used for tests. Relative to the sandbox 453 /// The path of the mock SDK directory used for tests. Relative to the sandbox
452 /// directory. 454 /// directory.
453 final String sdkPath = "sdk"; 455 final String sdkPath = "sdk";
454 456
455 /// The path of the mock app directory used for tests. Relative to the sandbox 457 /// The path of the mock app directory used for tests. Relative to the sandbox
456 /// directory. 458 /// directory.
457 final String appPath = "myapp"; 459 final String appPath = "myapp";
458 460
459 /// The path of the packages directory in the mock app used for tests. Relative 461 /// The path of the packages directory in the mock app used for tests. Relative
460 /// to the sandbox directory. 462 /// to the sandbox directory.
461 final String packagesPath = "$appPath/packages"; 463 final String packagesPath = "$appPath/packages";
462 464
463 /// The type for callbacks that will be fired during [schedulePub]. Takes the 465 /// The type for callbacks that will be fired during [schedulePub]. Takes the
464 /// sandbox directory as a parameter. 466 /// sandbox directory as a parameter.
465 typedef Future _ScheduledEvent(Directory parentDir); 467 typedef Future _ScheduledEvent(String parentDir);
466 468
467 /// The list of events that are scheduled to run as part of the test case. 469 /// The list of events that are scheduled to run as part of the test case.
468 List<_ScheduledEvent> _scheduled; 470 List<_ScheduledEvent> _scheduled;
469 471
470 /// The list of events that are scheduled to run after the test case, even if 472 /// The list of events that are scheduled to run after the test case, even if
471 /// it failed. 473 /// it failed.
472 List<_ScheduledEvent> _scheduledCleanup; 474 List<_ScheduledEvent> _scheduledCleanup;
473 475
474 /// The list of events that are scheduled to run after the test case only if it 476 /// The list of events that are scheduled to run after the test case only if it
475 /// failed. 477 /// failed.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // advance to the next test and run it. 537 // advance to the next test and run it.
536 registerException(e.error, e.stackTrace); 538 registerException(e.error, e.stackTrace);
537 }); 539 });
538 }); 540 });
539 } 541 }
540 542
541 /// Get the path to the root "util/test/pub" directory containing the pub 543 /// Get the path to the root "util/test/pub" directory containing the pub
542 /// tests. 544 /// tests.
543 String get testDirectory { 545 String get testDirectory {
544 var dir = new Options().script; 546 var dir = new Options().script;
545 while (basename(dir) != 'pub') dir = dirname(dir); 547 while (path.basename(dir) != 'pub') dir = path.dirname(dir);
546 548
547 return getFullPath(dir); 549 return path.absolute(dir);
548 } 550 }
549 551
550 /// Schedules renaming (moving) the directory at [from] to [to], both of which 552 /// Schedules renaming (moving) the directory at [from] to [to], both of which
551 /// are assumed to be relative to [sandboxDir]. 553 /// are assumed to be relative to [sandboxDir].
552 void scheduleRename(String from, String to) { 554 void scheduleRename(String from, String to) {
553 _schedule((sandboxDir) { 555 _schedule((sandboxDir) {
554 return renameDir(join(sandboxDir, from), join(sandboxDir, to)); 556 return renameDir(join(sandboxDir, from), join(sandboxDir, to));
555 }); 557 });
556 } 558 }
557 559
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 expectLater(pub.nextLine(), equals("'-- pubspec.yaml")); 624 expectLater(pub.nextLine(), equals("'-- pubspec.yaml"));
623 expectLater(pub.nextLine(), equals("")); 625 expectLater(pub.nextLine(), equals(""));
624 626
625 pub.writeLine("y"); 627 pub.writeLine("y");
626 } 628 }
627 629
628 /// Calls [fn] with appropriately modified arguments to run a pub process. [fn] 630 /// Calls [fn] with appropriately modified arguments to run a pub process. [fn]
629 /// should have the same signature as [startProcess], except that the returned 631 /// should have the same signature as [startProcess], except that the returned
630 /// [Future] may have a type other than [Process]. 632 /// [Future] may have a type other than [Process].
631 Future _doPub(Function fn, sandboxDir, List args, Future<Uri> tokenEndpoint) { 633 Future _doPub(Function fn, sandboxDir, List args, Future<Uri> tokenEndpoint) {
632 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); 634 String pathInSandbox(String relPath) {
635 return join(path.absolute(sandboxDir), relPath);
636 }
637
633 return defer(() { 638 return defer(() {
634 ensureDir(pathInSandbox(appPath)); 639 ensureDir(pathInSandbox(appPath));
635 return Future.wait([ 640 return Future.wait([
636 _awaitObject(args), 641 _awaitObject(args),
637 tokenEndpoint == null ? new Future.immediate(null) : tokenEndpoint 642 tokenEndpoint == null ? new Future.immediate(null) : tokenEndpoint
638 ]); 643 ]);
639 }).then((results) { 644 }).then((results) {
640 var args = results[0]; 645 var args = results[0];
641 var tokenEndpoint = results[1]; 646 var tokenEndpoint = results[1];
642 // Find a Dart executable we can use to spawn. Use the same one that was 647 // Find a Dart executable we can use to spawn. Use the same one that was
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 /// directory. 835 /// directory.
831 // TODO(nweiz): Use implicit closurization once issue 2984 is fixed. 836 // TODO(nweiz): Use implicit closurization once issue 2984 is fixed.
832 void scheduleCreate() => _schedule((dir) => this.create(dir)); 837 void scheduleCreate() => _schedule((dir) => this.create(dir));
833 838
834 /// Schedules the file or directory to be deleted recursively. 839 /// Schedules the file or directory to be deleted recursively.
835 void scheduleDelete() => _schedule((dir) => this.delete(dir)); 840 void scheduleDelete() => _schedule((dir) => this.delete(dir));
836 841
837 /// Schedules the directory to be validated after Pub is run with 842 /// Schedules the directory to be validated after Pub is run with
838 /// [schedulePub]. The directory will be validated relative to the sandbox 843 /// [schedulePub]. The directory will be validated relative to the sandbox
839 /// directory. 844 /// directory.
840 void scheduleValidate() => _schedule((parentDir) => validate(parentDir.path)); 845 void scheduleValidate() => _schedule((parentDir) => validate(parentDir));
841 846
842 /// Asserts that the name of the descriptor is a [String] and returns it. 847 /// Asserts that the name of the descriptor is a [String] and returns it.
843 String get _stringName { 848 String get _stringName {
844 if (name is String) return name; 849 if (name is String) return name;
845 throw 'Pattern $name must be a string.'; 850 throw 'Pattern $name must be a string.';
846 } 851 }
847 852
848 /// Validates that at least one file in [dir] matching [name] is valid 853 /// Validates that at least one file in [dir] matching [name] is valid
849 /// according to [validate]. [validate] should throw or complete to an 854 /// according to [validate]. [validate] should throw or complete to an
850 /// exception if the input path is invalid. 855 /// exception if the input path is invalid.
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 /// calling [completion] is unnecessary. 1628 /// calling [completion] is unnecessary.
1624 void expectLater(Future actual, matcher, {String reason, 1629 void expectLater(Future actual, matcher, {String reason,
1625 FailureHandler failureHandler, bool verbose: false}) { 1630 FailureHandler failureHandler, bool verbose: false}) {
1626 _schedule((_) { 1631 _schedule((_) {
1627 return actual.then((value) { 1632 return actual.then((value) {
1628 expect(value, matcher, reason: reason, failureHandler: failureHandler, 1633 expect(value, matcher, reason: reason, failureHandler: failureHandler,
1629 verbose: false); 1634 verbose: false);
1630 }); 1635 });
1631 }); 1636 });
1632 } 1637 }
OLDNEW
« no previous file with comments | « utils/pub/validator/name.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698