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

Unified Diff: test/version_solver_test.dart

Issue 2044253003: Refactor Source and SourceRegistry. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Rename LiveSource to BoundSource. Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/test_pub.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/version_solver_test.dart
diff --git a/test/version_solver_test.dart b/test/version_solver_test.dart
index 5fba6da5e52f51d46dadaff04630aad4b44686e1..7d8da5d532a0d01f62a64651d2cd41816f10076a 100644
--- a/test/version_solver_test.dart
+++ b/test/version_solver_test.dart
@@ -10,6 +10,7 @@ import 'package:pub/src/package.dart';
import 'package:pub/src/pubspec.dart';
import 'package:pub/src/sdk.dart' as sdk;
import 'package:pub/src/solver/version_solver.dart';
+import 'package:pub/src/source.dart';
import 'package:pub/src/source/cached.dart';
import 'package:pub/src/system_cache.dart';
import 'package:pub/src/utils.dart';
@@ -1109,11 +1110,12 @@ testResolve(String description, Map packages, {
if (maxTries == null) maxTries = 1;
test(description, () {
- var cache = new SystemCache('.');
source1 = new MockSource('mock1');
source2 = new MockSource('mock2');
- cache.register(source1);
- cache.register(source2);
+
+ var cache = new SystemCache(rootDir: '.');
+ cache.sources.register(source1);
+ cache.sources.register(source2);
cache.sources.setDefault(source1.name);
// Build the test package graph.
@@ -1128,8 +1130,8 @@ testResolve(String description, Map packages, {
// remote server.
root = package;
} else {
- (cache.sources[id.source] as MockSource).addPackage(
- id.description, package);
+ (cache.source(id.source) as BoundMockSource)
+ .addPackage(id.description, package);
}
});
@@ -1158,7 +1160,7 @@ testResolve(String description, Map packages, {
log.verbosity = log.Verbosity.NONE;
var future = resolveVersions(
downgrade ? SolveType.DOWNGRADE : SolveType.GET,
- cache.sources, root, lockFile: realLockFile);
+ cache, root, lockFile: realLockFile);
var matcher;
if (result != null) {
@@ -1347,24 +1349,14 @@ class SolveFailMatcher implements Matcher {
/// descriptions, a package's name is calculated by taking the description
/// string and stripping off any trailing hyphen followed by non-hyphen
/// characters.
-class MockSource extends CachedSource {
- final _packages = <String, Map<Version, Package>>{};
-
- /// Keeps track of which package version lists have been requested. Ensures
- /// that a source is only hit once for a given package and that pub
- /// internally caches the results.
- final _requestedVersions = new Set<String>();
-
- /// Keeps track of which package pubspecs have been requested. Ensures that a
- /// source is only hit once for a given package and that pub internally
- /// caches the results.
- final _requestedPubspecs = new Map<String, Set<Version>>();
-
+class MockSource extends Source {
final String name;
final hasMultipleVersions = true;
MockSource(this.name);
+ BoundSource bind(SystemCache cache) => new BoundMockSource(this, cache);
+
PackageRef parseRef(String name, description, {String containingPath}) =>
new PackageRef(name, this.name, description);
@@ -1373,6 +1365,26 @@ class MockSource extends CachedSource {
bool descriptionsEqual(description1, description2) =>
description1 == description2;
+}
+
+class BoundMockSource extends CachedSource {
+ final SystemCache systemCache;
+
+ final MockSource source;
+
+ final _packages = <String, Map<Version, Package>>{};
+
+ /// Keeps track of which package version lists have been requested. Ensures
+ /// that a source is only hit once for a given package and that pub
+ /// internally caches the results.
+ final _requestedVersions = new Set<String>();
+
+ /// Keeps track of which package pubspecs have been requested. Ensures that a
+ /// source is only hit once for a given package and that pub internally
+ /// caches the results.
+ final _requestedPubspecs = new Map<String, Set<Version>>();
+
+ BoundMockSource(this.source, this.systemCache);
String getDirectory(PackageId id) => '${id.name}-${id.version}';
@@ -1392,7 +1404,7 @@ class MockSource extends CachedSource {
return _packages[ref.description].values.map((package) {
return new PackageId(
- ref.name, this.name, package.version, ref.description);
+ ref.name, source.name, package.version, ref.description);
}).toList();
}
« no previous file with comments | « test/test_pub.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698