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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 } | 589 } |
590 | 590 |
591 throw new ExpectException(Strings.join(failures, '\n')); | 591 throw new ExpectException(Strings.join(failures, '\n')); |
592 } | 592 } |
593 | 593 |
594 return null; | 594 return null; |
595 }); | 595 }); |
596 }); | 596 }); |
597 } | 597 } |
598 | 598 |
599 /** | 599 /// A shorthand for [schedulePub] and [run] when no validation needs to be done |
600 * A shorthand for [schedulePub] and [run] when no validation needs to be done | 600 /// after Pub has been run. |
601 * after Pub has been run. | 601 /// |
602 */ | 602 /// Any futures in [args] will be resolved before the process is started. |
603 void runPub({List<String> args, Pattern output, Pattern error, | 603 void runPub({List<String> args, Pattern output, Pattern error, |
Bob Nystrom
2012/12/17 18:41:58
List<String> -> List, here and elsewhere.
if it c
nweiz
2012/12/17 21:18:48
Done.
| |
604 int exitCode: 0}) { | 604 int exitCode: 0}) { |
605 schedulePub(args: args, output: output, error: error, exitCode: exitCode); | 605 schedulePub(args: args, output: output, error: error, exitCode: exitCode); |
606 run(); | 606 run(); |
607 } | 607 } |
608 | 608 |
609 /// Starts a Pub process and returns a [ScheduledProcess] that supports | 609 /// Starts a Pub process and returns a [ScheduledProcess] that supports |
610 /// interaction with that process. | 610 /// interaction with that process. |
611 ScheduledProcess startPub({List<String> args}) { | 611 /// |
612 /// Any futures in [args] will be resolved before the process is started. | |
613 ScheduledProcess startPub({List<String> args, Future<Uri> tokenEndpoint}) { | |
612 var process = _scheduleValue((sandboxDir) => | 614 var process = _scheduleValue((sandboxDir) => |
613 _doPub(startProcess, sandboxDir, args)); | 615 _doPub(startProcess, sandboxDir, args, tokenEndpoint)); |
614 return new ScheduledProcess("pub", process); | 616 return new ScheduledProcess("pub", process); |
615 } | 617 } |
616 | 618 |
617 /// Like [startPub], but runs `pub lish` in particular with [server] used both | 619 /// Like [startPub], but runs `pub lish` in particular with [server] used both |
618 /// as the OAuth2 server (with "/token" as the token endpoint) and as the | 620 /// as the OAuth2 server (with "/token" as the token endpoint) and as the |
619 /// package server. | 621 /// package server. |
622 /// | |
623 /// Any futures in [args] will be resolved before the process is started. | |
620 ScheduledProcess startPubLish(ScheduledServer server, {List<String> args}) { | 624 ScheduledProcess startPubLish(ScheduledServer server, {List<String> args}) { |
621 var process = _scheduleValue((sandboxDir) { | 625 var tokenEndpoint = server.url.transform((url) => |
622 return server.url.chain((url) { | 626 url.resolve('/token').toString()); |
623 var tokenEndpoint = url.resolve('/token'); | 627 if (args == null) args = []; |
624 if (args == null) args = []; | 628 args = flatten(['lish', '--server', tokenEndpoint, args]); |
625 args = flatten(['lish', '--server', url.toString(), args]); | 629 return startPub(args: args, tokenEndpoint: tokenEndpoint); |
626 return _doPub(startProcess, sandboxDir, args, tokenEndpoint); | |
627 }); | |
628 }); | |
629 return new ScheduledProcess("pub lish", process); | |
630 } | 630 } |
631 | 631 |
632 /// Handles the beginning confirmation process for uploading a packages. | 632 /// Handles the beginning confirmation process for uploading a packages. |
633 /// Ensures that the right output is shown and then enters "y" to confirm the | 633 /// Ensures that the right output is shown and then enters "y" to confirm the |
634 /// upload. | 634 /// upload. |
635 void confirmPublish(ScheduledProcess pub) { | 635 void confirmPublish(ScheduledProcess pub) { |
636 // TODO(rnystrom): This is overly specific and inflexible regarding different | 636 // TODO(rnystrom): This is overly specific and inflexible regarding different |
637 // test packages. Should validate this a little more loosely. | 637 // test packages. Should validate this a little more loosely. |
638 expectLater(pub.nextLine(), equals('Publishing "test_pkg" 1.0.0:')); | 638 expectLater(pub.nextLine(), equals('Publishing "test_pkg" 1.0.0:')); |
639 expectLater(pub.nextLine(), equals("|-- LICENSE")); | 639 expectLater(pub.nextLine(), equals("|-- LICENSE")); |
640 expectLater(pub.nextLine(), equals("|-- lib")); | 640 expectLater(pub.nextLine(), equals("|-- lib")); |
641 expectLater(pub.nextLine(), equals("| '-- test_pkg.dart")); | 641 expectLater(pub.nextLine(), equals("| '-- test_pkg.dart")); |
642 expectLater(pub.nextLine(), equals("'-- pubspec.yaml")); | 642 expectLater(pub.nextLine(), equals("'-- pubspec.yaml")); |
643 expectLater(pub.nextLine(), equals("")); | 643 expectLater(pub.nextLine(), equals("")); |
644 | 644 |
645 pub.writeLine("y"); | 645 pub.writeLine("y"); |
646 } | 646 } |
647 | 647 |
648 | 648 |
649 /// Calls [fn] with appropriately modified arguments to run a pub process. [fn] | 649 /// Calls [fn] with appropriately modified arguments to run a pub process. [fn] |
650 /// should have the same signature as [startProcess], except that the returned | 650 /// should have the same signature as [startProcess], except that the returned |
651 /// [Future] may have a type other than [Process]. | 651 /// [Future] may have a type other than [Process]. |
652 Future _doPub(Function fn, sandboxDir, List<String> args, Uri tokenEndpoint) { | 652 Future _doPub(Function fn, sandboxDir, List<String> args, |
653 Future<Uri> tokenEndpoint) { | |
653 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); | 654 String pathInSandbox(path) => join(getFullPath(sandboxDir), path); |
654 | 655 |
655 return ensureDir(pathInSandbox(appPath)).chain((_) { | 656 return Futures.wait([ |
657 ensureDir(pathInSandbox(appPath)), | |
658 _awaitObject(args), | |
659 tokenEndpoint == null ? new Future.immediate(null) : tokenEndpoint | |
660 ]).chain((results) { | |
661 var args = results[1]; | |
662 var tokenEndpoint = results[2]; | |
656 // Find a Dart executable we can use to spawn. Use the same one that was | 663 // Find a Dart executable we can use to spawn. Use the same one that was |
657 // used to run this script itself. | 664 // used to run this script itself. |
658 var dartBin = new Options().executable; | 665 var dartBin = new Options().executable; |
659 | 666 |
660 // If the executable looks like a path, get its full path. That way we | 667 // If the executable looks like a path, get its full path. That way we |
661 // can still find it when we spawn it with a different working directory. | 668 // can still find it when we spawn it with a different working directory. |
662 if (dartBin.contains(Platform.pathSeparator)) { | 669 if (dartBin.contains(Platform.pathSeparator)) { |
663 dartBin = new File(dartBin).fullPathSync(); | 670 dartBin = new File(dartBin).fullPathSync(); |
664 } | 671 } |
665 | 672 |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1658 /// calling [completion] is unnecessary. | 1665 /// calling [completion] is unnecessary. |
1659 void expectLater(Future actual, matcher, {String reason, | 1666 void expectLater(Future actual, matcher, {String reason, |
1660 FailureHandler failureHandler, bool verbose: false}) { | 1667 FailureHandler failureHandler, bool verbose: false}) { |
1661 _schedule((_) { | 1668 _schedule((_) { |
1662 return actual.transform((value) { | 1669 return actual.transform((value) { |
1663 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1670 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
1664 verbose: false); | 1671 verbose: false); |
1665 }); | 1672 }); |
1666 }); | 1673 }); |
1667 } | 1674 } |
OLD | NEW |