| 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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 workingDirectory: _pathInSandbox(appPath), | 552 workingDirectory: _pathInSandbox(appPath), |
| 553 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 553 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
| 554 } | 554 } |
| 555 | 555 |
| 556 /// Ensure that a snapshot of the current pub source exists at | 556 /// Ensure that a snapshot of the current pub source exists at |
| 557 /// ".pub/pub.snapshot". | 557 /// ".pub/pub.snapshot". |
| 558 void _ensureSnapshot() { | 558 void _ensureSnapshot() { |
| 559 ensureDir(p.join(pubRoot, '.pub')); | 559 ensureDir(p.join(pubRoot, '.pub')); |
| 560 | 560 |
| 561 var version = sdk.version.toString(); | 561 var version = sdk.version.toString(); |
| 562 var hash = _hashChanges(); | 562 var pubHash = _hashChanges(); |
| 563 var dartHash = runningFromDartRepo ? _hashExecutable() : null; |
| 563 | 564 |
| 564 var snapshotPath = p.join(pubRoot, '.pub', 'pub.test.snapshot'); | 565 var snapshotPath = p.join(pubRoot, '.pub', 'pub.test.snapshot'); |
| 565 var hashPath = p.join(pubRoot, '.pub', 'pub.hash'); | 566 var pubHashPath = p.join(pubRoot, '.pub', 'pub.hash'); |
| 567 var dartHashPath = p.join(pubRoot, '.pub', 'dart.hash'); |
| 566 var versionPath = p.join(pubRoot, '.pub', 'pub.version'); | 568 var versionPath = p.join(pubRoot, '.pub', 'pub.version'); |
| 567 if (fileExists(hashPath) && fileExists(versionPath)) { | 569 if (fileExists(pubHashPath) && fileExists(versionPath) && |
| 568 var oldHash = readTextFile(hashPath); | 570 (!runningFromDartRepo || fileExists(dartHashPath))) { |
| 571 var oldPubHash = readTextFile(pubHashPath); |
| 572 var oldDartHash = runningFromDartRepo ? readTextFile(dartHashPath) : null; |
| 569 var oldVersion = readTextFile(versionPath); | 573 var oldVersion = readTextFile(versionPath); |
| 570 | 574 |
| 571 if (oldHash == hash && oldVersion == version && fileExists(snapshotPath)) { | 575 if (oldPubHash == pubHash && oldDartHash == dartHash && |
| 576 oldVersion == version && fileExists(snapshotPath)) { |
| 572 return; | 577 return; |
| 573 } | 578 } |
| 574 } | 579 } |
| 575 | 580 |
| 576 var args = ['--snapshot=$snapshotPath']; | 581 var args = ['--snapshot=$snapshotPath']; |
| 577 if (Platform.packageRoot.isNotEmpty) { | 582 if (Platform.packageRoot.isNotEmpty) { |
| 578 args.add('--package-root=${Platform.packageRoot}'); | 583 args.add('--package-root=${Platform.packageRoot}'); |
| 579 } | 584 } |
| 580 args.add(p.join(pubRoot, 'bin', 'pub.dart')); | 585 args.add(p.join(pubRoot, 'bin', 'pub.dart')); |
| 581 | 586 |
| 582 var dartSnapshot = runProcessSync(Platform.executable, args); | 587 var dartSnapshot = runProcessSync(Platform.executable, args); |
| 583 if (dartSnapshot.exitCode != 0) throw "Failed to run dart --snapshot."; | 588 if (dartSnapshot.exitCode != 0) throw "Failed to run dart --snapshot."; |
| 584 | 589 |
| 585 writeTextFile(hashPath, hash); | 590 writeTextFile(pubHashPath, pubHash); |
| 591 if (runningFromDartRepo) writeTextFile(dartHashPath, dartHash); |
| 586 writeTextFile(versionPath, version); | 592 writeTextFile(versionPath, version); |
| 587 } | 593 } |
| 588 | 594 |
| 589 /// Returns a hash that encapsulates the current state of the repo. | 595 /// Returns a hash that encapsulates the current state of the repo. |
| 590 String _hashChanges() { | 596 String _hashChanges() { |
| 591 var hash = new SHA1(); | 597 var hash = new SHA1(); |
| 592 | 598 |
| 593 // Include the current Git commit. | 599 // Include the current Git commit. |
| 594 hash.add(UTF8.encode( | 600 hash.add(UTF8.encode( |
| 595 gitlib.runSync(['rev-parse', 'HEAD'], workingDir: pubRoot).first)); | 601 gitlib.runSync(['rev-parse', 'HEAD'], workingDir: pubRoot).first)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 606 var untracked = gitlib.runSync( | 612 var untracked = gitlib.runSync( |
| 607 ['ls-files', '--others', '--exclude-standard', 'lib', 'bin'], | 613 ['ls-files', '--others', '--exclude-standard', 'lib', 'bin'], |
| 608 workingDir: pubRoot); | 614 workingDir: pubRoot); |
| 609 for (var path in untracked) { | 615 for (var path in untracked) { |
| 610 hash.add(readBinaryFile(path)); | 616 hash.add(readBinaryFile(path)); |
| 611 } | 617 } |
| 612 | 618 |
| 613 return CryptoUtils.bytesToHex(hash.close()); | 619 return CryptoUtils.bytesToHex(hash.close()); |
| 614 } | 620 } |
| 615 | 621 |
| 622 /// Return a SHA1 hash of the Dart executable used to run this script. |
| 623 /// |
| 624 /// This is used when running within the Dart repo to ensure that the snapshot |
| 625 /// is invalidated when the executable changes. |
| 626 String _hashExecutable() { |
| 627 var hash = new SHA1(); |
| 628 hash.add(new File(Platform.executable).readAsBytesSync()); |
| 629 return CryptoUtils.bytesToHex(hash.close()); |
| 630 } |
| 631 |
| 616 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output | 632 /// A subclass of [ScheduledProcess] that parses pub's verbose logging output |
| 617 /// and makes [stdout] and [stderr] work as though pub weren't running in | 633 /// and makes [stdout] and [stderr] work as though pub weren't running in |
| 618 /// verbose mode. | 634 /// verbose mode. |
| 619 class PubProcess extends ScheduledProcess { | 635 class PubProcess extends ScheduledProcess { |
| 620 Stream<Pair<log.Level, String>> _log; | 636 Stream<Pair<log.Level, String>> _log; |
| 621 Stream<String> _stdout; | 637 Stream<String> _stdout; |
| 622 Stream<String> _stderr; | 638 Stream<String> _stderr; |
| 623 | 639 |
| 624 PubProcess.start(executable, arguments, | 640 PubProcess.start(executable, arguments, |
| 625 {workingDirectory, environment, String description, | 641 {workingDirectory, environment, String description, |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 _lastMatcher.matches(item.last, matchState); | 1065 _lastMatcher.matches(item.last, matchState); |
| 1050 } | 1066 } |
| 1051 | 1067 |
| 1052 Description describe(Description description) { | 1068 Description describe(Description description) { |
| 1053 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 1069 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 1054 } | 1070 } |
| 1055 } | 1071 } |
| 1056 | 1072 |
| 1057 /// A [StreamMatcher] that matches multiple lines of output. | 1073 /// A [StreamMatcher] that matches multiple lines of output. |
| 1058 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 1074 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
| OLD | NEW |