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 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 /// A function that creates a [Validator] subclass. | 830 /// A function that creates a [Validator] subclass. |
831 typedef Validator ValidatorCreator(Entrypoint entrypoint); | 831 typedef Validator ValidatorCreator(Entrypoint entrypoint); |
832 | 832 |
833 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled | 833 /// Schedules a single [Validator] to run on the [appPath]. Returns a scheduled |
834 /// Future that contains the errors and warnings produced by that validator. | 834 /// Future that contains the errors and warnings produced by that validator. |
835 Future<Pair<List<String>, List<String>>> schedulePackageValidation( | 835 Future<Pair<List<String>, List<String>>> schedulePackageValidation( |
836 ValidatorCreator fn) { | 836 ValidatorCreator fn) { |
837 return schedule(() { | 837 return schedule(() { |
838 var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath)); | 838 var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath)); |
839 | 839 |
840 return new Future.sync(() { | 840 return syncFuture(() { |
841 var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache)); | 841 var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache)); |
842 return validator.validate().then((_) { | 842 return validator.validate().then((_) { |
843 return new Pair(validator.errors, validator.warnings); | 843 return new Pair(validator.errors, validator.warnings); |
844 }); | 844 }); |
845 }); | 845 }); |
846 }, "validating package"); | 846 }, "validating package"); |
847 } | 847 } |
848 | 848 |
849 /// A matcher that matches a Pair. | 849 /// A matcher that matches a Pair. |
850 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) => | 850 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) => |
851 new _PairMatcher(firstMatcher, lastMatcher); | 851 new _PairMatcher(firstMatcher, lastMatcher); |
852 | 852 |
853 class _PairMatcher extends Matcher { | 853 class _PairMatcher extends Matcher { |
854 final Matcher _firstMatcher; | 854 final Matcher _firstMatcher; |
855 final Matcher _lastMatcher; | 855 final Matcher _lastMatcher; |
856 | 856 |
857 _PairMatcher(this._firstMatcher, this._lastMatcher); | 857 _PairMatcher(this._firstMatcher, this._lastMatcher); |
858 | 858 |
859 bool matches(item, Map matchState) { | 859 bool matches(item, Map matchState) { |
860 if (item is! Pair) return false; | 860 if (item is! Pair) return false; |
861 return _firstMatcher.matches(item.first, matchState) && | 861 return _firstMatcher.matches(item.first, matchState) && |
862 _lastMatcher.matches(item.last, matchState); | 862 _lastMatcher.matches(item.last, matchState); |
863 } | 863 } |
864 | 864 |
865 Description describe(Description description) { | 865 Description describe(Description description) { |
866 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 866 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
867 } | 867 } |
868 } | 868 } |
OLD | NEW |