OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file | 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 | 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_tests; | 5 library pub_tests; |
6 | 6 |
7 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
8 import 'package:path/path.dart' as p; | 8 import 'package:path/path.dart' as p; |
9 import 'package:scheduled_test/scheduled_test.dart'; | 9 import 'package:scheduled_test/scheduled_test.dart'; |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 | 60 |
61 /// Expects that [DependencyComputer.transformersNeededByLibrary] will return | 61 /// Expects that [DependencyComputer.transformersNeededByLibrary] will return |
62 /// transformer ids matching [expected] when run on the library identified by | 62 /// transformer ids matching [expected] when run on the library identified by |
63 /// [id]. | 63 /// [id]. |
64 void expectLibraryDependencies(String id, Iterable<String> expected) { | 64 void expectLibraryDependencies(String id, Iterable<String> expected) { |
65 expected = expected.toSet(); | 65 expected = expected.toSet(); |
66 | 66 |
67 schedule(() { | 67 schedule(() { |
68 var computer = new DependencyComputer(_loadPackageGraph()); | 68 var computer = new DependencyComputer(_loadPackageGraph()); |
69 var result = computer.transformersNeededByLibrary(new AssetId.parse(id)) | 69 var result = computer.transformersNeededByLibrary( |
70 .map((id) => id.toString()).toSet(); | 70 new AssetId.parse(id)).map((id) => id.toString()).toSet(); |
71 expect(result, equals(expected)); | 71 expect(result, equals(expected)); |
72 }, "expect dependencies to match $expected"); | 72 }, "expect dependencies to match $expected"); |
73 } | 73 } |
74 | 74 |
75 /// Loads a [PackageGraph] from the packages in the sandbox. | 75 /// Loads a [PackageGraph] from the packages in the sandbox. |
76 /// | 76 /// |
77 /// This graph will also include barback and its transitive dependencies from | 77 /// This graph will also include barback and its transitive dependencies from |
78 /// the repo. | 78 /// the repo. |
79 PackageGraph _loadPackageGraph() { | 79 PackageGraph _loadPackageGraph() { |
80 // Load the sandbox packages. | 80 // Load the sandbox packages. |
81 var packages = {}; | 81 var packages = {}; |
82 | 82 |
83 var systemCache = new SystemCache(p.join(sandboxDir, cachePath)); | 83 var systemCache = new SystemCache(p.join(sandboxDir, cachePath)); |
84 systemCache.sources | 84 systemCache.sources |
85 ..register(new PathSource()) | 85 ..register(new PathSource()) |
86 ..setDefault('path'); | 86 ..setDefault('path'); |
87 var entrypoint = new Entrypoint(p.join(sandboxDir, appPath), systemCache); | 87 var entrypoint = new Entrypoint(p.join(sandboxDir, appPath), systemCache); |
88 | 88 |
89 for (var package in listDir(sandboxDir)) { | 89 for (var package in listDir(sandboxDir)) { |
90 if (!fileExists(p.join(package, 'pubspec.yaml'))) continue; | 90 if (!fileExists(p.join(package, 'pubspec.yaml'))) continue; |
91 var packageName = p.basename(package); | 91 var packageName = p.basename(package); |
92 packages[packageName] = new Package.load( | 92 packages[packageName] = |
93 packageName, package, systemCache.sources); | 93 new Package.load(packageName, package, systemCache.sources); |
94 } | 94 } |
95 | 95 |
96 loadPackage(packageName) { | 96 loadPackage(packageName) { |
97 if (packages.containsKey(packageName)) return; | 97 if (packages.containsKey(packageName)) return; |
98 packages[packageName] = new Package.load( | 98 packages[packageName] = |
99 packageName, packagePath(packageName), systemCache.sources); | 99 new Package.load(packageName, packagePath(packageName), systemCache.sour
ces); |
100 for (var dep in packages[packageName].dependencies) { | 100 for (var dep in packages[packageName].dependencies) { |
101 loadPackage(dep.name); | 101 loadPackage(dep.name); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 loadPackage('barback'); | 105 loadPackage('barback'); |
106 | 106 |
107 return new PackageGraph(entrypoint, null, packages); | 107 return new PackageGraph(entrypoint, null, packages); |
108 } | 108 } |
109 | 109 |
110 /// Returns the contents of a no-op transformer that imports each URL in | 110 /// Returns the contents of a no-op transformer that imports each URL in |
111 /// [imports]. | 111 /// [imports]. |
112 String transformer([Iterable<String> imports]) { | 112 String transformer([Iterable<String> imports]) { |
113 if (imports == null) imports = []; | 113 if (imports == null) imports = []; |
114 | 114 |
115 var buffer = new StringBuffer() | 115 var buffer = |
116 ..writeln('import "package:barback/barback.dart";'); | 116 new StringBuffer()..writeln('import "package:barback/barback.dart";'); |
117 for (var import in imports) { | 117 for (var import in imports) { |
118 buffer.writeln('import "$import";'); | 118 buffer.writeln('import "$import";'); |
119 } | 119 } |
120 | 120 |
121 buffer.writeln(""" | 121 buffer.writeln(""" |
122 NoOpTransformer extends Transformer { | 122 NoOpTransformer extends Transformer { |
123 bool isPrimary(AssetId id) => true; | 123 bool isPrimary(AssetId id) => true; |
124 void apply(Transform transform) {} | 124 void apply(Transform transform) {} |
125 } | 125 } |
126 """); | 126 """); |
127 | 127 |
128 return buffer.toString(); | 128 return buffer.toString(); |
129 } | 129 } |
OLD | NEW |