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

Side by Side Diff: sdk/lib/_internal/pub_generated/test/dependency_computer/utils.dart

Issue 657673002: Regenerate pub sources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file
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.
4
1 library pub_tests; 5 library pub_tests;
6
2 import 'package:barback/barback.dart'; 7 import 'package:barback/barback.dart';
3 import 'package:path/path.dart' as p; 8 import 'package:path/path.dart' as p;
4 import 'package:scheduled_test/scheduled_test.dart'; 9 import 'package:scheduled_test/scheduled_test.dart';
10
5 import '../../lib/src/barback/cycle_exception.dart'; 11 import '../../lib/src/barback/cycle_exception.dart';
6 import '../../lib/src/barback/dependency_computer.dart'; 12 import '../../lib/src/barback/dependency_computer.dart';
7 import '../../lib/src/entrypoint.dart'; 13 import '../../lib/src/entrypoint.dart';
8 import '../../lib/src/io.dart'; 14 import '../../lib/src/io.dart';
9 import '../../lib/src/package.dart'; 15 import '../../lib/src/package.dart';
10 import '../../lib/src/package_graph.dart'; 16 import '../../lib/src/package_graph.dart';
11 import '../../lib/src/source/path.dart'; 17 import '../../lib/src/source/path.dart';
12 import '../../lib/src/system_cache.dart'; 18 import '../../lib/src/system_cache.dart';
13 import '../../lib/src/utils.dart'; 19 import '../../lib/src/utils.dart';
14 import '../test_pub.dart'; 20 import '../test_pub.dart';
21
22 /// Expects that [DependencyComputer.transformersNeededByTransformers] will
23 /// return a graph matching [expected] when run on the package graph defined by
24 /// packages in the sandbox.
15 void expectDependencies(Map<String, Iterable<String>> expected) { 25 void expectDependencies(Map<String, Iterable<String>> expected) {
16 expected = mapMap(expected, value: (_, ids) => ids.toSet()); 26 expected = mapMap(expected, value: (_, ids) => ids.toSet());
27
17 schedule(() { 28 schedule(() {
18 var computer = new DependencyComputer(_loadPackageGraph()); 29 var computer = new DependencyComputer(_loadPackageGraph());
19 var result = mapMap( 30 var result = mapMap(
20 computer.transformersNeededByTransformers(), 31 computer.transformersNeededByTransformers(),
21 key: (id, _) => id.toString(), 32 key: (id, _) => id.toString(),
22 value: (_, ids) => ids.map((id) => id.toString()).toSet()); 33 value: (_, ids) => ids.map((id) => id.toString()).toSet());
23 expect(result, equals(expected)); 34 expect(result, equals(expected));
24 }, "expect dependencies to match $expected"); 35 }, "expect dependencies to match $expected");
25 } 36 }
37
38 /// Expects that [computeTransformersNeededByTransformers] will throw an
39 /// exception matching [matcher] when run on the package graph defiend by
40 /// packages in the sandbox.
26 void expectException(matcher) { 41 void expectException(matcher) {
27 schedule(() { 42 schedule(() {
28 expect(() { 43 expect(() {
29 var computer = new DependencyComputer(_loadPackageGraph()); 44 var computer = new DependencyComputer(_loadPackageGraph());
30 computer.transformersNeededByTransformers(); 45 computer.transformersNeededByTransformers();
31 }, throwsA(matcher)); 46 }, throwsA(matcher));
32 }, "expect an exception: $matcher"); 47 }, "expect an exception: $matcher");
33 } 48 }
49
50 /// Expects that [computeTransformersNeededByTransformers] will throw a
51 /// [CycleException] with the given [steps] when run on the package graph
52 /// defiend by packages in the sandbox.
34 void expectCycleException(Iterable<String> steps) { 53 void expectCycleException(Iterable<String> steps) {
35 expectException(predicate((error) { 54 expectException(predicate((error) {
36 expect(error, new isInstanceOf<CycleException>()); 55 expect(error, new isInstanceOf<CycleException>());
37 expect(error.steps, equals(steps)); 56 expect(error.steps, equals(steps));
38 return true; 57 return true;
39 }, "cycle exception:\n${steps.map((step) => " $step").join("\n")}")); 58 }, "cycle exception:\n${steps.map((step) => " $step").join("\n")}"));
40 } 59 }
60
61 /// Expects that [DependencyComputer.transformersNeededByLibrary] will return
62 /// transformer ids matching [expected] when run on the library identified by
63 /// [id].
41 void expectLibraryDependencies(String id, Iterable<String> expected) { 64 void expectLibraryDependencies(String id, Iterable<String> expected) {
42 expected = expected.toSet(); 65 expected = expected.toSet();
66
43 schedule(() { 67 schedule(() {
44 var computer = new DependencyComputer(_loadPackageGraph()); 68 var computer = new DependencyComputer(_loadPackageGraph());
45 var result = computer.transformersNeededByLibrary( 69 var result = computer.transformersNeededByLibrary(
46 new AssetId.parse(id)).map((id) => id.toString()).toSet(); 70 new AssetId.parse(id)).map((id) => id.toString()).toSet();
47 expect(result, equals(expected)); 71 expect(result, equals(expected));
48 }, "expect dependencies to match $expected"); 72 }, "expect dependencies to match $expected");
49 } 73 }
74
75 /// Loads a [PackageGraph] from the packages in the sandbox.
76 ///
77 /// This graph will also include barback and its transitive dependencies from
78 /// the repo.
50 PackageGraph _loadPackageGraph() { 79 PackageGraph _loadPackageGraph() {
80 // Load the sandbox packages.
51 var packages = {}; 81 var packages = {};
82
52 var systemCache = new SystemCache(p.join(sandboxDir, cachePath)); 83 var systemCache = new SystemCache(p.join(sandboxDir, cachePath));
53 systemCache.sources 84 systemCache.sources
54 ..register(new PathSource()) 85 ..register(new PathSource())
55 ..setDefault('path'); 86 ..setDefault('path');
56 var entrypoint = new Entrypoint(p.join(sandboxDir, appPath), systemCache); 87 var entrypoint = new Entrypoint(p.join(sandboxDir, appPath), systemCache);
88
57 for (var package in listDir(sandboxDir)) { 89 for (var package in listDir(sandboxDir)) {
58 if (!fileExists(p.join(package, 'pubspec.yaml'))) continue; 90 if (!fileExists(p.join(package, 'pubspec.yaml'))) continue;
59 var packageName = p.basename(package); 91 var packageName = p.basename(package);
60 packages[packageName] = 92 packages[packageName] =
61 new Package.load(packageName, package, systemCache.sources); 93 new Package.load(packageName, package, systemCache.sources);
62 } 94 }
95
63 loadPackage(packageName) { 96 loadPackage(packageName) {
64 if (packages.containsKey(packageName)) return; 97 if (packages.containsKey(packageName)) return;
65 packages[packageName] = new Package.load( 98 packages[packageName] = new Package.load(
66 packageName, 99 packageName,
67 p.join(pkgPath, packageName), 100 p.join(pkgPath, packageName),
68 systemCache.sources); 101 systemCache.sources);
69 for (var dep in packages[packageName].dependencies) { 102 for (var dep in packages[packageName].dependencies) {
70 loadPackage(dep.name); 103 loadPackage(dep.name);
71 } 104 }
72 } 105 }
106
73 loadPackage('barback'); 107 loadPackage('barback');
108
74 return new PackageGraph(entrypoint, null, packages); 109 return new PackageGraph(entrypoint, null, packages);
75 } 110 }
111
112 /// Returns the contents of a no-op transformer that imports each URL in
113 /// [imports].
76 String transformer([Iterable<String> imports]) { 114 String transformer([Iterable<String> imports]) {
77 if (imports == null) imports = []; 115 if (imports == null) imports = [];
116
78 var buffer = 117 var buffer =
79 new StringBuffer()..writeln('import "package:barback/barback.dart";'); 118 new StringBuffer()..writeln('import "package:barback/barback.dart";');
80 for (var import in imports) { 119 for (var import in imports) {
81 buffer.writeln('import "$import";'); 120 buffer.writeln('import "$import";');
82 } 121 }
122
83 buffer.writeln(""" 123 buffer.writeln("""
84 NoOpTransformer extends Transformer { 124 NoOpTransformer extends Transformer {
85 bool isPrimary(AssetId id) => true; 125 bool isPrimary(AssetId id) => true;
86 void apply(Transform transform) {} 126 void apply(Transform transform) {}
87 } 127 }
88 """); 128 """);
129
89 return buffer.toString(); 130 return buffer.toString();
90 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698