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

Side by Side Diff: packages/package_config/test/discovery_test.dart

Issue 3014633002: Roll to pickup pool changes (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 package_config.discovery_test; 5 library package_config.discovery_test;
6 6
7 import "dart:async"; 7 import "dart:async";
8 import "dart:io"; 8 import "dart:io";
9 import "package:test/test.dart"; 9 import "package:test/test.dart";
10 import "package:package_config/packages.dart"; 10 import "package:package_config/packages.dart";
(...skipping 23 matching lines...) Expand all
34 expect(resolver, isNotNull); 34 expect(resolver, isNotNull);
35 expect(resolver.resolve(pkg("foo", "bar/baz")), 35 expect(resolver.resolve(pkg("foo", "bar/baz")),
36 equals(location.resolve("packages/foo/bar/baz"))); 36 equals(location.resolve("packages/foo/bar/baz")));
37 expect(resolver.resolve(pkg("bar", "baz/qux")), 37 expect(resolver.resolve(pkg("bar", "baz/qux")),
38 equals(location.resolve("packages/bar/baz/qux"))); 38 equals(location.resolve("packages/bar/baz/qux")));
39 expect(resolver.resolve(pkg("baz", "qux/foo")), 39 expect(resolver.resolve(pkg("baz", "qux/foo")),
40 equals(location.resolve("packages/baz/qux/foo"))); 40 equals(location.resolve("packages/baz/qux/foo")));
41 if (location.scheme == "file") { 41 if (location.scheme == "file") {
42 expect(resolver.packages, unorderedEquals(["foo", "bar", "baz"])); 42 expect(resolver.packages, unorderedEquals(["foo", "bar", "baz"]));
43 } else { 43 } else {
44 expect(() => resolver.packages, throws); 44 expect(() => resolver.packages, throwsUnsupportedError);
45 } 45 }
46 } 46 }
47 47
48 Uri pkg(String packageName, String packagePath) { 48 Uri pkg(String packageName, String packagePath) {
49 var path; 49 var path;
50 if (packagePath.startsWith('/')) { 50 if (packagePath.startsWith('/')) {
51 path = "$packageName$packagePath"; 51 path = "$packageName$packagePath";
52 } else { 52 } else {
53 path = "$packageName/$packagePath"; 53 path = "$packageName/$packagePath";
54 } 54 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 }); 162 });
163 163
164 test(".packages w/ loader", () async { 164 test(".packages w/ loader", () async {
165 Uri location = Uri.parse("krutch://example.com/path/"); 165 Uri location = Uri.parse("krutch://example.com/path/");
166 Future<List<int>> loader(Uri file) async { 166 Future<List<int>> loader(Uri file) async {
167 if (file.path.endsWith(".packages")) { 167 if (file.path.endsWith(".packages")) {
168 return packagesFile.codeUnits; 168 return packagesFile.codeUnits;
169 } 169 }
170 throw "not found"; 170 throw "not found";
171 } 171 }
172
172 // A non-file: location with no .packages or packages/: 173 // A non-file: location with no .packages or packages/:
173 // Assumes a packages dir exists, and resolves relative to that. 174 // Assumes a packages dir exists, and resolves relative to that.
174 Packages resolver; 175 Packages resolver;
175 resolver = await findPackages(location, loader: loader); 176 resolver = await findPackages(location, loader: loader);
176 validatePackagesFile(resolver, location); 177 validatePackagesFile(resolver, location);
177 resolver = 178 resolver =
178 await findPackages(location.resolve("script.dart"), loader: loader); 179 await findPackages(location.resolve("script.dart"), loader: loader);
179 validatePackagesFile(resolver, location); 180 validatePackagesFile(resolver, location);
180 resolver = await findPackagesFromNonFile(location, loader: loader); 181 resolver = await findPackagesFromNonFile(location, loader: loader);
181 validatePackagesFile(resolver, location); 182 validatePackagesFile(resolver, location);
182 resolver = await findPackagesFromNonFile(location.resolve("script.dart"), 183 resolver = await findPackagesFromNonFile(location.resolve("script.dart"),
183 loader: loader); 184 loader: loader);
184 validatePackagesFile(resolver, location); 185 validatePackagesFile(resolver, location);
185 }); 186 });
186 187
187 test("no packages w/ loader", () async { 188 test("no packages w/ loader", () async {
188 Uri location = Uri.parse("krutch://example.com/path/"); 189 Uri location = Uri.parse("krutch://example.com/path/");
189 Future<List<int>> loader(Uri file) async { 190 Future<List<int>> loader(Uri file) async {
190 throw "not found"; 191 throw "not found";
191 } 192 }
193
192 // A non-file: location with no .packages or packages/: 194 // A non-file: location with no .packages or packages/:
193 // Assumes a packages dir exists, and resolves relative to that. 195 // Assumes a packages dir exists, and resolves relative to that.
194 Packages resolver; 196 Packages resolver;
195 resolver = await findPackages(location, loader: loader); 197 resolver = await findPackages(location, loader: loader);
196 validatePackagesDir(resolver, location); 198 validatePackagesDir(resolver, location);
197 resolver = 199 resolver =
198 await findPackages(location.resolve("script.dart"), loader: loader); 200 await findPackages(location.resolve("script.dart"), loader: loader);
199 validatePackagesDir(resolver, location); 201 validatePackagesDir(resolver, location);
200 resolver = await findPackagesFromNonFile(location, loader: loader); 202 resolver = await findPackagesFromNonFile(location, loader: loader);
201 validatePackagesDir(resolver, location); 203 validatePackagesDir(resolver, location);
(...skipping 19 matching lines...) Expand all
221 223
222 test("loadPackagesFile w/ loader", () async { 224 test("loadPackagesFile w/ loader", () async {
223 Future<List<int>> loader(Uri uri) async => packagesFile.codeUnits; 225 Future<List<int>> loader(Uri uri) async => packagesFile.codeUnits;
224 Uri file = Uri.parse("krutz://example.com/.packages"); 226 Uri file = Uri.parse("krutz://example.com/.packages");
225 Packages resolver = await loadPackagesFile(file, loader: loader); 227 Packages resolver = await loadPackagesFile(file, loader: loader);
226 validatePackagesFile(resolver, file); 228 validatePackagesFile(resolver, file);
227 }); 229 });
228 230
229 generalTest("loadPackagesFile not found", {}, (Uri directory) async { 231 generalTest("loadPackagesFile not found", {}, (Uri directory) async {
230 Uri file = directory.resolve(".packages"); 232 Uri file = directory.resolve(".packages");
231 expect(loadPackagesFile(file), throws); 233 expect(
234 loadPackagesFile(file),
235 throwsA(anyOf(new isInstanceOf<FileSystemException>(),
236 new isInstanceOf<HttpException>())));
232 }); 237 });
233 238
234 generalTest("loadPackagesFile syntax error", {".packages": "syntax error"}, 239 generalTest("loadPackagesFile syntax error", {".packages": "syntax error"},
235 (Uri directory) async { 240 (Uri directory) async {
236 Uri file = directory.resolve(".packages"); 241 Uri file = directory.resolve(".packages");
237 expect(loadPackagesFile(file), throws); 242 expect(loadPackagesFile(file), throwsFormatException);
238 }); 243 });
239 244
240 generalTest("getPackagesDir", { 245 generalTest("getPackagesDir", {
241 "packages": {"foo": {}, "bar": {}, "baz": {}} 246 "packages": {"foo": {}, "bar": {}, "baz": {}}
242 }, (Uri directory) async { 247 }, (Uri directory) async {
243 Uri packages = directory.resolve("packages/"); 248 Uri packages = directory.resolve("packages/");
244 Packages resolver = getPackagesDirectory(packages); 249 Packages resolver = getPackagesDirectory(packages);
245 Uri resolved = resolver.resolve(pkg("foo", "flip/flop")); 250 Uri resolved = resolver.resolve(pkg("foo", "flip/flop"));
246 expect(resolved, packages.resolve("foo/flip/flop")); 251 expect(resolved, packages.resolve("foo/flip/flop"));
247 }); 252 });
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (content is Map) { 318 if (content is Map) {
314 Directory subDir = new Directory(path.join(target.path, name)); 319 Directory subDir = new Directory(path.join(target.path, name));
315 subDir.createSync(); 320 subDir.createSync();
316 _createFiles(subDir, content); 321 _createFiles(subDir, content);
317 } else { 322 } else {
318 File file = new File(path.join(target.path, name)); 323 File file = new File(path.join(target.path, name));
319 file.writeAsStringSync(content, flush: true); 324 file.writeAsStringSync(content, flush: true);
320 } 325 }
321 }); 326 });
322 } 327 }
OLDNEW
« no previous file with comments | « packages/package_config/test/discovery_analysis_test.dart ('k') | packages/package_config/test/parse_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698