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

Side by Side Diff: utils/tests/pub/version_solver_test.dart

Issue 11369066: Show better error messages in network failures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up string interpolation a bit. Created 8 years, 1 month 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 | « utils/tests/pub/update/hosted/fail_gracefully_on_missing_package_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_update_test; 5 library pub_update_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 import '../../pub/lock_file.dart'; 10 import '../../pub/lock_file.dart';
11 import '../../pub/package.dart'; 11 import '../../pub/package.dart';
12 import '../../pub/pubspec.dart'; 12 import '../../pub/pubspec.dart';
13 import '../../pub/root_source.dart'; 13 import '../../pub/root_source.dart';
14 import '../../pub/source.dart'; 14 import '../../pub/source.dart';
15 import '../../pub/source_registry.dart'; 15 import '../../pub/source_registry.dart';
16 import '../../pub/system_cache.dart';
16 import '../../pub/utils.dart'; 17 import '../../pub/utils.dart';
17 import '../../pub/version.dart'; 18 import '../../pub/version.dart';
18 import '../../pub/version_solver.dart'; 19 import '../../pub/version_solver.dart';
19 import '../../../pkg/unittest/lib/unittest.dart'; 20 import '../../../pkg/unittest/lib/unittest.dart';
20 21
21 final noVersion = 'no version'; 22 final noVersion = 'no version';
22 final disjointConstraint = 'disjoint'; 23 final disjointConstraint = 'disjoint';
23 final sourceMismatch = 'source mismatch'; 24 final sourceMismatch = 'source mismatch';
24 final descriptionMismatch = 'description mismatch'; 25 final descriptionMismatch = 'description mismatch';
25 final couldNotSolve = 'unsolved'; 26 final couldNotSolve = 'unsolved';
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 " is a DisjointConstraintException"); 347 " is a DisjointConstraintException");
347 var isSourceMismatchException = 348 var isSourceMismatchException =
348 predicate((x)=> x is SourceMismatchException, 349 predicate((x)=> x is SourceMismatchException,
349 "is a SourceMismatchException"); 350 "is a SourceMismatchException");
350 var isDescriptionMismatchException = 351 var isDescriptionMismatchException =
351 predicate((x)=> x is DescriptionMismatchException, 352 predicate((x)=> x is DescriptionMismatchException,
352 "is a DescriptionMismatchException"); 353 "is a DescriptionMismatchException");
353 var isCouldNotSolveException = predicate((x)=> x is CouldNotSolveException, 354 var isCouldNotSolveException = predicate((x)=> x is CouldNotSolveException,
354 "is a CouldNotSolveException"); 355 "is a CouldNotSolveException");
355 356
356 var sources = new SourceRegistry(); 357 var cache = new SystemCache('.');
357 source1 = new MockSource('mock1'); 358 source1 = new MockSource('mock1');
358 source2 = new MockSource('mock2'); 359 source2 = new MockSource('mock2');
359 versionlessSource = new MockVersionlessSource(); 360 versionlessSource = new MockVersionlessSource();
360 sources.register(source1); 361 cache.register(source1);
361 sources.register(source2); 362 cache.register(source2);
362 sources.register(versionlessSource); 363 cache.register(versionlessSource);
363 sources.setDefault(source1.name); 364 cache.sources.setDefault(source1.name);
364 365
365 // Build the test package graph. 366 // Build the test package graph.
366 var root; 367 var root;
367 packages.forEach((nameVersion, dependencies) { 368 packages.forEach((nameVersion, dependencies) {
368 var parsed = parseSource(nameVersion); 369 var parsed = parseSource(nameVersion);
369 nameVersion = parsed.first; 370 nameVersion = parsed.first;
370 var source = parsed.last; 371 var source = parsed.last;
371 372
372 var parts = nameVersion.split(' '); 373 var parts = nameVersion.split(' ');
373 var name = parts[0]; 374 var name = parts[0];
374 var version = parts[1]; 375 var version = parts[1];
375 376
376 var package = source1.mockPackage(name, version, dependencies); 377 var package = source1.mockPackage(name, version, dependencies);
377 if (name == 'myapp') { 378 if (name == 'myapp') {
378 // Don't add the root package to the server, so we can verify that Pub 379 // Don't add the root package to the server, so we can verify that Pub
379 // doesn't try to look up information about the local package on the 380 // doesn't try to look up information about the local package on the
380 // remote server. 381 // remote server.
381 root = package; 382 root = package;
382 rootSource = new RootSource(root); 383 rootSource = new RootSource(root);
383 sources.register(rootSource); 384 cache.register(rootSource);
384 } else { 385 } else {
385 source.addPackage(package); 386 source.addPackage(package);
386 } 387 }
387 }); 388 });
388 389
389 // Clean up the expectation. 390 // Clean up the expectation.
390 if (result != null) { 391 if (result != null) {
391 var newResult = {}; 392 var newResult = {};
392 result.forEach((name, version) { 393 result.forEach((name, version) {
393 var parsed = parseSource(name); 394 var parsed = parseSource(name);
394 name = parsed.first; 395 name = parsed.first;
395 var source = parsed.last; 396 var source = parsed.last;
396 version = new Version.parse(version); 397 version = new Version.parse(version);
397 newResult[name] = new PackageId(name, source, version, name); 398 newResult[name] = new PackageId(name, source, version, name);
398 }); 399 });
399 result = newResult; 400 result = newResult;
400 } 401 }
401 402
402 var realLockFile = new LockFile.empty(); 403 var realLockFile = new LockFile.empty();
403 if (lockfile != null) { 404 if (lockfile != null) {
404 lockfile.forEach((name, version) { 405 lockfile.forEach((name, version) {
405 version = new Version.parse(version); 406 version = new Version.parse(version);
406 realLockFile.packages[name] = 407 realLockFile.packages[name] =
407 new PackageId(name, source1, version, name); 408 new PackageId(name, source1, version, name);
408 }); 409 });
409 } 410 }
410 411
411 // Resolve the versions. 412 // Resolve the versions.
412 var future = resolveVersions(sources, root, realLockFile); 413 var future = resolveVersions(cache.sources, root, realLockFile);
413 414
414 if (result != null) { 415 if (result != null) {
415 expect(future, completion(predicate((actualResult) { 416 expect(future, completion(predicate((actualResult) {
416 for (var actualId in actualResult) { 417 for (var actualId in actualResult) {
417 if (!result.containsKey(actualId.name)) return false; 418 if (!result.containsKey(actualId.name)) return false;
418 var expectedId = result.remove(actualId.name); 419 var expectedId = result.remove(actualId.name);
419 if (actualId != expectedId) return false; 420 if (actualId != expectedId) return false;
420 } 421 }
421 return result.isEmpty; 422 return result.isEmpty;
422 }, 'packages to match $result'))); 423 }, 'packages to match $result')));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 var match = new RegExp(r"(.*) from (.*)").firstMatch(name); 539 var match = new RegExp(r"(.*) from (.*)").firstMatch(name);
539 if (match == null) return new Pair<String, Source>(name, source1); 540 if (match == null) return new Pair<String, Source>(name, source1);
540 switch (match[2]) { 541 switch (match[2]) {
541 case 'mock1': return new Pair<String, Source>(match[1], source1); 542 case 'mock1': return new Pair<String, Source>(match[1], source1);
542 case 'mock2': return new Pair<String, Source>(match[1], source2); 543 case 'mock2': return new Pair<String, Source>(match[1], source2);
543 case 'root': return new Pair<String, Source>(match[1], rootSource); 544 case 'root': return new Pair<String, Source>(match[1], rootSource);
544 case 'versionless': 545 case 'versionless':
545 return new Pair<String, Source>(match[1], versionlessSource); 546 return new Pair<String, Source>(match[1], versionlessSource);
546 } 547 }
547 } 548 }
OLDNEW
« no previous file with comments | « utils/tests/pub/update/hosted/fail_gracefully_on_missing_package_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698