| 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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 /// A function that creates a [Validator] subclass. | 572 /// A function that creates a [Validator] subclass. |
| 573 typedef Validator ValidatorCreator(Entrypoint entrypoint); | 573 typedef Validator ValidatorCreator(Entrypoint entrypoint); |
| 574 | 574 |
| 575 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled | 575 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled |
| 576 /// Future that contains the errors and warnings produced by that validator. | 576 /// Future that contains the errors and warnings produced by that validator. |
| 577 Future<Pair<List<String>, List<String>>> schedulePackageValidation( | 577 Future<Pair<List<String>, List<String>>> schedulePackageValidation( |
| 578 ValidatorCreator fn) { | 578 ValidatorCreator fn) { |
| 579 return schedule(() { | 579 return schedule(() { |
| 580 var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath)); | 580 var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath)); |
| 581 | 581 |
| 582 return defer(() { | 582 return new Future.of(() { |
| 583 var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache)); | 583 var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache)); |
| 584 return validator.validate().then((_) { | 584 return validator.validate().then((_) { |
| 585 return new Pair(validator.errors, validator.warnings); | 585 return new Pair(validator.errors, validator.warnings); |
| 586 }); | 586 }); |
| 587 }); | 587 }); |
| 588 }, "validating package"); | 588 }, "validating package"); |
| 589 } | 589 } |
| 590 | 590 |
| 591 /// A matcher that matches a Pair. | 591 /// A matcher that matches a Pair. |
| 592 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) => | 592 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) => |
| 593 new _PairMatcher(firstMatcher, lastMatcher); | 593 new _PairMatcher(firstMatcher, lastMatcher); |
| 594 | 594 |
| 595 class _PairMatcher extends BaseMatcher { | 595 class _PairMatcher extends BaseMatcher { |
| 596 final Matcher _firstMatcher; | 596 final Matcher _firstMatcher; |
| 597 final Matcher _lastMatcher; | 597 final Matcher _lastMatcher; |
| 598 | 598 |
| 599 _PairMatcher(this._firstMatcher, this._lastMatcher); | 599 _PairMatcher(this._firstMatcher, this._lastMatcher); |
| 600 | 600 |
| 601 bool matches(item, MatchState matchState) { | 601 bool matches(item, MatchState matchState) { |
| 602 if (item is! Pair) return false; | 602 if (item is! Pair) return false; |
| 603 return _firstMatcher.matches(item.first, matchState) && | 603 return _firstMatcher.matches(item.first, matchState) && |
| 604 _lastMatcher.matches(item.last, matchState); | 604 _lastMatcher.matches(item.last, matchState); |
| 605 } | 605 } |
| 606 | 606 |
| 607 Description describe(Description description) { | 607 Description describe(Description description) { |
| 608 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 608 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
| 609 } | 609 } |
| 610 } | 610 } |
| OLD | NEW |