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

Side by Side Diff: sdk/lib/_internal/pub/test/test_pub.dart

Issue 557563002: Store the async-await compiled pub code directly in the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
OLDNEW
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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 pub.stdout.expect(emitsLines( 469 pub.stdout.expect(emitsLines(
470 "|-- LICENSE\n" 470 "|-- LICENSE\n"
471 "|-- lib\n" 471 "|-- lib\n"
472 "| '-- test_pkg.dart\n" 472 "| '-- test_pkg.dart\n"
473 "'-- pubspec.yaml\n" 473 "'-- pubspec.yaml\n"
474 "\n" 474 "\n"
475 "Looks great! Are you ready to upload your package (y/n)?")); 475 "Looks great! Are you ready to upload your package (y/n)?"));
476 pub.writeLine("y"); 476 pub.writeLine("y");
477 } 477 }
478 478
479 /// Whether the async/await compiler has already been run.
480 ///
481 /// If a test suite runs pub more than once, we only need to run the compiler
482 /// the first time.
483 // TODO(rnystrom): Remove this when #104 is fixed.
484 bool _compiledAsync = false;
485
486 /// Gets the path to the pub entrypoint Dart script to run.
487 // TODO(rnystrom): This exists to run the async/await compiler on pub and then
488 // get the path to the output of that. Once #104 is fixed, remove this.
489 String _getPubPath(String dartBin) {
490 var buildDir = p.join(p.dirname(dartBin), '../../');
491
492 // Ensure the async/await compiler has been run once for this test suite. The
493 // compiler itself will only re-compile source files that have actually
494 // changed, so this is a no-op if everything is already compiled.
495 if (!_compiledAsync) {
496 var result = Process.runSync(dartBin, [
497 '--package-root=$_packageRoot/',
498 p.join(testDirectory, '..', 'bin', 'async_compile.dart'),
499 buildDir,
500 '--silent'
501 ]);
502 stdout.write(result.stdout);
503 stderr.write(result.stderr);
504 if (result.exitCode != 0) fail("Async/await compiler failed.");
505
506 _compiledAsync = true;
507 }
508
509 return p.join(buildDir, 'pub_async/bin/pub.dart');
510 }
511
512 /// Starts a Pub process and returns a [ScheduledProcess] that supports 479 /// Starts a Pub process and returns a [ScheduledProcess] that supports
513 /// interaction with that process. 480 /// interaction with that process.
514 /// 481 ///
515 /// Any futures in [args] will be resolved before the process is started. 482 /// Any futures in [args] will be resolved before the process is started.
516 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { 483 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) {
517 String pathInSandbox(String relPath) { 484 String pathInSandbox(String relPath) {
518 return p.join(p.absolute(sandboxDir), relPath); 485 return p.join(p.absolute(sandboxDir), relPath);
519 } 486 }
520 487
521 ensureDir(pathInSandbox(appPath)); 488 ensureDir(pathInSandbox(appPath));
522 489
523 // Find a Dart executable we can use to spawn. Use the same one that was 490 // Find a Dart executable we can use to spawn. Use the same one that was
524 // used to run this script itself. 491 // used to run this script itself.
525 var dartBin = Platform.executable; 492 var dartBin = Platform.executable;
526 493
527 // If the executable looks like a path, get its full path. That way we 494 // If the executable looks like a path, get its full path. That way we
528 // can still find it when we spawn it with a different working directory. 495 // can still find it when we spawn it with a different working directory.
529 if (dartBin.contains(Platform.pathSeparator)) { 496 if (dartBin.contains(Platform.pathSeparator)) {
530 dartBin = p.absolute(dartBin); 497 dartBin = p.absolute(dartBin);
531 } 498 }
532 499
533 // Find the main pub entrypoint. 500 // Always run pub from a snapshot. Since we require the SDK to be built, the
534 var pubPath = _getPubPath(dartBin); 501 // snapshot should be there. Note that this *does* mean that the snapshot has
535 // TODO(rnystrom): Replace the above line with the following when #104 is 502 // to be manually updated when changing code before running the tests.
536 // fixed. 503 // Otherwise, you will test against stale data.
537 //var pubPath = p.join(testDirectory, '..', 'bin', 'pub.dart'); 504 //
538 505 // Using the snapshot makes running the tests much faster, which is why we
539 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, 506 // make this trade-off.
540 '--verbose']; 507 var pubPath = p.join(p.dirname(dartBin), 'snapshots/pub.dart.snapshot');
508 var dartArgs = [pubPath, '--verbose'];
541 dartArgs.addAll(args); 509 dartArgs.addAll(args);
542 510
543 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); 511 if (tokenEndpoint == null) tokenEndpoint = new Future.value();
544 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { 512 var environmentFuture = tokenEndpoint.then((tokenEndpoint) {
545 var environment = {}; 513 var environment = {};
546 environment['_PUB_TESTING'] = 'true'; 514 environment['_PUB_TESTING'] = 'true';
547 environment['PUB_CACHE'] = pathInSandbox(cachePath); 515 environment['PUB_CACHE'] = pathInSandbox(cachePath);
548 516
549 // Ensure a known SDK version is set for the tests that rely on that. 517 // Ensure a known SDK version is set for the tests that rely on that.
550 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; 518 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3";
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 "homepage": "http://pub.dartlang.org", 787 "homepage": "http://pub.dartlang.org",
820 "description": "A package, I guess." 788 "description": "A package, I guess."
821 }; 789 };
822 790
823 if (dependencies != null) package["dependencies"] = dependencies; 791 if (dependencies != null) package["dependencies"] = dependencies;
824 792
825 return package; 793 return package;
826 } 794 }
827 795
828 /// Resolves [target] relative to the path to pub's `test/asset` directory. 796 /// Resolves [target] relative to the path to pub's `test/asset` directory.
829 String testAssetPath(String target) => 797 String testAssetPath(String target) {
830 p.join(p.dirname(libraryPath('test_pub')), 'asset', target); 798 var libPath = libraryPath('test_pub');
799
800 // We are running from the generated directory, but non-dart assets are only
801 // in the canonical directory.
802 // TODO(rnystrom): Remove this when #104 is fixed.
803 libPath = libPath.replaceAll('pub_generated', 'pub');
804
805 return p.join(p.dirname(libPath), 'asset', target);
806 }
831 807
832 /// Returns a Map in the format used by the pub.dartlang.org API to represent a 808 /// Returns a Map in the format used by the pub.dartlang.org API to represent a
833 /// package version. 809 /// package version.
834 /// 810 ///
835 /// [pubspec] is the parsed pubspec of the package version. If [full] is true, 811 /// [pubspec] is the parsed pubspec of the package version. If [full] is true,
836 /// this returns the complete map, including metadata that's only included when 812 /// this returns the complete map, including metadata that's only included when
837 /// requesting the package version directly. 813 /// requesting the package version directly.
838 Map packageVersionApiMap(Map pubspec, {bool full: false}) { 814 Map packageVersionApiMap(Map pubspec, {bool full: false}) {
839 var name = pubspec['name']; 815 var name = pubspec['name'];
840 var version = pubspec['version']; 816 var version = pubspec['version'];
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 _lastMatcher.matches(item.last, matchState); 959 _lastMatcher.matches(item.last, matchState);
984 } 960 }
985 961
986 Description describe(Description description) { 962 Description describe(Description description) {
987 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 963 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
988 } 964 }
989 } 965 }
990 966
991 /// A [StreamMatcher] that matches multiple lines of output. 967 /// A [StreamMatcher] that matches multiple lines of output.
992 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); 968 StreamMatcher emitsLines(String output) => inOrder(output.split("\n"));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698