| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library pub_update_test; | 5 library pub_update_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| 11 import '../lib/src/lock_file.dart'; | 11 import '../lib/src/lock_file.dart'; |
| 12 import '../lib/src/log.dart' as log; | 12 import '../lib/src/log.dart' as log; |
| 13 import '../lib/src/package.dart'; | 13 import '../lib/src/package.dart'; |
| 14 import '../lib/src/pubspec.dart'; | 14 import '../lib/src/pubspec.dart'; |
| 15 import '../lib/src/sdk.dart' as sdk; | 15 import '../lib/src/sdk.dart' as sdk; |
| 16 import '../lib/src/source.dart'; | 16 import '../lib/src/source.dart'; |
| 17 import '../lib/src/source_registry.dart'; | |
| 18 import '../lib/src/system_cache.dart'; | 17 import '../lib/src/system_cache.dart'; |
| 19 import '../lib/src/version.dart'; | 18 import '../lib/src/version.dart'; |
| 20 import '../lib/src/solver/version_solver.dart'; | 19 import '../lib/src/solver/version_solver.dart'; |
| 21 import 'test_pub.dart'; | 20 import 'test_pub.dart'; |
| 22 | 21 |
| 23 MockSource source1; | 22 MockSource source1; |
| 24 MockSource source2; | 23 MockSource source2; |
| 25 | 24 |
| 26 main() { | 25 main() { |
| 27 initConfig(); | 26 initConfig(); |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 951 |
| 953 Description describeMismatch(SolveResult result, | 952 Description describeMismatch(SolveResult result, |
| 954 Description description, | 953 Description description, |
| 955 Map state, bool verbose) { | 954 Map state, bool verbose) { |
| 956 if (!result.succeeded) { | 955 if (!result.succeeded) { |
| 957 description.add('Solver failed with:\n${result.error}'); | 956 description.add('Solver failed with:\n${result.error}'); |
| 958 return null; | 957 return null; |
| 959 } | 958 } |
| 960 | 959 |
| 961 description.add('Resolved:\n${_listPackages(result.packages)}\n'); | 960 description.add('Resolved:\n${_listPackages(result.packages)}\n'); |
| 962 description.add(state.state); | 961 description.add(state['failures']); |
| 963 return description; | 962 return description; |
| 964 } | 963 } |
| 965 | 964 |
| 966 bool matches(SolveResult result, Map state) { | 965 bool matches(SolveResult result, Map state) { |
| 967 if (!result.succeeded) return false; | 966 if (!result.succeeded) return false; |
| 968 | 967 |
| 969 var expected = new Map.from(_expected); | 968 var expected = new Map.from(_expected); |
| 970 var failures = new StringBuffer(); | 969 var failures = new StringBuffer(); |
| 971 | 970 |
| 972 for (var id in result.packages) { | 971 for (var id in result.packages) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 984 failures.writeln('Missing:\n${_listPackages(expected.values)}'); | 983 failures.writeln('Missing:\n${_listPackages(expected.values)}'); |
| 985 } | 984 } |
| 986 | 985 |
| 987 // Allow 1 here because the greedy solver will only make one attempt. | 986 // Allow 1 here because the greedy solver will only make one attempt. |
| 988 if (result.attemptedSolutions != 1 && | 987 if (result.attemptedSolutions != 1 && |
| 989 result.attemptedSolutions != _maxTries) { | 988 result.attemptedSolutions != _maxTries) { |
| 990 failures.writeln('Took ${result.attemptedSolutions} attempts'); | 989 failures.writeln('Took ${result.attemptedSolutions} attempts'); |
| 991 } | 990 } |
| 992 | 991 |
| 993 if (!failures.isEmpty) { | 992 if (!failures.isEmpty) { |
| 994 state.state = failures.toString(); | 993 state['failures'] = failures.toString(); |
| 995 return false; | 994 return false; |
| 996 } | 995 } |
| 997 | 996 |
| 998 return true; | 997 return true; |
| 999 } | 998 } |
| 1000 | 999 |
| 1001 String _listPackages(Iterable<PackageId> packages) { | 1000 String _listPackages(Iterable<PackageId> packages) { |
| 1002 return '- ${packages.join('\n- ')}'; | 1001 return '- ${packages.join('\n- ')}'; |
| 1003 } | 1002 } |
| 1004 } | 1003 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1022 if (!_expected.isEmpty) { | 1021 if (!_expected.isEmpty) { |
| 1023 var textList = _expected.map((s) => '"$s"').join(", "); | 1022 var textList = _expected.map((s) => '"$s"').join(", "); |
| 1024 description.add(' The error should contain $textList.'); | 1023 description.add(' The error should contain $textList.'); |
| 1025 } | 1024 } |
| 1026 return description; | 1025 return description; |
| 1027 } | 1026 } |
| 1028 | 1027 |
| 1029 Description describeMismatch(SolveResult result, | 1028 Description describeMismatch(SolveResult result, |
| 1030 Description description, | 1029 Description description, |
| 1031 Map state, bool verbose) { | 1030 Map state, bool verbose) { |
| 1032 description.add(state.state); | 1031 description.add(state['failures']); |
| 1033 return description; | 1032 return description; |
| 1034 } | 1033 } |
| 1035 | 1034 |
| 1036 bool matches(SolveResult result, Map state) { | 1035 bool matches(SolveResult result, Map state) { |
| 1037 var failures = new StringBuffer(); | 1036 var failures = new StringBuffer(); |
| 1038 | 1037 |
| 1039 if (result.succeeded) { | 1038 if (result.succeeded) { |
| 1040 failures.writeln('Solver succeeded'); | 1039 failures.writeln('Solver succeeded'); |
| 1041 } else { | 1040 } else { |
| 1042 if (_expectedType != null && result.error.runtimeType != _expectedType) { | 1041 if (_expectedType != null && result.error.runtimeType != _expectedType) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1053 } | 1052 } |
| 1054 | 1053 |
| 1055 // Allow 1 here because the greedy solver will only make one attempt. | 1054 // Allow 1 here because the greedy solver will only make one attempt. |
| 1056 if (result.attemptedSolutions != 1 && | 1055 if (result.attemptedSolutions != 1 && |
| 1057 result.attemptedSolutions != _maxTries) { | 1056 result.attemptedSolutions != _maxTries) { |
| 1058 failures.writeln('Took ${result.attemptedSolutions} attempts'); | 1057 failures.writeln('Took ${result.attemptedSolutions} attempts'); |
| 1059 } | 1058 } |
| 1060 } | 1059 } |
| 1061 | 1060 |
| 1062 if (!failures.isEmpty) { | 1061 if (!failures.isEmpty) { |
| 1063 state.state = failures.toString(); | 1062 state['failures'] = failures.toString(); |
| 1064 return false; | 1063 return false; |
| 1065 } | 1064 } |
| 1066 | 1065 |
| 1067 return true; | 1066 return true; |
| 1068 } | 1067 } |
| 1069 } | 1068 } |
| 1070 | 1069 |
| 1071 /// A source used for testing. This both creates mock package objects and acts | 1070 /// A source used for testing. This both creates mock package objects and acts |
| 1072 /// as a source for them. | 1071 /// as a source for them. |
| 1073 /// | 1072 /// |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 var source = "mock1"; | 1188 var source = "mock1"; |
| 1190 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); | 1189 var match = new RegExp(r"(.*) from (.*)").firstMatch(description); |
| 1191 if (match != null) { | 1190 if (match != null) { |
| 1192 name = match[1]; | 1191 name = match[1]; |
| 1193 source = match[2]; | 1192 source = match[2]; |
| 1194 if (source == "root") source = null; | 1193 if (source == "root") source = null; |
| 1195 } | 1194 } |
| 1196 | 1195 |
| 1197 callback(isDev, name, source); | 1196 callback(isDev, name, source); |
| 1198 } | 1197 } |
| OLD | NEW |