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

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

Issue 472173004: Skeleton code for running the forthcoming async/await compiler on pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 4 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 | « sdk/lib/_internal/pub/lib/src/io.dart ('k') | tools/create_pub_snapshot.py » ('j') | 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) 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 = path.join(path.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 path.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 path.join(buildDir, 'pub_async/bin/pub.dart');
510 }
511
479 /// Starts a Pub process and returns a [ScheduledProcess] that supports 512 /// Starts a Pub process and returns a [ScheduledProcess] that supports
480 /// interaction with that process. 513 /// interaction with that process.
481 /// 514 ///
482 /// Any futures in [args] will be resolved before the process is started. 515 /// Any futures in [args] will be resolved before the process is started.
483 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { 516 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) {
484 String pathInSandbox(String relPath) { 517 String pathInSandbox(String relPath) {
485 return path.join(path.absolute(sandboxDir), relPath); 518 return path.join(path.absolute(sandboxDir), relPath);
486 } 519 }
487 520
488 ensureDir(pathInSandbox(appPath)); 521 ensureDir(pathInSandbox(appPath));
489 522
490 // Find a Dart executable we can use to spawn. Use the same one that was 523 // Find a Dart executable we can use to spawn. Use the same one that was
491 // used to run this script itself. 524 // used to run this script itself.
492 var dartBin = Platform.executable; 525 var dartBin = Platform.executable;
493 526
494 // If the executable looks like a path, get its full path. That way we 527 // If the executable looks like a path, get its full path. That way we
495 // can still find it when we spawn it with a different working directory. 528 // can still find it when we spawn it with a different working directory.
496 if (dartBin.contains(Platform.pathSeparator)) { 529 if (dartBin.contains(Platform.pathSeparator)) {
497 dartBin = path.absolute(dartBin); 530 dartBin = path.absolute(dartBin);
498 } 531 }
499 532
500 // Find the main pub entrypoint. 533 // Find the main pub entrypoint.
501 var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart'); 534 var pubPath = _getPubPath(dartBin);
535 // TODO(rnystrom): Replace the above line with the following when #104 is
536 // fixed.
537 //var pubPath = path.join(testDirectory, '..', 'bin', 'pub.dart');
502 538
503 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath, 539 var dartArgs = ['--package-root=$_packageRoot/', '--checked', pubPath,
504 '--verbose']; 540 '--verbose'];
505 dartArgs.addAll(args); 541 dartArgs.addAll(args);
506 542
507 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); 543 if (tokenEndpoint == null) tokenEndpoint = new Future.value();
508 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { 544 var environmentFuture = tokenEndpoint.then((tokenEndpoint) {
509 var environment = {}; 545 var environment = {};
510 environment['_PUB_TESTING'] = 'true'; 546 environment['_PUB_TESTING'] = 'true';
511 environment['PUB_CACHE'] = pathInSandbox(cachePath); 547 environment['PUB_CACHE'] = pathInSandbox(cachePath);
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 _lastMatcher.matches(item.last, matchState); 979 _lastMatcher.matches(item.last, matchState);
944 } 980 }
945 981
946 Description describe(Description description) { 982 Description describe(Description description) {
947 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); 983 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
948 } 984 }
949 } 985 }
950 986
951 /// A [StreamMatcher] that matches multiple lines of output. 987 /// A [StreamMatcher] that matches multiple lines of output.
952 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); 988 StreamMatcher emitsLines(String output) => inOrder(output.split("\n"));
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/io.dart ('k') | tools/create_pub_snapshot.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698