Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: sdk/lib/_internal/pub/test/version_solver_test.dart

Issue 243683002: Refactor Source. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise all the things. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/pub/test/pubspec_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_upgrade_test; 5 library pub_upgrade_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/cached.dart';
17 import '../lib/src/system_cache.dart'; 17 import '../lib/src/system_cache.dart';
18 import '../lib/src/utils.dart'; 18 import '../lib/src/utils.dart';
19 import '../lib/src/version.dart'; 19 import '../lib/src/version.dart';
20 import '../lib/src/solver/version_solver.dart'; 20 import '../lib/src/solver/version_solver.dart';
21 import 'test_pub.dart'; 21 import 'test_pub.dart';
22 22
23 MockSource source1; 23 MockSource source1;
24 MockSource source2; 24 MockSource source2;
25 25
26 main() { 26 main() {
(...skipping 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 } 1288 }
1289 } 1289 }
1290 1290
1291 /// A source used for testing. This both creates mock package objects and acts 1291 /// A source used for testing. This both creates mock package objects and acts
1292 /// as a source for them. 1292 /// as a source for them.
1293 /// 1293 ///
1294 /// In order to support testing packages that have the same name but different 1294 /// In order to support testing packages that have the same name but different
1295 /// descriptions, a package's name is calculated by taking the description 1295 /// descriptions, a package's name is calculated by taking the description
1296 /// string and stripping off any trailing hyphen followed by non-hyphen 1296 /// string and stripping off any trailing hyphen followed by non-hyphen
1297 /// characters. 1297 /// characters.
1298 class MockSource extends Source { 1298 class MockSource extends CachedSource {
1299 final _packages = <String, Map<Version, Package>>{}; 1299 final _packages = <String, Map<Version, Package>>{};
1300 1300
1301 /// Keeps track of which package version lists have been requested. Ensures 1301 /// Keeps track of which package version lists have been requested. Ensures
1302 /// that a source is only hit once for a given package and that pub 1302 /// that a source is only hit once for a given package and that pub
1303 /// internally caches the results. 1303 /// internally caches the results.
1304 final _requestedVersions = new Set<String>(); 1304 final _requestedVersions = new Set<String>();
1305 1305
1306 /// Keeps track of which package pubspecs have been requested. Ensures that a 1306 /// Keeps track of which package pubspecs have been requested. Ensures that a
1307 /// source is only hit once for a given package and that pub internally 1307 /// source is only hit once for a given package and that pub internally
1308 /// caches the results. 1308 /// caches the results.
1309 final _requestedPubspecs = new Map<String, Set<Version>>(); 1309 final _requestedPubspecs = new Map<String, Set<Version>>();
1310 1310
1311 final String name; 1311 final String name;
1312 bool get shouldCache => true;
1313 1312
1314 MockSource(this.name); 1313 MockSource(this.name);
1315 1314
1316 Future<String> systemCacheDirectory(PackageId id) { 1315 dynamic parseDescription(String containingPath, description,
1316 {bool fromLockFile: false}) => description;
1317
1318 bool descriptionsEqual(description1, description2) =>
1319 description1 == description2;
1320
1321 Future<String> getDirectory(PackageId id) {
1317 return new Future.value('${id.name}-${id.version}'); 1322 return new Future.value('${id.name}-${id.version}');
1318 } 1323 }
1319 1324
1320 Future<List<Version>> getVersions(String name, String description) { 1325 Future<List<Version>> getVersions(String name, String description) {
1321 return syncFuture(() { 1326 return syncFuture(() {
1322 // Make sure the solver doesn't request the same thing twice. 1327 // Make sure the solver doesn't request the same thing twice.
1323 if (_requestedVersions.contains(description)) { 1328 if (_requestedVersions.contains(description)) {
1324 throw new Exception('Version list for $description was already ' 1329 throw new Exception('Version list for $description was already '
1325 'requested.'); 1330 'requested.');
1326 } 1331 }
1327 1332
1328 _requestedVersions.add(description); 1333 _requestedVersions.add(description);
1329 1334
1330 if (!_packages.containsKey(description)){ 1335 if (!_packages.containsKey(description)){
1331 throw new Exception('MockSource does not have a package matching ' 1336 throw new Exception('MockSource does not have a package matching '
1332 '"$description".'); 1337 '"$description".');
1333 } 1338 }
1334 1339
1335 return _packages[description].keys.toList(); 1340 return _packages[description].keys.toList();
1336 }); 1341 });
1337 } 1342 }
1338 1343
1339 Future<Pubspec> describe(PackageId id) { 1344 Future<Pubspec> describeUncached(PackageId id) {
1340 return syncFuture(() { 1345 return syncFuture(() {
1341 // Make sure the solver doesn't request the same thing twice. 1346 // Make sure the solver doesn't request the same thing twice.
1342 if (_requestedPubspecs.containsKey(id.description) && 1347 if (_requestedPubspecs.containsKey(id.description) &&
1343 _requestedPubspecs[id.description].contains(id.version)) { 1348 _requestedPubspecs[id.description].contains(id.version)) {
1344 throw new Exception('Pubspec for $id was already requested.'); 1349 throw new Exception('Pubspec for $id was already requested.');
1345 } 1350 }
1346 1351
1347 _requestedPubspecs.putIfAbsent(id.description, () => new Set<Version>()); 1352 _requestedPubspecs.putIfAbsent(id.description, () => new Set<Version>());
1348 _requestedPubspecs[id.description].add(id.version); 1353 _requestedPubspecs[id.description].add(id.version);
1349 1354
1350 return _packages[id.description][id.version].pubspec; 1355 return _packages[id.description][id.version].pubspec;
1351 }); 1356 });
1352 } 1357 }
1353 1358
1354 Future<bool> get(PackageId id, String path) { 1359 Future<Package> downloadToSystemCache(PackageId id) =>
1355 throw new Exception('no'); 1360 throw new UnsupportedError('Cannot download mock packages');
1356 } 1361
1362 List<Package> getCachedPackages() =>
1363 throw new UnsupportedError('Cannot get mock packages');
1364
1365 Future<Pair<int, int>> repairCachedPackages() =>
1366 throw new UnsupportedError('Cannot repair mock packages');
1357 1367
1358 void addPackage(String description, Package package) { 1368 void addPackage(String description, Package package) {
1359 _packages.putIfAbsent(description, () => new Map<Version, Package>()); 1369 _packages.putIfAbsent(description, () => new Map<Version, Package>());
1360 _packages[description][package.version] = package; 1370 _packages[description][package.version] = package;
1361 } 1371 }
1362 } 1372 }
1363 1373
1364 Package mockPackage(PackageId id, Map dependencyStrings, Map overrides) { 1374 Package mockPackage(PackageId id, Map dependencyStrings, Map overrides) {
1365 var sdkConstraint = null; 1375 var sdkConstraint = null;
1366 1376
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 } 1455 }
1446 1456
1447 var source = "mock1"; 1457 var source = "mock1";
1448 if (match[7] != null) { 1458 if (match[7] != null) {
1449 source = match[7]; 1459 source = match[7];
1450 if (source == "root") source = null; 1460 if (source == "root") source = null;
1451 } 1461 }
1452 1462
1453 return new PackageId(name, source, parsedVersion, description); 1463 return new PackageId(name, source, parsedVersion, description);
1454 } 1464 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/test/pubspec_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698