Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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. | 5 /// Test infrastructure for testing pub. |
| 6 /// | 6 /// |
| 7 /// Unlike typical unit tests, most pub tests are integration tests that stage | 7 /// Unlike typical unit tests, most pub tests are integration tests that stage |
| 8 /// some stuff on the file system, run pub, and then validate the results. This | 8 /// some stuff on the file system, run pub, and then validate the results. This |
| 9 /// library provides an API to build tests like that. | 9 /// library provides an API to build tests like that. |
| 10 library test_pub; | 10 library test_pub; |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 pub.stdout.expect(emitsLines( | 599 pub.stdout.expect(emitsLines( |
| 600 "|-- LICENSE\n" | 600 "|-- LICENSE\n" |
| 601 "|-- lib\n" | 601 "|-- lib\n" |
| 602 "| '-- test_pkg.dart\n" | 602 "| '-- test_pkg.dart\n" |
| 603 "'-- pubspec.yaml\n" | 603 "'-- pubspec.yaml\n" |
| 604 "\n" | 604 "\n" |
| 605 "Looks great! Are you ready to upload your package (y/n)?")); | 605 "Looks great! Are you ready to upload your package (y/n)?")); |
| 606 pub.writeLine("y"); | 606 pub.writeLine("y"); |
| 607 } | 607 } |
| 608 | 608 |
| 609 /// Whether the async/await compiler has already been run. | |
| 610 /// | |
| 611 /// If a test suite runs pub more than once, we only need to run the compiler | |
| 612 /// the first time. | |
| 613 // TODO(rnystrom): Remove this when #104 is fixed. | |
| 614 bool _compiledAsync = false; | |
| 615 | |
| 616 /// Gets the path to the pub entrypoint Dart script to run. | |
| 617 // TODO(rnystrom): This exists to run the async/await compiler on pub and then | |
| 618 // get the path to the output of that. Once #104 is fixed, remove this. | |
| 619 String _getPubPath(String dartBin) { | |
| 620 var buildDir = path.join(path.dirname(dartBin), '../../'); | |
| 621 | |
| 622 // Run the async/await compiler if needed. | |
|
nweiz
2014/08/22 19:29:16
When I first read this, I was confused as to why e
Bob Nystrom
2014/08/25 17:40:00
Done.
| |
| 623 if (!_compiledAsync) { | |
| 624 var result = Process.runSync(dartBin, [ | |
| 625 '--package-root=$_packageRoot/', | |
| 626 path.join(testDirectory, '..', 'bin', 'async_compile.dart'), | |
| 627 buildDir, | |
| 628 '--silent' | |
| 629 ]); | |
| 630 stdout.write(result.stdout); | |
| 631 stderr.write(result.stderr); | |
| 632 if (result.exitCode != 0) fail("Async/await compiler failed."); | |
| 633 | |
| 634 _compiledAsync = true; | |
| 635 } | |
| 636 | |
| 637 return path.join(buildDir, 'pub_async/bin/pub.dart'); | |
| 638 } | |
| 639 | |
| 609 /// Starts a Pub process and returns a [ScheduledProcess] that supports | 640 /// Starts a Pub process and returns a [ScheduledProcess] that supports |
| 610 /// interaction with that process. | 641 /// interaction with that process. |
| 611 /// | 642 /// |
| 612 /// Any futures in [args] will be resolved before the process is started. | 643 /// Any futures in [args] will be resolved before the process is started. |
| 613 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { | 644 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { |
| 614 String pathInSandbox(String relPath) { | 645 String pathInSandbox(String relPath) { |
| 615 return path.join(path.absolute(sandboxDir), relPath); | 646 return path.join(path.absolute(sandboxDir), relPath); |
| 616 } | 647 } |
| 617 | 648 |
| 618 ensureDir(pathInSandbox(appPath)); | 649 ensureDir(pathInSandbox(appPath)); |
| 619 | 650 |
| 620 // Find a Dart executable we can use to spawn. Use the same one that was | 651 // Find a Dart executable we can use to spawn. Use the same one that was |
| 621 // used to run this script itself. | 652 // used to run this script itself. |
| 622 var dartBin = Platform.executable; | 653 var dartBin = Platform.executable; |
| 623 | 654 |
| 624 // If the executable looks like a path, get its full path. That way we | 655 // If the executable looks like a path, get its full path. That way we |
| 625 // can still find it when we spawn it with a different working directory. | 656 // can still find it when we spawn it with a different working directory. |
| 626 if (dartBin.contains(Platform.pathSeparator)) { | 657 if (dartBin.contains(Platform.pathSeparator)) { |
| 627 dartBin = path.absolute(dartBin); | 658 dartBin = path.absolute(dartBin); |
| 628 } | 659 } |
| 629 | 660 |
| 630 // Find the main pub entrypoint. | 661 // Find the main pub entrypoint. |
| 631 var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart'); | 662 var pubPath = _getPubPath(dartBin); |
| 663 // TODO(rnystrom): Replace the above line with the following when #104 is | |
| 664 // fixed. | |
| 665 //var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart'); | |
| 632 | 666 |
| 633 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, | 667 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, |
| 634 '--verbose']; | 668 '--verbose']; |
| 635 dartArgs.addAll(args); | 669 dartArgs.addAll(args); |
| 636 | 670 |
| 637 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); | 671 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); |
| 638 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { | 672 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { |
| 639 var environment = {}; | 673 var environment = {}; |
| 640 environment['_PUB_TESTING'] = 'true'; | 674 environment['_PUB_TESTING'] = 'true'; |
| 641 environment['PUB_CACHE'] = pathInSandbox(cachePath); | 675 environment['PUB_CACHE'] = pathInSandbox(cachePath); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 _lastMatcher.matches(item.last, matchState); | 1107 _lastMatcher.matches(item.last, matchState); |
| 1074 } | 1108 } |
| 1075 | 1109 |
| 1076 Description describe(Description description) { | 1110 Description describe(Description description) { |
| 1077 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1111 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 1078 } | 1112 } |
| 1079 } | 1113 } |
| 1080 | 1114 |
| 1081 /// A [StreamMatcher] that matches multiple lines of output. | 1115 /// A [StreamMatcher] that matches multiple lines of output. |
| 1082 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1116 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |