| 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. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
| 6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
| 7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
| 8 /// tests like that. | 8 /// tests like that. |
| 9 library test_pub; | 9 library test_pub; |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 import 'descriptor.dart' as d; | 39 import 'descriptor.dart' as d; |
| 40 | 40 |
| 41 /// This should be called at the top of a test file to set up an appropriate | 41 /// This should be called at the top of a test file to set up an appropriate |
| 42 /// test configuration for the machine running the tests. | 42 /// test configuration for the machine running the tests. |
| 43 initConfig() { | 43 initConfig() { |
| 44 useCompactVMConfiguration(); | 44 useCompactVMConfiguration(); |
| 45 filterStacks = true; | 45 filterStacks = true; |
| 46 unittestConfiguration.timeout = null; | 46 unittestConfiguration.timeout = null; |
| 47 } | 47 } |
| 48 | 48 |
| 49 /// Returns whether we're running on a Dart build bot. | |
| 50 bool get runningOnBuildbot => | |
| 51 Platform.environment.containsKey('BUILDBOT_BUILDERNAME'); | |
| 52 | |
| 53 /// The current [HttpServer] created using [serve]. | 49 /// The current [HttpServer] created using [serve]. |
| 54 var _server; | 50 var _server; |
| 55 | 51 |
| 56 /// The list of paths that have been requested from the server since the last | 52 /// The list of paths that have been requested from the server since the last |
| 57 /// call to [getRequestedPaths]. | 53 /// call to [getRequestedPaths]. |
| 58 final _requestedPaths = <String>[]; | 54 final _requestedPaths = <String>[]; |
| 59 | 55 |
| 60 /// The cached value for [_portCompleter]. | 56 /// The cached value for [_portCompleter]. |
| 61 Completer<int> _portCompleterCache; | 57 Completer<int> _portCompleterCache; |
| 62 | 58 |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 571 |
| 576 var pair = tee(_stderr); | 572 var pair = tee(_stderr); |
| 577 _stderr = pair.first; | 573 _stderr = pair.first; |
| 578 return pair.last; | 574 return pair.last; |
| 579 } | 575 } |
| 580 } | 576 } |
| 581 | 577 |
| 582 /// The path to the `packages` directory from which pub loads its dependencies. | 578 /// The path to the `packages` directory from which pub loads its dependencies. |
| 583 String get _packageRoot => path.absolute(Platform.packageRoot); | 579 String get _packageRoot => path.absolute(Platform.packageRoot); |
| 584 | 580 |
| 585 /// Skips the current test if Git is not installed. This validates that the | 581 /// Fails the current test if Git is not installed. |
| 586 /// current test is running on a buildbot in which case we expect git to be | |
| 587 /// installed. If we are not running on the buildbot, we will instead see if | |
| 588 /// git is installed and skip the test if not. This way, users don't need to | |
| 589 /// have git installed to run the tests locally (unless they actually care | |
| 590 /// about the pub git tests). | |
| 591 /// | 582 /// |
| 592 /// This will also increase the [Schedule] timeout to 30 seconds on Windows, | 583 /// We require machines running these tests to have git installed. This |
| 584 /// validation gives an easier-to-understand error when that requirement isn't |
| 585 /// met than just failing in the middle of a test when pub invokes git. |
| 586 /// |
| 587 /// This also increases the [Schedule] timeout to 30 seconds on Windows, |
| 593 /// where Git runs really slowly. | 588 /// where Git runs really slowly. |
| 594 void ensureGit() { | 589 void ensureGit() { |
| 595 if (Platform.operatingSystem == "windows") { | 590 if (Platform.operatingSystem == "windows") { |
| 596 currentSchedule.timeout = new Duration(seconds: 30); | 591 currentSchedule.timeout = new Duration(seconds: 30); |
| 597 } | 592 } |
| 598 | 593 |
| 599 schedule(() { | 594 schedule(() { |
| 600 return gitlib.isInstalled.then((installed) { | 595 return gitlib.isInstalled.then((installed) { |
| 601 if (installed) return; | 596 if (!installed) { |
| 602 if (runningOnBuildbot) return; | 597 throw new Exception("Git must be installed to run this test."); |
| 603 currentSchedule.abort(); | 598 } |
| 604 }); | 599 }); |
| 605 }, 'ensuring that Git is installed'); | 600 }, 'ensuring that Git is installed'); |
| 606 } | 601 } |
| 607 | 602 |
| 608 /// Create a lock file for [package] without running `pub get`. | 603 /// Create a lock file for [package] without running `pub get`. |
| 609 /// | 604 /// |
| 610 /// This creates a lock file with only path dependencies. [sandbox] is a list of | 605 /// This creates a lock file with only path dependencies. [sandbox] is a list of |
| 611 /// dependencies to be found in the sandbox directory. [pkg] is a list of | 606 /// dependencies to be found in the sandbox directory. [pkg] is a list of |
| 612 /// packages in the Dart repo's "pkg" directory; each package listed here and | 607 /// packages in the Dart repo's "pkg" directory; each package listed here and |
| 613 /// all its dependencies will be linked to the version in the Dart repo. | 608 /// all its dependencies will be linked to the version in the Dart repo. |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 bool matches(item, Map matchState) { | 831 bool matches(item, Map matchState) { |
| 837 if (item is! Pair) return false; | 832 if (item is! Pair) return false; |
| 838 return _firstMatcher.matches(item.first, matchState) && | 833 return _firstMatcher.matches(item.first, matchState) && |
| 839 _lastMatcher.matches(item.last, matchState); | 834 _lastMatcher.matches(item.last, matchState); |
| 840 } | 835 } |
| 841 | 836 |
| 842 Description describe(Description description) { | 837 Description describe(Description description) { |
| 843 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 838 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 844 } | 839 } |
| 845 } | 840 } |
| OLD | NEW |