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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 import 'package:scheduled_test/scheduled_test.dart'; | 8 import 'package:scheduled_test/scheduled_test.dart'; |
9 | 9 |
10 import 'package:pub/src/lock_file.dart'; | 10 import 'package:pub/src/lock_file.dart'; |
(...skipping 14 matching lines...) Expand all Loading... |
25 import 'test_pub.dart'; | 25 import 'test_pub.dart'; |
26 | 26 |
27 main() { | 27 main() { |
28 group('basic graph', basicGraph); | 28 group('basic graph', basicGraph); |
29 group('with lockfile', withLockFile); | 29 group('with lockfile', withLockFile); |
30 group('root dependency', rootDependency); | 30 group('root dependency', rootDependency); |
31 group('dev dependency', devDependency); | 31 group('dev dependency', devDependency); |
32 group('unsolvable', unsolvable); | 32 group('unsolvable', unsolvable); |
33 group('bad source', badSource); | 33 group('bad source', badSource); |
34 group('backtracking', backtracking); | 34 group('backtracking', backtracking); |
35 group('SDK constraint', sdkConstraint); | 35 group('Dart SDK constraint', dartSdkConstraint); |
| 36 group('Flutter SDK constraint', flutterSdkConstraint); |
36 group('pre-release', prerelease); | 37 group('pre-release', prerelease); |
37 group('override', override); | 38 group('override', override); |
38 group('downgrade', downgrade); | 39 group('downgrade', downgrade); |
39 } | 40 } |
40 | 41 |
41 void basicGraph() { | 42 void basicGraph() { |
42 integration('no dependencies', () { | 43 integration('no dependencies', () { |
43 d.appDir().create(); | 44 d.appDir().create(); |
44 expectResolves(result: {}); | 45 expectResolves(result: {}); |
45 }); | 46 }); |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 builder.serve('d', '2.0.0', deps: {'myapp': 'any'}); | 763 builder.serve('d', '2.0.0', deps: {'myapp': 'any'}); |
763 builder.serve('d', '1.0.0', deps: {'myapp': '<1.0.0'}); | 764 builder.serve('d', '1.0.0', deps: {'myapp': '<1.0.0'}); |
764 }); | 765 }); |
765 | 766 |
766 d.appDir({"a": "any", "c": "any", "d": "any"}).create(); | 767 d.appDir({"a": "any", "c": "any", "d": "any"}).create(); |
767 expectResolves( | 768 expectResolves( |
768 result: {'a': '1.0.0', 'b': '1.0.0', 'c': '1.0.0', 'd': '2.0.0'}); | 769 result: {'a': '1.0.0', 'b': '1.0.0', 'c': '1.0.0', 'd': '2.0.0'}); |
769 }); | 770 }); |
770 } | 771 } |
771 | 772 |
772 void sdkConstraint() { | 773 void dartSdkConstraint() { |
773 integration('root matches SDK', () { | 774 integration('root matches SDK', () { |
774 d.dir(appPath, [ | 775 d.dir(appPath, [ |
775 d.pubspec({ | 776 d.pubspec({ |
776 'name': 'myapp', | 777 'name': 'myapp', |
777 'environment': {'sdk': '0.1.2+3'} | 778 'environment': {'sdk': '0.1.2+3'} |
778 }) | 779 }) |
779 ]).create(); | 780 ]).create(); |
780 | 781 |
781 expectResolves(result: {}); | 782 expectResolves(result: {}); |
782 }); | 783 }); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 pubspec: {'environment': {'sdk': '0.1.2+3'}}); | 860 pubspec: {'environment': {'sdk': '0.1.2+3'}}); |
860 builder.serve('bar', '3.0.0', pubspec: {'environment': {'sdk': '0.0.0'}}); | 861 builder.serve('bar', '3.0.0', pubspec: {'environment': {'sdk': '0.0.0'}}); |
861 builder.serve('bar', '4.0.0', pubspec: {'environment': {'sdk': '0.0.0'}}); | 862 builder.serve('bar', '4.0.0', pubspec: {'environment': {'sdk': '0.0.0'}}); |
862 }); | 863 }); |
863 | 864 |
864 d.appDir({'foo': 'any'}).create(); | 865 d.appDir({'foo': 'any'}).create(); |
865 expectResolves(result: {'foo': '2.0.0', 'bar': '2.0.0'}, tries: 3); | 866 expectResolves(result: {'foo': '2.0.0', 'bar': '2.0.0'}, tries: 3); |
866 }); | 867 }); |
867 } | 868 } |
868 | 869 |
| 870 void flutterSdkConstraint() { |
| 871 group('without a Flutter SDK', () { |
| 872 integration('fails for the root package', () { |
| 873 d.dir(appPath, [ |
| 874 d.pubspec({ |
| 875 'name': 'myapp', |
| 876 'environment': {'flutter': '1.2.3'} |
| 877 }) |
| 878 ]).create(); |
| 879 |
| 880 expectResolves( |
| 881 error: 'Package myapp requires the Flutter SDK, which is not ' |
| 882 'available.'); |
| 883 }); |
| 884 |
| 885 integration('fails for a dependency', () { |
| 886 servePackages((builder) { |
| 887 builder.serve('foo', '1.0.0', |
| 888 pubspec: {'environment': {'flutter': '0.0.0'}}); |
| 889 }); |
| 890 |
| 891 d.appDir({'foo': 'any'}).create(); |
| 892 expectResolves( |
| 893 error: 'Package foo requires the Flutter SDK, which is not ' |
| 894 'available.'); |
| 895 }); |
| 896 |
| 897 integration("chooses a version that doesn't need Flutter", () { |
| 898 servePackages((builder) { |
| 899 builder.serve('foo', '1.0.0'); |
| 900 builder.serve('foo', '2.0.0'); |
| 901 builder.serve('foo', '3.0.0', |
| 902 pubspec: {'environment': {'flutter': '0.0.0'}}); |
| 903 }); |
| 904 |
| 905 d.appDir({'foo': 'any'}).create(); |
| 906 expectResolves(result: {'foo': '2.0.0'}); |
| 907 }); |
| 908 |
| 909 integration('fails even with a matching Dart SDK constraint', () { |
| 910 d.dir(appPath, [ |
| 911 d.pubspec({ |
| 912 'name': 'myapp', |
| 913 'environment': { |
| 914 'dart': '0.1.2+3', |
| 915 'flutter': '1.2.3' |
| 916 } |
| 917 }) |
| 918 ]).create(); |
| 919 |
| 920 expectResolves( |
| 921 error: 'Package myapp requires the Flutter SDK, which is not ' |
| 922 'available.'); |
| 923 }); |
| 924 }); |
| 925 |
| 926 group('with a Flutter SDK', () { |
| 927 setUp(() { |
| 928 d.dir('flutter', [ |
| 929 d.file('version', '1.2.3') |
| 930 ]).create(); |
| 931 }); |
| 932 |
| 933 integration('succeeds with a matching constraint', () { |
| 934 d.dir(appPath, [ |
| 935 d.pubspec({ |
| 936 'name': 'myapp', |
| 937 'environment': {'flutter': 'any'} |
| 938 }) |
| 939 ]).create(); |
| 940 |
| 941 expectResolves( |
| 942 environment: {'FLUTTER_ROOT': p.join(sandboxDir, 'flutter')}, |
| 943 result: {}); |
| 944 }); |
| 945 |
| 946 integration('fails with a non-matching constraint', () { |
| 947 d.dir(appPath, [ |
| 948 d.pubspec({ |
| 949 'name': 'myapp', |
| 950 'environment': {'flutter': '>1.2.3'} |
| 951 }) |
| 952 ]).create(); |
| 953 |
| 954 expectResolves( |
| 955 environment: {'FLUTTER_ROOT': p.join(sandboxDir, 'flutter')}, |
| 956 error: 'Package myapp requires Flutter SDK version >1.2.3 but the ' |
| 957 'current SDK is 1.2.3.'); |
| 958 }); |
| 959 |
| 960 integration('succeeds if both Flutter and Dart SDKs match', () { |
| 961 d.dir(appPath, [ |
| 962 d.pubspec({ |
| 963 'name': 'myapp', |
| 964 'environment': { |
| 965 'sdk': '0.1.2+3', |
| 966 'flutter': '1.2.3' |
| 967 } |
| 968 }) |
| 969 ]).create(); |
| 970 |
| 971 expectResolves( |
| 972 environment: {'FLUTTER_ROOT': p.join(sandboxDir, 'flutter')}, |
| 973 result: {}); |
| 974 }); |
| 975 |
| 976 integration("fails if Flutter SDK doesn't match but Dart does", () { |
| 977 d.dir(appPath, [ |
| 978 d.pubspec({ |
| 979 'name': 'myapp', |
| 980 'environment': { |
| 981 'sdk': '0.1.2+3', |
| 982 'flutter': '>1.2.3' |
| 983 } |
| 984 }) |
| 985 ]).create(); |
| 986 |
| 987 expectResolves( |
| 988 environment: {'FLUTTER_ROOT': p.join(sandboxDir, 'flutter')}, |
| 989 error: 'Package myapp requires Flutter SDK version >1.2.3 but the ' |
| 990 'current SDK is 1.2.3.'); |
| 991 }); |
| 992 |
| 993 integration("fails if Dart SDK doesn't match but Flutter does", () { |
| 994 d.dir(appPath, [ |
| 995 d.pubspec({ |
| 996 'name': 'myapp', |
| 997 'environment': { |
| 998 'sdk': '>0.1.2+3', |
| 999 'flutter': '1.2.3' |
| 1000 } |
| 1001 }) |
| 1002 ]).create(); |
| 1003 |
| 1004 expectResolves( |
| 1005 environment: {'FLUTTER_ROOT': p.join(sandboxDir, 'flutter')}, |
| 1006 error: 'Package myapp requires SDK version >0.1.2+3 but the current ' |
| 1007 'SDK is 0.1.2+3.'); |
| 1008 }); |
| 1009 |
| 1010 integration('selects the latest dependency with a matching constraint', () { |
| 1011 servePackages((builder) { |
| 1012 builder.serve('foo', '1.0.0', |
| 1013 pubspec: {'environment': {'flutter': '^0.0.0'}}); |
| 1014 builder.serve('foo', '2.0.0', |
| 1015 pubspec: {'environment': {'flutter': '^1.0.0'}}); |
| 1016 builder.serve('foo', '3.0.0', |
| 1017 pubspec: {'environment': {'flutter': '^2.0.0'}}); |
| 1018 }); |
| 1019 |
| 1020 d.appDir({'foo': 'any'}).create(); |
| 1021 expectResolves( |
| 1022 environment: {'FLUTTER_ROOT': p.join(sandboxDir, 'flutter')}, |
| 1023 result: {'foo': '2.0.0'}); |
| 1024 }); |
| 1025 }); |
| 1026 } |
| 1027 |
869 void prerelease() { | 1028 void prerelease() { |
870 integration('prefer stable versions over unstable', () { | 1029 integration('prefer stable versions over unstable', () { |
871 servePackages((builder) { | 1030 servePackages((builder) { |
872 builder.serve('a', '1.0.0'); | 1031 builder.serve('a', '1.0.0'); |
873 builder.serve('a', '1.1.0-dev'); | 1032 builder.serve('a', '1.1.0-dev'); |
874 builder.serve('a', '2.0.0-dev'); | 1033 builder.serve('a', '2.0.0-dev'); |
875 builder.serve('a', '3.0.0-dev'); | 1034 builder.serve('a', '3.0.0-dev'); |
876 }); | 1035 }); |
877 | 1036 |
878 d.appDir({'a': 'any'}).create(); | 1037 d.appDir({'a': 'any'}).create(); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 /// If [result] is passed, it's parsed as a pubspec-style dependency map, and | 1268 /// If [result] is passed, it's parsed as a pubspec-style dependency map, and |
1110 /// this asserts that the resulting lockfile matches those dependencies, and | 1269 /// this asserts that the resulting lockfile matches those dependencies, and |
1111 /// that it contains only packages listed in [result]. | 1270 /// that it contains only packages listed in [result]. |
1112 /// | 1271 /// |
1113 /// If [error] is passed, this asserts that pub's error output matches the | 1272 /// If [error] is passed, this asserts that pub's error output matches the |
1114 /// value. It may be a String, a [RegExp], or a [Matcher]. | 1273 /// value. It may be a String, a [RegExp], or a [Matcher]. |
1115 /// | 1274 /// |
1116 /// Asserts that version solving looks at exactly [tries] solutions. It defaults | 1275 /// Asserts that version solving looks at exactly [tries] solutions. It defaults |
1117 /// to allowing only a single solution. | 1276 /// to allowing only a single solution. |
1118 /// | 1277 /// |
| 1278 /// If [environment] is passed, it's added to the OS environment when running |
| 1279 /// pub. |
| 1280 /// |
1119 /// If [downgrade] is `true`, this runs "pub downgrade" instead of "pub get". | 1281 /// If [downgrade] is `true`, this runs "pub downgrade" instead of "pub get". |
1120 void expectResolves({Map result, error, int tries, bool downgrade: false}) { | 1282 void expectResolves({Map result, error, int tries, |
| 1283 Map<String, String> environment, bool downgrade: false}) { |
1121 schedulePub( | 1284 schedulePub( |
1122 args: [downgrade ? 'downgrade' : 'get'], | 1285 args: [downgrade ? 'downgrade' : 'get'], |
| 1286 environment: environment, |
1123 output: error == null | 1287 output: error == null |
1124 ? anyOf( | 1288 ? anyOf( |
1125 contains('Got dependencies!'), | 1289 contains('Got dependencies!'), |
1126 matches(new RegExp(r'Changed \d+ dependenc(ies|y)!'))) | 1290 matches(new RegExp(r'Changed \d+ dependenc(ies|y)!'))) |
1127 : null, | 1291 : null, |
1128 error: error, | 1292 error: error, |
1129 silent: contains('Tried ${tries ?? 1} solutions'), | 1293 silent: contains('Tried ${tries ?? 1} solutions'), |
1130 exitCode: error == null ? 0 : 1); | 1294 exitCode: error == null ? 0 : 1); |
1131 | 1295 |
1132 if (result == null) return; | 1296 if (result == null) return; |
(...skipping 16 matching lines...) Expand all Loading... |
1149 dep = registry.hosted | 1313 dep = registry.hosted |
1150 .refFor(dep.name, url: await globalPackageServer.url) | 1314 .refFor(dep.name, url: await globalPackageServer.url) |
1151 .withConstraint(dep.constraint); | 1315 .withConstraint(dep.constraint); |
1152 } | 1316 } |
1153 expect(dep.allows(id), isTrue, reason: "Expected $id to match $dep."); | 1317 expect(dep.allows(id), isTrue, reason: "Expected $id to match $dep."); |
1154 } | 1318 } |
1155 | 1319 |
1156 expect(ids, isEmpty, reason: "Expected no additional packages."); | 1320 expect(ids, isEmpty, reason: "Expected no additional packages."); |
1157 }); | 1321 }); |
1158 } | 1322 } |
OLD | NEW |